Class: SeedData::DataManager
- Inherits:
-
Object
- Object
- SeedData::DataManager
- Defined in:
- lib/seed_data/data_manager.rb
Constant Summary collapse
- ANY_ENVIRONMENT =
'any'.freeze
Instance Attribute Summary collapse
-
#builder ⇒ Object
readonly
Returns the value of attribute builder.
-
#data_sets ⇒ Object
readonly
Returns the value of attribute data_sets.
-
#environment_variable ⇒ Object
readonly
Returns the value of attribute environment_variable.
Instance Method Summary collapse
-
#initialize(options) ⇒ DataManager
constructor
A new instance of DataManager.
- #load ⇒ Object
- #register(options) ⇒ Object
- #valid_data_sets ⇒ Object
Constructor Details
#initialize(options) ⇒ DataManager
Returns a new instance of DataManager.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/seed_data/data_manager.rb', line 12 def initialize() @data_sets = [] @environment_variable = [:environment_variable] || 'RACK_ENV' if [:builder] == nil raise SeedData::DataBuilderNotSpecifiedException.new end @builder = [:builder] end |
Instance Attribute Details
#builder ⇒ Object (readonly)
Returns the value of attribute builder.
7 8 9 |
# File 'lib/seed_data/data_manager.rb', line 7 def builder @builder end |
#data_sets ⇒ Object (readonly)
Returns the value of attribute data_sets.
6 7 8 |
# File 'lib/seed_data/data_manager.rb', line 6 def data_sets @data_sets end |
#environment_variable ⇒ Object (readonly)
Returns the value of attribute environment_variable.
8 9 10 |
# File 'lib/seed_data/data_manager.rb', line 8 def environment_variable @environment_variable end |
Instance Method Details
#load ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/seed_data/data_manager.rb', line 39 def load puts 'SeedData:: Load.' valid_data_sets.each do |itm| puts "SeedData:: Loading data set: #{itm[:data_set]}" @builder.build(itm[:data_set]) end puts 'SeedData:: Loading complete.' return true end |
#register(options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/seed_data/data_manager.rb', line 24 def register() if !.has_key?(:environment) [:environment] = ANY_ENVIRONMENT end if !.has_key?(:data_set) raise SeedData::InvalidRegistrationException.new('Invalid registration option, :data_set must be specified.') end @data_sets << return true end |
#valid_data_sets ⇒ Object
57 58 59 |
# File 'lib/seed_data/data_manager.rb', line 57 def valid_data_sets return @data_sets.select { |i| i[:environment] == ENV[@environment_variable] || i[:environment] == ANY_ENVIRONMENT } end |