Skip to content

Commit 3439ed5

Browse files
author
Robert Jackson
committed
Add #build method for repeating components.
1 parent 298fbc9 commit 3439ed5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/hippo/transaction_sets/base.rb

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,30 @@ def method_missing(method_name, *args)
9090
yield component if block_given?
9191

9292
values[component_entry[:sequence]] = if component_entry[:maximum] > 1
93-
RepeatingComponent[component]
93+
RepeatingComponent.new(component_entry[:class],self, component)
9494
else
9595
component
9696
end
97-
else
98-
return values[component_entry[:sequence]]
9997
end
98+
99+
return values[component_entry[:sequence]]
100100
end
101101

102102
class RepeatingComponent < Array
103+
def initialize(klass, parent, *args)
104+
@klass = klass
105+
@parent = parent
106+
107+
self.push(*args)
108+
end
109+
110+
def build
111+
self.push(@klass.new :parent => @parent)
112+
113+
yield self[-1] if block_given?
114+
self[-1]
115+
end
116+
103117
def to_s
104118
self.map(&:to_s).join
105119
end

0 commit comments

Comments
 (0)