Class: FieldMapper::Custom::Plat
Constant Summary
Constants included
from Marshaller
Marshaller::OPTIONS
Class Attribute Summary collapse
#node_id
Class Method Summary
collapse
Instance Method Summary
collapse
#[], #[]=, #after_convert, #cache_key, field_names, fields, find_field, has_plat_fields?, #initialize, inspect, #inspect, plat_fields, #scope, #snapshot, symbolize_hash, #to_hash
Methods included from NameHelper
#attr_name
Methods included from Marshaller
#marshal, #unmarshal
Class Attribute Details
.standard_plat ⇒ Object
Returns the value of attribute standard_plat.
12
13
14
|
# File 'lib/field_mapper/custom/plat.rb', line 12
def standard_plat
@standard_plat
end
|
Class Method Details
.basic_mapped_field(name) ⇒ Object
57
58
59
|
# File 'lib/field_mapper/custom/plat.rb', line 57
def basic_mapped_field(name)
field name, standard: name
end
|
.basic_mapped_fields(*names) ⇒ Object
53
54
55
|
# File 'lib/field_mapper/custom/plat.rb', line 53
def basic_mapped_fields(*names)
names.each { |name| basic_mapped_field(name) }
end
|
.field(name, type: nil, desc: nil, default: nil, placeholder: nil, standard: nil, custom_to_standard: FieldMapper::Custom::Field::DefaultFlipper, standard_to_custom: FieldMapper::Custom::Field::DefaultFlipper, &block) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/field_mapper/custom/plat.rb', line 18
def field(
name,
type: nil,
desc: nil,
default: nil,
placeholder: nil,
standard: nil,
custom_to_standard: FieldMapper::Custom::Field::DefaultFlipper,
standard_to_custom: FieldMapper::Custom::Field::DefaultFlipper,
&block
)
field_names[attr_name(name)] = name
field = fields[name] = FieldMapper::Custom::Field.new(
name,
type: type,
desc: desc,
default: default,
placeholder: placeholder,
standard_field: standard_plat.fields[standard],
custom_to_standard: custom_to_standard,
standard_to_custom: standard_to_custom
)
field.instance_exec(&block) if block_given?
define_method(attr_name name) do
self[name]
end
define_method("#{attr_name name}=") do |value|
self[name] = value
end
end
|
.fields_by_standard_name ⇒ Object
65
66
67
68
69
70
|
# File 'lib/field_mapper/custom/plat.rb', line 65
def fields_by_standard_name
@fields_by_standard_name ||= fields.values.reduce({}) do |memo, field|
memo[field.standard_field.name] = field unless field.standard_field.nil?
memo
end
end
|
.find_mapped_fields(standard_field) ⇒ Object
61
62
63
|
# File 'lib/field_mapper/custom/plat.rb', line 61
def find_mapped_fields(standard_field)
fields.values.select { |field| field.standard_field == standard_field }
end
|
.new_from_standard_keyed_params(standard_keyed_params) ⇒ Object
100
101
102
|
# File 'lib/field_mapper/custom/plat.rb', line 100
def new_from_standard_keyed_params(standard_keyed_params)
new standard_keys_to_custom_keys(standard_keyed_params)
end
|
.set_standard(standard_plat) ⇒ Object
14
15
16
|
# File 'lib/field_mapper/custom/plat.rb', line 14
def set_standard(standard_plat)
@standard_plat = standard_plat
end
|
.standard_keys_to_custom_keys(standard_keyed_params) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/field_mapper/custom/plat.rb', line 72
def standard_keys_to_custom_keys(standard_keyed_params)
standard_keyed_params.reduce({}) do |memo, standard_param|
key = standard_param.first
value = standard_param.last
field = fields_by_standard_name[key.to_sym]
if !field.nil?
case field.type.name
when "FieldMapper::Types::Plat" then
if value.is_a?(Hash)
value = field.type.type.standard_keys_to_custom_keys(value)
end
when "FieldMapper::Types::List" then
if field.type.type.ancestors.include?(Plat)
if value.is_a?(Array)
value = value.compact.map do |val|
field.type.type.standard_keys_to_custom_keys(val)
end
end
end
end
memo[field.name] = value
end
memo
end
end
|