Class: FlattenRecord::Meta::Column
- Inherits:
-
Node
- Object
- Node
- FlattenRecord::Meta::Column
show all
- Defined in:
- lib/flatten_record/meta/column.rb
Instance Attribute Summary collapse
Attributes inherited from Node
#children, #model, #parent, #target_model
Instance Method Summary
collapse
Methods inherited from Node
#prefix, #traverse_by
Constructor Details
#initialize(parent, col, target_model, model) ⇒ Column
Returns a new instance of Column.
6
7
8
9
10
11
|
# 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
|
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
4
5
6
|
# File 'lib/flatten_record/meta/column.rb', line 4
def column
@column
end
|
Instance Method Details
#denormalize(instance, to_record) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# 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 ⇒ Object
13
14
15
|
# File 'lib/flatten_record/meta/column.rb', line 13
def name
parent.prefix + @column.name.to_s
end
|
#nullify(to_record) ⇒ Object
34
35
36
37
38
|
# File 'lib/flatten_record/meta/column.rb', line 34
def nullify(to_record)
assign_value(to_record, name) do |record|
nil
end
end
|
#type ⇒ Object
17
18
19
|
# File 'lib/flatten_record/meta/column.rb', line 17
def type
@column.type
end
|