Class: Sprig::Reap::SeedFile

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

Constant Summary collapse

DEFAULT_NAMESPACE =
'records'

Constants included from Logging

Logging::LOG_COLORS, Logging::LOG_LEVELS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ SeedFile

Returns a new instance of SeedFile.

Raises:

  • (ArgumentError)


9
10
11
12
13
# File 'lib/sprig/reap/seed_file.rb', line 9

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.



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

def model
  @model
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/sprig/reap/seed_file.rb', line 19

def exists?
  File.exists?(path)
end

#pathObject



15
16
17
# File 'lib/sprig/reap/seed_file.rb', line 15

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

#writeObject



23
24
25
26
27
28
# File 'lib/sprig/reap/seed_file.rb', line 23

def write
  initialize_file do |file, namespace|
    file.write model.to_yaml(:namespace => namespace)
    log_info "Successfully reaped records for #{model}...\r"
  end
end