Class: Skr::Core::DB::Seed
- Inherits:
-
Object
- Object
- Skr::Core::DB::Seed
- Defined in:
- lib/skr/core/db/seed.rb
Constant Summary collapse
- @@seeds =
[]
Class Method Summary collapse
- .add(&block) ⇒ Object
-
.execute! ⇒ Object
Loads the database with seed models Currently loads GlAccount, PaymentTerm, and Location.
Class Method Details
.add(&block) ⇒ Object
15 16 17 |
# File 'lib/skr/core/db/seed.rb', line 15 def add(&block) @@seeds.push(block) end |
.execute! ⇒ Object
Loads the database with seed models Currently loads GlAccount, PaymentTerm, and Location
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/skr/core/db/seed.rb', line 21 def execute! seeds_path = Pathname.new(__FILE__).dirname.join('seed') unless Location.default Location.create( code: Core.config.default_location_code, name: "System default", address: Address.new(name:"System default") ) end YAML::load( seeds_path.join('chart_of_accounts.yml').read ).each do | acct_data | GlAccount.where(number: acct_data['number'].to_s).any? || GlAccount.create!(acct_data) end YAML::load( seeds_path.join('payment_terms.yml').read ).each do | acct_data | PaymentTerm.where(code: acct_data['code'].to_s).any? || PaymentTerm.create!(acct_data) end @@seeds.each(&:call) end |