lib/rubyonacid/factories/repeat.rb in rubyonacid-0.3.1 vs lib/rubyonacid/factories/repeat.rb in rubyonacid-0.4.0
- old
+ new
@@ -3,30 +3,29 @@
module RubyOnAcid
#Gets values from a source factory and returns the same value the given number of times before getting a fresh value.
class RepeatFactory < Factory
- #Factory to get values from.
- attr_accessor :source_factory
#The number of times to repeat a value for a given key.
attr_accessor :repeat_count
- def initialize(source_factory = nil, repeat_count = 2)
+ #Takes a hash with all keys supported by Factory, plus these keys and defaults:
+ # :repeat_count => 2
+ def initialize(options = {})
super
- @source_factory = source_factory
- @repeat_count = repeat_count
+ @repeat_count = options[:repeat_count] || 2
@repeat_counts = {}
@values = {}
end
- #Returns the value of get_unit on the source factory the assigned number of times.
+ #Returns the value of get_unit from the source factories the assigned number of times.
def get_unit(key)
@repeat_counts[key] ||= 0
if @repeat_counts[key] >= @repeat_count
@values[key] = nil
@repeat_counts[key] = 0
end
- @values[key] ||= @source_factory.get_unit(key)
+ @values[key] ||= super
@repeat_counts[key] += 1
@values[key]
end
end
\ No newline at end of file