Class: Cuttings::Cutting
- Inherits:
-
Object
- Object
- Cuttings::Cutting
- Defined in:
- lib/cuttings/cutting.rb
Instance Attribute Summary collapse
-
#model_name ⇒ Object
Returns the value of attribute model_name.
-
#processor ⇒ Object
Returns the value of attribute processor.
Instance Method Summary collapse
- #attachment(path) ⇒ Object
- #create(attrs) ⇒ Object
-
#initialize(model_name, options = {}, &block) ⇒ Cutting
constructor
A new instance of Cutting.
- #model ⇒ Object
- #run ⇒ Object
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, = {}, &block) self.model_name = model_name self.processor = block end |
Instance Attribute Details
#model_name ⇒ Object
Returns the value of attribute model_name.
3 4 5 |
# File 'lib/cuttings/cutting.rb', line 3 def model_name @model_name end |
#processor ⇒ Object
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 (path) file = File.open(Rails.root.join('lib', 'seeds', 'attachments', path)) << file file end |
#create(attrs) ⇒ Object
19 20 21 |
# File 'lib/cuttings/cutting.rb', line 19 def create(attrs) model.create!(attrs) end |
#model ⇒ Object
10 11 12 |
# File 'lib/cuttings/cutting.rb', line 10 def model @model ||= model_name.constantize end |
#run ⇒ Object
14 15 16 17 |
# File 'lib/cuttings/cutting.rb', line 14 def run processor && instance_eval(&processor) close_all_open_files end |