Module: SeedBox

Defined in:
lib/seed_box.rb,
lib/seed_box/railtie.rb,
lib/seed_box/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#seed(model, find_or_create_by, update_with = {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/seed_box.rb', line 8

def seed(model, find_or_create_by, update_with = {})
  record = model.where(find_or_create_by).first_or_initialize

  record.update_attributes(update_with)

  handle_errors(record, find_or_create_by, update_with)
end

#seed_file(name) ⇒ Object



24
25
26
# File 'lib/seed_box.rb', line 24

def seed_file(name)
  File.new(Rails.root.join('db/seeds').join(name))
end

#seed_once(model, find_or_create_by, create_with = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/seed_box.rb', line 16

def seed_once(model, find_or_create_by, create_with = {})
  record = model.where(find_or_create_by).first_or_initialize(create_with)

  record.save

  handle_errors(record, find_or_create_by, create_with)
end