-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
module Nyaplot | ||
class LayerBase | ||
class << self | ||
def define_args(*args) | ||
args.each do |s| | ||
define_method(s) do |val=nil| | ||
unless val.nil? | ||
@props[s] = val | ||
else | ||
@props[s] | ||
module Layers | ||
class LayerBase | ||
class << self | ||
def define_args(*args) | ||
args.each do |s| | ||
define_method(s) do |val=nil| | ||
unless val.nil? | ||
@props[s] = val | ||
self | ||
else | ||
@props[s] | ||
end | ||
end | ||
self | ||
end | ||
end | ||
end | ||
end | ||
|
||
def initialize(props={}) | ||
@uuid = SecureRandom.uuid | ||
@props = props | ||
end | ||
|
||
args = @props.reduce({}) do |memo, pair| | ||
memo[pair[0]] = pair[1] unless pari[1].is_a? LayerBase | ||
memo | ||
end | ||
attr_reader :uuid | ||
|
||
sync_args = @props.reduce({}) do |memo, pair| | ||
memo[pair[0]] = pair[1].uuid if pair[1].is_a? LayerBase | ||
memo | ||
def initialize(props={}) | ||
@uuid = SecureRandom.uuid | ||
@props = props | ||
end | ||
|
||
def to_node(children=[]) | ||
{ | ||
uuid: @uuid, | ||
children: children | ||
} | ||
end | ||
|
||
{ | ||
uuid: @uuid, | ||
args: args, | ||
sync_args: sync_args | ||
}.to_json | ||
def to_json(*args) | ||
args = @props.reduce({}) do |memo, pair| | ||
memo[pair[0]] = pair[1] unless pair[1].is_a? LayerBase | ||
memo | ||
end | ||
|
||
sync_args = @props.reduce({}) do |memo, pair| | ||
memo[pair[0]] = pair[1].uuid if pair[1].is_a? LayerBase | ||
memo | ||
end | ||
|
||
{ | ||
type: self.class.name.downcase.split("::").last, | ||
uuid: @uuid, | ||
args: args, | ||
sync_args: sync_args | ||
}.to_json | ||
end | ||
end | ||
end | ||
end |