Class: Hanuman::StageBuilder
Instance Method Summary
collapse
Instance Method Details
#add_link(level, from, into) ⇒ Object
70
71
72
|
# File 'lib/hanuman/stage.rb', line 70
def add_link(level, from, into)
links << Hanuman::LinkFactory.connect(level, from, into)
end
|
#build(options = {}) ⇒ Object
45
46
47
|
# File 'lib/hanuman/stage.rb', line 45
def build(options = {})
for_class.receive self.serialize.merge(options).merge(options[label] || {})
end
|
#clone ⇒ Object
This is a hacky method to clone a Stage ; probably could be merged into serialize?
88
89
90
91
92
|
# File 'lib/hanuman/stage.rb', line 88
def clone
cloned_attrs = Hash[ serialize.map{ |key, val| dup_key = key.dup rescue key ; dup_val = val.dup rescue val ; [ dup_key, dup_val ] } ]
cloned_links = links.map{ |link| link.dup }
self.class.receive(cloned_attrs.merge(links: cloned_links).merge(for_class: for_class))
end
|
#define(*args, &blk) ⇒ Object
39
40
41
42
43
|
# File 'lib/hanuman/stage.rb', line 39
def define(*args, &blk)
stage = for_class || define_class(label, *args)
stage.class_eval(&blk) if block_given?
stage.register
end
|
#define_class(name, *args) ⇒ Object
61
62
63
64
65
66
|
# File 'lib/hanuman/stage.rb', line 61
def define_class(name, *args)
klass = namespace(*args).const_get(name.to_s.camelize, Class.new(namespace(*args))) rescue nil
klass ||= namespace(*args).const_set(name.to_s.camelize, Class.new(namespace(*args)))
klass.set_builder(self)
klass
end
|
#handle_extra_attributes(attrs) ⇒ Object
49
50
51
|
# File 'lib/hanuman/stage.rb', line 49
def handle_extra_attributes(attrs)
args.merge!(attrs)
end
|
#into(other_stage) ⇒ Object
Also known as:
|
74
75
76
77
|
# File 'lib/hanuman/stage.rb', line 74
def into(other_stage)
self.add_link(:simple, self.linkable_name(:in), other_stage.linkable_name(:out))
other_stage
end
|
#linkable_name(direction) ⇒ Object
68
|
# File 'lib/hanuman/stage.rb', line 68
def linkable_name(direction) self.label ; end
|
#merge!(other_builder = {}) ⇒ Object
53
54
55
56
57
|
# File 'lib/hanuman/stage.rb', line 53
def merge!(other_builder = {})
attrs = other_builder.attributes rescue other_builder
self.receive!(attrs)
self
end
|
#namespace(*args) ⇒ Object
59
|
# File 'lib/hanuman/stage.rb', line 59
def namespace(*args) Hanuman::Stage ; end
|
#serialize ⇒ Object
80
81
82
83
84
85
|
# File 'lib/hanuman/stage.rb', line 80
def serialize()
attrs = attributes
args = attrs.delete(:args)
attrs.delete(:links) ; attrs.delete(:for_class)
attrs.merge(args)
end
|