field_mapper 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/field_mapper/custom/field.rb +8 -1
- data/lib/field_mapper/custom/plat.rb +2 -0
- data/lib/field_mapper/standard/field.rb +6 -2
- data/lib/field_mapper/standard/plat.rb +3 -1
- data/lib/field_mapper/version.rb +1 -1
- data/test/custom/converter_test.rb +4 -0
- data/test/custom/plat_example.rb +5 -0
- data/test/custom/plat_test.rb +6 -0
- data/test/standard/converter_test.rb +10 -0
- data/test/standard/plat_example.rb +3 -1
- data/test/standard/plat_test.rb +7 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43226c49e641e6c7534c9aa0656857af80d4e8e0
|
4
|
+
data.tar.gz: 9169cce64f196bbd5a8ecad35ef5c9fdf57bb34c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b5fb6da267576062469504cdf7c93fc07d07a1d26912f5431f89648a16106328a89958d8d43b75fa316152848d74c190576a921bd72fd6a8c5b04ab478cc64
|
7
|
+
data.tar.gz: 0e78802579e987fafab953d42b31e114b9372f446c97413d08189916b85c7392a6abd229e5d14bb0799e8c3a6bae6968c6404c228c1baf2e6dad9787f67eae82
|
@@ -23,13 +23,14 @@ module FieldMapper
|
|
23
23
|
type: nil,
|
24
24
|
desc: nil,
|
25
25
|
default: nil,
|
26
|
+
placeholder: nil,
|
26
27
|
standard_field: nil,
|
27
28
|
custom_to_standard: DefaultFlipper,
|
28
29
|
standard_to_custom: DefaultFlipper,
|
29
30
|
&block
|
30
31
|
)
|
31
32
|
type ||= standard_field.type unless standard_field.nil?
|
32
|
-
super name, type: type, desc: desc, default: default
|
33
|
+
super name, type: type, desc: desc, default: default, placeholder: placeholder
|
33
34
|
|
34
35
|
@standard_field = standard_field
|
35
36
|
@custom_to_standard = custom_to_standard
|
@@ -42,6 +43,12 @@ module FieldMapper
|
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
46
|
+
attr_writer :placeholder
|
47
|
+
|
48
|
+
def placeholder
|
49
|
+
@placeholder || standard_field.placeholder
|
50
|
+
end
|
51
|
+
|
45
52
|
def value(value, standard: nil, priority: nil)
|
46
53
|
@values ||= []
|
47
54
|
@values << FieldMapper::Custom::Value.new(
|
@@ -19,6 +19,7 @@ module FieldMapper
|
|
19
19
|
type: nil,
|
20
20
|
desc: nil,
|
21
21
|
default: nil,
|
22
|
+
placeholder: nil,
|
22
23
|
standard: nil,
|
23
24
|
custom_to_standard: FieldMapper::Custom::Field::DefaultFlipper,
|
24
25
|
standard_to_custom: FieldMapper::Custom::Field::DefaultFlipper,
|
@@ -31,6 +32,7 @@ module FieldMapper
|
|
31
32
|
type: type,
|
32
33
|
desc: desc,
|
33
34
|
default: default,
|
35
|
+
placeholder: placeholder,
|
34
36
|
standard_field: standard_plat.fields[standard],
|
35
37
|
custom_to_standard: custom_to_standard,
|
36
38
|
standard_to_custom: standard_to_custom
|
@@ -12,20 +12,24 @@ module FieldMapper
|
|
12
12
|
:type,
|
13
13
|
:desc,
|
14
14
|
:default,
|
15
|
-
:values
|
15
|
+
:values,
|
16
16
|
)
|
17
17
|
|
18
|
+
attr_accessor :placeholder
|
19
|
+
|
18
20
|
def initialize(
|
19
21
|
name,
|
20
22
|
type: nil,
|
21
23
|
desc: nil,
|
22
|
-
default: nil
|
24
|
+
default: nil,
|
25
|
+
placeholder: nil
|
23
26
|
)
|
24
27
|
raise TypeNotSpecified.new("type not specified for: #{name}") if type.nil?
|
25
28
|
@name = name.to_sym
|
26
29
|
@type = type
|
27
30
|
@desc= desc
|
28
31
|
@default = default
|
32
|
+
@placeholder = placeholder
|
29
33
|
end
|
30
34
|
|
31
35
|
def list?
|
@@ -26,6 +26,7 @@ module FieldMapper
|
|
26
26
|
type: nil,
|
27
27
|
desc: nil,
|
28
28
|
default: nil,
|
29
|
+
placeholder: nil,
|
29
30
|
&block
|
30
31
|
)
|
31
32
|
field_names[attr_name(name)] = name
|
@@ -34,7 +35,8 @@ module FieldMapper
|
|
34
35
|
name,
|
35
36
|
type: type,
|
36
37
|
desc: desc,
|
37
|
-
default: default
|
38
|
+
default: default,
|
39
|
+
placeholder: placeholder
|
38
40
|
)
|
39
41
|
|
40
42
|
field.instance_exec(&block) if block_given?
|
data/lib/field_mapper/version.rb
CHANGED
data/test/custom/plat_example.rb
CHANGED
@@ -54,5 +54,10 @@ module Custom
|
|
54
54
|
field :parent_plat, type: FieldMapper::Types::Plat[Custom::PlatExample], standard: :parent
|
55
55
|
field :child_plats, type: FieldMapper::Types::List[Custom::PlatExample], standard: :children, default: []
|
56
56
|
|
57
|
+
field :time, standard: :timestamp, type: String,
|
58
|
+
standard_to_custom: -> (value, standard_instance: nil) {
|
59
|
+
value.strftime("%Y-%m-%m") unless value.nil?
|
60
|
+
}
|
61
|
+
|
57
62
|
end
|
58
63
|
end
|
data/test/custom/plat_test.rb
CHANGED
@@ -61,6 +61,7 @@ module Custom
|
|
61
61
|
"color" => nil,
|
62
62
|
"painter" => nil,
|
63
63
|
"characters" => nil,
|
64
|
+
"time" => nil,
|
64
65
|
"parent_plat" => {
|
65
66
|
"_node_id" => @instance.parent_plat.object_id,
|
66
67
|
"_flat" => false,
|
@@ -70,6 +71,7 @@ module Custom
|
|
70
71
|
"color" => nil,
|
71
72
|
"painter" => nil,
|
72
73
|
"characters" => nil,
|
74
|
+
"time" => nil,
|
73
75
|
"parent_plat" => nil,
|
74
76
|
"child_plats" => []
|
75
77
|
},
|
@@ -98,5 +100,9 @@ module Custom
|
|
98
100
|
}
|
99
101
|
end
|
100
102
|
|
103
|
+
test "placeholder" do
|
104
|
+
assert @instance.class.fields[:name].placeholder == "TYPE YOUR NAME"
|
105
|
+
end
|
106
|
+
|
101
107
|
end
|
102
108
|
end
|
@@ -84,5 +84,15 @@ module Standard
|
|
84
84
|
assert custom.parent_plat.to_hash.merge(_node_id: nil) == custom_parent.to_hash.merge(_node_id: nil)
|
85
85
|
end
|
86
86
|
|
87
|
+
test "convert_to (different datatype)" do
|
88
|
+
@standard.timestamp = Time.now
|
89
|
+
custom = @converter.convert_to(Custom::PlatExample)
|
90
|
+
assert custom.time == @standard.timestamp.strftime("%Y-%m-%m")
|
91
|
+
end
|
92
|
+
|
93
|
+
test "placeholder" do
|
94
|
+
assert @standard.class.fields[:name].placeholder == "TYPE YOUR NAME"
|
95
|
+
end
|
96
|
+
|
87
97
|
end
|
88
98
|
end
|
@@ -3,7 +3,7 @@ require_relative "../test_helper"
|
|
3
3
|
module Standard
|
4
4
|
class PlatExample < FieldMapper::Standard::Plat
|
5
5
|
|
6
|
-
field :name, type: String
|
6
|
+
field :name, type: String, placeholder: "TYPE YOUR NAME"
|
7
7
|
field :desc, type: String
|
8
8
|
|
9
9
|
field :score, default: 2, type: Integer do
|
@@ -44,5 +44,7 @@ module Standard
|
|
44
44
|
field :parent, type: FieldMapper::Types::Plat[Standard::PlatExample]
|
45
45
|
field :children, type: FieldMapper::Types::List[Standard::PlatExample], default: []
|
46
46
|
|
47
|
+
field :timestamp, type: Time
|
48
|
+
|
47
49
|
end
|
48
50
|
end
|
data/test/standard/plat_test.rb
CHANGED
@@ -108,6 +108,7 @@ module Standard
|
|
108
108
|
"artist" => nil,
|
109
109
|
"day" => nil,
|
110
110
|
"letters" => ["a", "b"],
|
111
|
+
"timestamp" => nil,
|
111
112
|
"parent"=>{
|
112
113
|
"_node_id" => parent.object_id,
|
113
114
|
"_flat" => false,
|
@@ -120,6 +121,7 @@ module Standard
|
|
120
121
|
"artist" => nil,
|
121
122
|
"day" => nil,
|
122
123
|
"letters" => ["a", "b"],
|
124
|
+
"timestamp" => nil,
|
123
125
|
"parent" => nil,
|
124
126
|
"children" => [@instance.object_id]
|
125
127
|
},
|
@@ -136,6 +138,7 @@ module Standard
|
|
136
138
|
"artist" => nil,
|
137
139
|
"day" => nil,
|
138
140
|
"letters" => ["a", "b"],
|
141
|
+
"timestamp" => nil,
|
139
142
|
"parent" => @instance.object_id,
|
140
143
|
"children" => []
|
141
144
|
},
|
@@ -151,6 +154,7 @@ module Standard
|
|
151
154
|
"artist" => nil,
|
152
155
|
"day" => nil,
|
153
156
|
"letters" => ["a", "b"],
|
157
|
+
"timestamp" => nil,
|
154
158
|
"parent" => @instance.object_id,
|
155
159
|
"children" => []
|
156
160
|
}
|
@@ -183,8 +187,9 @@ module Standard
|
|
183
187
|
"artist" => nil,
|
184
188
|
"day" => nil,
|
185
189
|
"letters" => "[\"a\",\"b\"]",
|
186
|
-
"
|
187
|
-
"
|
190
|
+
"timestamp" => nil,
|
191
|
+
"parent" => "{\"_node_id\":#{parent.object_id},\"_flat\":true,\"name\":null,\"desc\":null,\"score\":2,\"color\":null,\"camelCase\":null,\"PascalCase\":null,\"artist\":null,\"day\":null,\"letters\":\"[\\\"a\\\",\\\"b\\\"]\",\"parent\":null,\"children\":\"[#{@instance.object_id}]\",\"timestamp\":null}",
|
192
|
+
"children" => "[{\"_node_id\":#{child1.object_id},\"_flat\":true,\"name\":null,\"desc\":null,\"score\":2,\"color\":null,\"camelCase\":null,\"PascalCase\":null,\"artist\":null,\"day\":null,\"letters\":\"[\\\"a\\\",\\\"b\\\"]\",\"parent\":#{@instance.object_id},\"children\":[],\"timestamp\":null},{\"_node_id\":#{child2.object_id},\"_flat\":true,\"name\":null,\"desc\":null,\"score\":2,\"color\":null,\"camelCase\":null,\"PascalCase\":null,\"artist\":null,\"day\":null,\"letters\":\"[\\\"a\\\",\\\"b\\\"]\",\"parent\":#{@instance.object_id},\"children\":[],\"timestamp\":null}]"
|
188
193
|
}
|
189
194
|
|
190
195
|
actual = @instance.to_hash(flatten: true)
|