Skip to content

Commit

Permalink
Make LayerBase in the module Layers
Browse files Browse the repository at this point in the history
  • Loading branch information
domitry committed Dec 13, 2015
1 parent d5c2076 commit c50f17e
Showing 1 changed file with 40 additions and 28 deletions.
68 changes: 40 additions & 28 deletions lib/nyaplot/layers/base.rb
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

0 comments on commit c50f17e

Please sign in to comment.