Class: FlattenRecord::Meta::ComputeColumn
- Defined in:
- lib/flatten_record/meta/compute_column.rb
Instance Attribute Summary
Attributes inherited from Column
Attributes inherited from Node
#children, #model, #parent, #target_model
Instance Method Summary collapse
- #denormalize(instance, to_record) ⇒ Object
-
#initialize(parent, method, type, target_model, model, options = {}) ⇒ ComputeColumn
constructor
A new instance of ComputeColumn.
Methods inherited from Column
#column_prefix, #name, #nullify, #type
Methods inherited from Node
Constructor Details
#initialize(parent, method, type, target_model, model, options = {}) ⇒ ComputeColumn
4 5 6 7 |
# File 'lib/flatten_record/meta/compute_column.rb', line 4 def initialize(parent, method, type, target_model, model, ={}) @column = new_column(method, [:default], :integer, [:not_null]) super(parent, @column, target_model, model) end |
Instance Method Details
#denormalize(instance, to_record) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flatten_record/meta/compute_column.rb', line 9 def denormalize(instance, to_record) first_record = to_record.respond_to?(:each) ? to_record.flatten.first : to_record #if first_record.class.method_defined?(@column.name) begin to_record = assign_value(to_record, name) do |record| record.send("compute_#{@column.name}".to_sym, instance) end rescue raise "compute_#{@column.name} is not found in #{to_record.inspect}" end to_record end |