Class: Sprig::Reap::SeedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sprig/reap/seed_file.rb

Constant Summary collapse

DEFAULT_NAMESPACE =
'records'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SeedFile

Returns a new instance of SeedFile.

Raises:

  • (ArgumentError)


7
8
9
10
11
# File 'lib/sprig/reap/seed_file.rb', line 7

def initialize(model)
  raise ArgumentError, 'Must initialize with a Sprig::Reap::Model' unless model.is_a? Model

  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



5
6
7
# File 'lib/sprig/reap/seed_file.rb', line 5

def model
  @model
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/sprig/reap/seed_file.rb', line 17

def exists?
  File.exists?(path)
end

#pathObject



13
14
15
# File 'lib/sprig/reap/seed_file.rb', line 13

def path
  Rails.root.join('db', 'seeds', Sprig::Reap.target_env, "#{model.to_s.tableize.gsub('/', '_')}.yml")
end

#writeObject



21
22
23
24
25
# File 'lib/sprig/reap/seed_file.rb', line 21

def write
  initialize_file do |file, namespace|
    file.write model.to_yaml(:namespace => namespace)
  end
end