Class: Cuttings::Cutting

Inherits:
Object
  • Object
show all
Defined in:
lib/cuttings/cutting.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_name, options = {}, &block) ⇒ Cutting

Returns a new instance of Cutting.



5
6
7
8
# File 'lib/cuttings/cutting.rb', line 5

def initialize(model_name, options = {}, &block)
  self.model_name = model_name
  self.processor = block
end

Instance Attribute Details

#model_nameObject

Returns the value of attribute model_name.



3
4
5
# File 'lib/cuttings/cutting.rb', line 3

def model_name
  @model_name
end

#processorObject

Returns the value of attribute processor.



3
4
5
# File 'lib/cuttings/cutting.rb', line 3

def processor
  @processor
end

Instance Method Details

#attachment(path) ⇒ Object



23
24
25
26
27
# 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) ⇒ Object



19
20
21
# File 'lib/cuttings/cutting.rb', line 19

def create(attrs)
  model.create!(attrs)
end

#modelObject



10
11
12
# File 'lib/cuttings/cutting.rb', line 10

def model
  @model ||= model_name.constantize
end

#runObject



14
15
16
17
# File 'lib/cuttings/cutting.rb', line 14

def run
  processor && instance_eval(&processor)
  close_all_open_files
end