Class: SeedGimmick::SeedFile
- Inherits:
-
Object
- Object
- SeedGimmick::SeedFile
- Includes:
- Finder
- Defined in:
- lib/seed_gimmick/seed_file.rb
Instance Attribute Summary collapse
-
#inflector ⇒ Object
readonly
Returns the value of attribute inflector.
-
#seed_file ⇒ Object
readonly
Returns the value of attribute seed_file.
Instance Method Summary collapse
- #bootstrap! ⇒ Object
- #custom_action {|_model, load_file| ... } ⇒ Object
-
#initialize(seed_dir, seed_file) ⇒ SeedFile
constructor
A new instance of SeedFile.
- #load_file ⇒ Object
Constructor Details
#initialize(seed_dir, seed_file) ⇒ SeedFile
Returns a new instance of SeedFile.
7 8 9 10 |
# File 'lib/seed_gimmick/seed_file.rb', line 7 def initialize(seed_dir, seed_file) @inflector = Inflector.new(seed_dir) @seed_file = seed_file end |
Instance Attribute Details
#inflector ⇒ Object (readonly)
Returns the value of attribute inflector.
5 6 7 |
# File 'lib/seed_gimmick/seed_file.rb', line 5 def inflector @inflector end |
#seed_file ⇒ Object (readonly)
Returns the value of attribute seed_file.
5 6 7 |
# File 'lib/seed_gimmick/seed_file.rb', line 5 def seed_file @seed_file end |
Instance Method Details
#bootstrap! ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/seed_gimmick/seed_file.rb', line 16 def bootstrap! custom_action do |model, data| ActiveRecord::Migration.say_with_time(model.model_name.plural) do model.transaction do model.delete_all model.import(data.map {|rec| model.new(rec) }) end end end rescue LoadFailed => e puts e. end |
#custom_action {|_model, load_file| ... } ⇒ Object
29 30 31 |
# File 'lib/seed_gimmick/seed_file.rb', line 29 def custom_action yield(_model, load_file) if block_given? end |
#load_file ⇒ Object
12 13 14 |
# File 'lib/seed_gimmick/seed_file.rb', line 12 def load_file SeedIO.get(seed_file).load_data end |