field_mapper 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/field_mapper/standard/plat.rb +11 -6
- data/lib/field_mapper/version.rb +1 -1
- 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: bb205b02af511da788ea2c3c642813826ffc8bac
|
4
|
+
data.tar.gz: 61e613f7ffec07456079c6aaa500e2add65c6324
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57df3d16ce7625cdadb0b5d36ce4010e9e0635da6780e67de3f65bc7ad1afde42ac5e297adacf0284eb67925672e5cced70c24866b3825c44483aac3488a68e4
|
7
|
+
data.tar.gz: 53e945b37c0060f3814b55cef0a2f605080f3112a276c412a16b41313a3336fe3acf8e289d9061296024095bd62747963bf5f50048b4bdd29bb72e8c4d5644dc
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "digest/md5"
|
2
|
+
require "observer"
|
2
3
|
require_relative "../errors"
|
3
4
|
require_relative "../name_helper"
|
4
5
|
require_relative "../marshaller"
|
@@ -7,6 +8,7 @@ require_relative "field"
|
|
7
8
|
module FieldMapper
|
8
9
|
module Standard
|
9
10
|
class Plat
|
11
|
+
include Observable
|
10
12
|
include FieldMapper::NameHelper
|
11
13
|
include FieldMapper::Marshaller
|
12
14
|
|
@@ -100,7 +102,7 @@ module FieldMapper
|
|
100
102
|
def []=(field_name, value)
|
101
103
|
field = self.class.find_field(field_name)
|
102
104
|
raise FieldNotDefined if field.nil?
|
103
|
-
assign_param field_name, field
|
105
|
+
assign_param field_name, cast_value(field, value)
|
104
106
|
end
|
105
107
|
|
106
108
|
def to_hash(flatten: false, history: {}, include_meta: true, placeholders: false)
|
@@ -180,6 +182,12 @@ module FieldMapper
|
|
180
182
|
|
181
183
|
protected
|
182
184
|
|
185
|
+
def cast_value(field, value)
|
186
|
+
changed
|
187
|
+
notify_observers :before_cast, field.name.to_s, value
|
188
|
+
field.cast(value)
|
189
|
+
end
|
190
|
+
|
183
191
|
def plat_values
|
184
192
|
self.class.plat_fields.values.reduce([]) do |memo, field|
|
185
193
|
value = send(attr_name(field.name))
|
@@ -224,7 +232,7 @@ module FieldMapper
|
|
224
232
|
if !field.default.nil?
|
225
233
|
value = field.default
|
226
234
|
value = value.clone rescue value
|
227
|
-
assign_param name, field
|
235
|
+
assign_param name, cast_value(field, value)
|
228
236
|
end
|
229
237
|
end
|
230
238
|
end
|
@@ -234,7 +242,7 @@ module FieldMapper
|
|
234
242
|
params.each do |name, value|
|
235
243
|
field = self.class.fields[name]
|
236
244
|
next if field.nil?
|
237
|
-
value = field
|
245
|
+
value = cast_value(field, value)
|
238
246
|
next if value.nil?
|
239
247
|
next if field.list? && value.compact.empty?
|
240
248
|
assign_param name, value
|
@@ -245,9 +253,6 @@ module FieldMapper
|
|
245
253
|
end
|
246
254
|
|
247
255
|
def assign_param(name, value)
|
248
|
-
if defined? before_assign_param
|
249
|
-
value = before_assign_param(name, value)
|
250
|
-
end
|
251
256
|
instance_variable_set "@#{attr_name(name)}", value
|
252
257
|
end
|
253
258
|
|
data/lib/field_mapper/version.rb
CHANGED