Module: DataBuilder
- Extended by:
- DateGeneration, StandardGeneration, DataReader
- Defined in:
- lib/data_builder.rb,
lib/data_builder/version.rb,
lib/data_builder/generation.rb,
lib/data_builder/generation_date.rb,
lib/data_builder/generation_standard.rb
Defined Under Namespace
Modules: DateGeneration, StandardGeneration
Classes: Generation
Constant Summary
collapse
- VERSION =
"2.0.0".freeze
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
day_of_week, day_of_week_abbr, month, month_abbr, today, tomorrow, yesterday
catch_phrase, cell_phone, characters, city, company_name, country, credit_card_number, credit_card_type, domain_name, email_address, first_name, full_name, last_name, mask, name_prefix, name_suffix, paragraphs, phone_number, randomize, secondary_address, sentence, sentences, sequence, state, state_abbr, street_address, title, url, user_name, words, zip_code
Class Attribute Details
.data_contents ⇒ Object
Returns the value of attribute data_contents.
31
32
33
|
# File 'lib/data_builder.rb', line 31
def data_contents
@data_contents
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
17
18
19
|
# File 'lib/data_builder.rb', line 17
def parent
@parent
end
|
Class Method Details
.data_files_for(scenario) ⇒ Object
Also known as:
data_for_scenario
37
38
39
40
41
42
|
# File 'lib/data_builder.rb', line 37
def data_files_for(scenario)
tags = scenario.send(scenario.respond_to?(:tags) ? :tags : :source_tags)
tags.map(&:name).select { |t| t =~ /@databuilder_/ }.map do |t|
t.gsub('@databuilder_', '').to_sym
end
end
|
.default_data_path ⇒ Object
33
34
35
|
# File 'lib/data_builder.rb', line 33
def default_data_path
'data'
end
|
.generators ⇒ Object
50
51
52
|
# File 'lib/data_builder.rb', line 50
def generators
@generators || []
end
|
.included(caller) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/data_builder.rb', line 23
def self.included(caller)
@parent = caller
generators.each do |generator|
Generation.send :include, generator
end
end
|
.locale=(value) ⇒ Object
46
47
48
|
# File 'lib/data_builder.rb', line 46
def locale=(value)
Faker::Config.locale = value
end
|
.use_in_scenario(scenario, data_location = DataBuilder.data_path) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/data_builder.rb', line 77
def self.use_in_scenario(scenario, data_location = DataBuilder.data_path)
original_data_path = DataBuilder.data_path
DataBuilder.data_path = data_location
data_files = data_files_for(scenario)
DataBuilder.load("#{data_files.last}.yml") if data_files.count.positive?
DataBuilder.data_path = original_data_path
end
|
Instance Method Details
#data_about(key, specified = {}) ⇒ Object
Also known as:
data_from, data_for, using_data_for, using_data_from
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/data_builder.rb', line 55
def data_about(key, specified = {})
if key.is_a?(String) && key.match(%r{/})
file, record = key.split('/')
DataBuilder.load("#{file}.yml")
else
record = key.to_s
DataBuilder.load(builder_source) unless DataBuilder.data_contents
end
data = DataBuilder.data_contents[record]
raise ArgumentError, "Undefined key for data: #{key}" unless data
process_data(data.merge(specified.key?(record) ? specified[record] : specified).deep_copy)
end
|