class FlattenRecord::Meta::Column
Attributes
column[R]
Public Class Methods
new(parent, col, target_model, model)
click to toggle source
Calls superclass method
# File lib/flatten_record/meta/column.rb, line 6 def initialize(parent, col, target_model, model) super(parent, target_model, model) @column = Struct. new(:name, :default, :type, :null). new(col.name, col.default, col.type, col.null) end
Public Instance Methods
denormalize(instance, to_record)
click to toggle source
# File lib/flatten_record/meta/column.rb, line 21 def denormalize(instance, to_record) return nullify(to_records) if instance.blank? if instance.respond_to?(@column.name) to_record = assign_value(to_record, name) do |record| instance.send(@column.name.to_sym) end else raise "#{@column.name} is not found in #{instance.inspect}" end to_record end
name()
click to toggle source
# File lib/flatten_record/meta/column.rb, line 13 def name parent.prefix + @column.name.to_s end
nullify(to_record)
click to toggle source
# File lib/flatten_record/meta/column.rb, line 34 def nullify(to_record) assign_value(to_record, name) do |record| nil end end
type()
click to toggle source
# File lib/flatten_record/meta/column.rb, line 17 def type @column.type end
Protected Instance Methods
assign_value(to_record, name) { |record| ... }
click to toggle source
# File lib/flatten_record/meta/column.rb, line 41 def assign_value(to_record, name, &block) if to_record.respond_to?(:each) to_record = to_record.collect do |record| value = yield(record) record.send("#{name}=", value) record end else to_record.send("#{name}=", yield(to_record)) end to_record end