Class ActiveWarehouse::Builder::TestDataBuilder
In: lib/active_warehouse/builder/test_data_builder.rb
Parent: Object

Unlike the RandomDataBuilder, which puts truly random data in the warehouse, this generator uses collections of possible values to construct semi-understandable data

Methods

build   new  

Public Class methods

[Source]

    # File lib/active_warehouse/builder/test_data_builder.rb, line 8
 8:       def initialize
 9:         
10:       end

Public Instance methods

Usage:

  fields = [:id,:product_name,:product_description,:suggested_retail_price]
  field_definitions = {
    :id => :sequence,                                                  # symbol or string
    :product_name => [['Foo','Bar']['Baz','Bing']],                    # array
    :product_description => IpsumLorumGenerator                        # class
    :suggested_retail_price => RandomNumberGenerator.new(0.00, 100.00) # generator instance
  }

[Source]

    # File lib/active_warehouse/builder/test_data_builder.rb, line 21
21:       def build(fields, field_definitions, options={})
22:         options[:number] ||= 100
23:         rows = []
24:         generators = {}
25:         # set up all of the generators first
26:         field_definitions.each do |name, fd|
27:           case fd
28:           when Class
29:             generators[name] = fd.new
30:           when String, Symbol
31:             generators[name] = "#{fd}Generator".classify.constantize.new
32:           when Array
33:             generators[name] = NameGenerator.new(fd)
34:           when Generator
35:             generators[name] = fd
36:           else
37:             raise "Invalid generator specified: #{fd}"
38:           end
39:         end
40:         
41:         # generate all of the rows
42:         0.upto(options[:number]) do
43:           row = {}
44:           fields.each do |field|
45:             row[field] = generators[field].next(options)
46:           end
47:           rows << row
48:         end
49:         
50:         rows
51:       end

[Validate]