Class: Ghost::Seeder::Models::GenericSeed
- Inherits:
-
Object
- Object
- Ghost::Seeder::Models::GenericSeed
show all
- Defined in:
- lib/ghost/seeder/models/generic_seed.rb,
lib/ghost/seeder/models/generic_seed/yaml_bindings.rb
Defined Under Namespace
Classes: YamlBindings
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(attributes) ⇒ GenericSeed
Returns a new instance of GenericSeed.
44
45
46
47
48
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 44
def initialize(attributes)
@attributes = attributes
@record = OpenStruct.new(attributes)
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
42
43
44
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 42
def attributes
@attributes
end
|
#record ⇒ Object
Returns the value of attribute record.
42
43
44
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 42
def record
@record
end
|
Class Method Details
.klass ⇒ Object
39
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 39
def klass; raise NotImplementedError; end
|
.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(yaml_bindings.helper)
)
end
|
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
|
.yaml_bindings ⇒ Object
35
36
37
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 35
def yaml_bindings
YamlBindings.new
end
|
Instance Method Details
#seed! ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/ghost/seeder/models/generic_seed.rb', line 50
def seed!
if record_exists?
Logger.info "#{self.class} exists:", record_slug
raise "#{record_slug} not expected to exist!" if Runner.wipe_db?
else
create_record!
end
end
|