Sha256: 80012832b9e3430cf9f9f64296b48757405dd0c8e2490e46fded83906366dbe3
Contents?: true
Size: 898 Bytes
Versions: 6
Compression:
Stored size: 898 Bytes
Contents
require 'rubyonacid/factory' 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) super @source_factory = source_factory @repeat_count = repeat_count @repeat_counts = {} @values = {} end #Returns the value of get_unit on the source factory 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) @repeat_counts[key] += 1 @values[key] end end end
Version data entries
6 entries across 6 versions & 1 rubygems