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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c533fed241c4d7aecbc9bfd54ed267442f21ef55
4
- data.tar.gz: f8b51b655f705e1a7c0a1041d2a8b15bfda143f2
3
+ metadata.gz: bb205b02af511da788ea2c3c642813826ffc8bac
4
+ data.tar.gz: 61e613f7ffec07456079c6aaa500e2add65c6324
5
5
  SHA512:
6
- metadata.gz: 7b7572599adc99c9b9600a402410b1914609bbdf4646f5a2c4081971b315bcd91b64c537a49dac6936aa0b260a48606c8ae6c0b7dc57de15b8184dc85965c92f
7
- data.tar.gz: 5536aa7fcf2a26af90e82f720cec7346bcd3ffb83065eb8155503f3b500a46b6735dc05cb3624d3aeed3e73c8fa72302760a57a4f4d45ab175451797213d7af5
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.cast(value)
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.cast(value)
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.cast(value)
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
 
@@ -1,3 +1,3 @@
1
1
  module FieldMapper
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: field_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins