Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/seed-fu.rb

Class Method Summary collapse

Class Method Details

.seed(*constraints, &block) ⇒ Object

Creates a single record of seed data for use with the db:seed rake task.

Parameters

constraints

Immutable reference attributes. Defaults to :id



73
74
75
# File 'lib/seed-fu.rb', line 73

def self.seed(*constraints, &block)
  SeedFu::Seeder.plant(self, *constraints, &block)
end

.seed_many(*constraints) ⇒ Object



82
83
84
85
86
87
88
89
90
91
# File 'lib/seed-fu.rb', line 82

def self.seed_many(*constraints)
  seeds = constraints.pop
  seeds.each do |seed_data|
    seed(*constraints) do |s|
      seed_data.each_pair do |k,v|
        s.send "#{k}=", v
      end
    end
  end
end

.seed_once(*constraints, &block) ⇒ Object



77
78
79
80
# File 'lib/seed-fu.rb', line 77

def self.seed_once(*constraints, &block)
  constraints << true
  SeedFu::Seeder.plant(self, *constraints, &block)
end