Class: Ghost::Seeder::Models::GenericSeed
- Inherits:
-
Object
- Object
- Ghost::Seeder::Models::GenericSeed
- Defined in:
- lib/ghost/seeder/models/generic_seed.rb,
lib/ghost/seeder/models/generic_seed/yaml_bindings.rb
Direct Known Subclasses
Defined Under Namespace
Classes: YamlBindings
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#record ⇒ Object
readonly
Returns the value of attribute record.
Class Method Summary collapse
- .load_fixtures(identifier) ⇒ Object
- .perform_queries ⇒ Object
- .seeds ⇒ Object
- .wipe_records! ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes) ⇒ GenericSeed
constructor
A new instance of GenericSeed.
- #seed! ⇒ Object
Constructor Details
#initialize(attributes) ⇒ GenericSeed
Returns a new instance of GenericSeed.
38 39 40 41 42 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 38 def initialize(attributes) @attributes = attributes # allow calling hash attributes as methods @record = OpenStruct.new(attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
36 37 38 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 36 def attributes @attributes end |
#record ⇒ Object (readonly)
Returns the value of attribute record.
36 37 38 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 36 def record @record end |
Class Method Details
.load_fixtures(identifier) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 21 def load_fixtures(identifier) YAML.load( ERB.new( File.read( "./config/seed/fixtures/#{identifier}.yml" ) ).result(YamlBindings.new.helper) ) end |
.perform_queries ⇒ Object
10 11 12 13 14 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 10 def perform_queries seeds.each do |record| new(record).seed! end end |
.seeds ⇒ Object
31 32 33 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 31 def seeds load_fixtures klass.to_s.downcase.pluralize end |
.wipe_records! ⇒ Object
16 17 18 19 |
# File 'lib/ghost/seeder/models/generic_seed.rb', line 16 def wipe_records! Logger.warn "wiping", klass klass.destroy_all end |