class Cuttings::Cutting

Attributes

model_name[RW]
processor[RW]

Public Class Methods

new(model_name, options = {}, &block) click to toggle source
# File lib/cuttings/cutting.rb, line 5
def initialize(model_name, options = {}, &block)
  self.model_name = model_name
  self.processor = block
end

Public Instance Methods

attachment(path) click to toggle source
# File lib/cuttings/cutting.rb, line 23
def attachment(path)
  file = File.open(Rails.root.join('lib', 'seeds', 'attachments', path))
  attachment_files << file
  file
end
create(attrs) click to toggle source
# File lib/cuttings/cutting.rb, line 19
def create(attrs)
  model.create!(attrs)
end
model() click to toggle source
# File lib/cuttings/cutting.rb, line 10
def model
  @model ||= model_name.constantize
end
run() click to toggle source
# File lib/cuttings/cutting.rb, line 14
def run
  processor && instance_eval(&processor)
  close_all_open_files
end

Private Instance Methods

attachment_files() click to toggle source
# File lib/cuttings/cutting.rb, line 31
def attachment_files
  @attachment_files ||= []
end
close_all_open_files() click to toggle source
# File lib/cuttings/cutting.rb, line 35
def close_all_open_files
  attachment_files.each(&:close)
  attachment_files.clear
end