Module: CelluloidBenchmark::DataSources
- Included in:
- Visitor
- Defined in:
- lib/celluloid_benchmark/data_sources.rb
Instance Method Summary collapse
- #data_source(key) ⇒ Object
- #data_sources ⇒ Object
- #data_sources=(hash) ⇒ Object
- #empty?(key) ⇒ Boolean
- #raise_empty(key) ⇒ Object
- #random_data(key) ⇒ Object
Instance Method Details
#data_source(key) ⇒ Object
17 18 19 20 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 17 def data_source(key) raise_empty(key) if empty?(key) data_sources[key] end |
#data_sources ⇒ Object
7 8 9 10 11 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 7 def data_sources @data_sources ||= Hash.new do |hash, key| hash[key] = File.readlines("tmp/data/#{key}s.csv").map(&:strip) end end |
#data_sources=(hash) ⇒ Object
13 14 15 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 13 def data_sources=(hash) @data_sources = hash end |
#empty?(key) ⇒ Boolean
26 27 28 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 26 def empty?(key) data_sources[key].size == 0 end |
#raise_empty(key) ⇒ Object
22 23 24 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 22 def raise_empty(key) raise "Empty random data for '#{key}'. Ensure target has test data and run rake app:performance:get_random_data." end |
#random_data(key) ⇒ Object
3 4 5 |
# File 'lib/celluloid_benchmark/data_sources.rb', line 3 def random_data(key) data_source(key).sample end |