Class: Copyable::Declarations::Columns
- Inherits:
-
Declaration
- Object
- Declaration
- Copyable::Declarations::Columns
- Defined in:
- lib/copyable/declarations/columns.rb
Class Method Summary collapse
-
.execute(column_list, original_model, new_model, overrides) ⇒ Object
this is the algorithm for copying columns from the original record to the brand new copy of the record according to the instructions given in the copyable declaration.
Methods inherited from Declaration
Class Method Details
.execute(column_list, original_model, new_model, overrides) ⇒ Object
this is the algorithm for copying columns from the original record to the brand new copy of the record according to the instructions given in the copyable declaration
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/copyable/declarations/columns.rb', line 8 def self.execute(column_list, original_model, new_model, overrides) column_list.each do |column, advice| # when create_copy! is called, you can pass in a hash of # overrides that trumps the instructions in the copyable # declaration if overrides[column.to_sym].present? value = overrides[column.to_sym] elsif overrides[column.to_s].present? value = overrides[column.to_s] elsif advice == :copy value = original_model.send(column) elsif advice == :do_not_copy value = nil elsif advice.is_a? Proc value = advice.call(original_model) else = "Error in copyable:columns of #{original_model.class.name}: " << "the column '#{column}' must be :copy, :do_not_copy, or a lambda." raise ColumnError.new() end new_model.send("#{column}=", value) end end |