activejsonmodel 0.1.5 → 0.1.6

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
  SHA256:
3
- metadata.gz: 6358d312dd78f6dec607bfcc0417e3bb716c8029d19502701d2c96704107d0f7
4
- data.tar.gz: 0da1d126eead2748545c9455ac94a4b79c94e4278526ef9f78332104c63f121a
3
+ metadata.gz: dc97da5d920f8d4bd3086c08d7e785867d6aad6d76549ac5d4642d0dc7905269
4
+ data.tar.gz: be4f3c6d7b7eadee052cc42d7e7b7e3c4df3f7d86d9d673c6ae0c6dcd34f09f2
5
5
  SHA512:
6
- metadata.gz: 3e9d4ec02edfcdfc3ac5eea8ed235094e37d18be43e4980d1fc789219856c73fe442116c53362f5e36e91ca1a79f3a5845f7da85e6a0822dc0271e7a2b6c7e45
7
- data.tar.gz: 78b47a73bc4f50e8309655b01dbac8851377630941e1e85fba9c30e02e4f5a7c0c0a326c1bfd5e6fc3f0c0f04437a23e8b948a1295e235d609abfa91d0b2a40f
6
+ metadata.gz: 0ffe713e2616fff952482e90adab32f709634e6976040f7dd0c43fa34c5db81de5cf0f8f3829f83cfd9d54730618411d9b8003cfe1e415cf51111dc529a990cd
7
+ data.tar.gz: f28fee77d5d862f8615b146e7526d6593393518988f7ced44f1871914350e429dc0b1c44763674a1c1946f29699efa1bf3b1c114b87891a5133f1ac098a6352c
@@ -48,14 +48,13 @@ if Gem.find_files("symmetric-encryption").any? &&
48
48
  end
49
49
 
50
50
  def serialize(value)
51
- case value
52
- when @clazz
51
+ if value.respond_to?(:dump_to_json)
53
52
  SymmetricEncryption.encrypt(
54
- @clazz.dump(value),
53
+ value.dump_to_json,
55
54
  random_iv: true,
56
55
  type: :json
57
56
  )
58
- when ::Hash, ::HashWithIndifferentAccess, ::Array
57
+ elsif ::Hash === value || ::HashWithIndifferentAccess === value || ::Array === value
59
58
  SymmetricEncryption.encrypt(
60
59
  value,
61
60
  random_iv: true,
@@ -63,10 +63,9 @@ if Gem.find_files("active_record").any?
63
63
  end
64
64
 
65
65
  def serialize(value)
66
- case value
67
- when @clazz
68
- ::ActiveSupport::JSON.encode(@clazz.dump(value))
69
- when ::Hash, ::HashWithIndifferentAccess, ::Array
66
+ if value.respond_to?(:dump_to_json)
67
+ ::ActiveSupport::JSON.encode(value.dump_to_json)
68
+ elsif ::Hash === value || ::HashWithIndifferentAccess === value || ::Array === value
70
69
  ::ActiveSupport::JSON.encode(value)
71
70
  else
72
71
  super
@@ -564,7 +564,10 @@ module ActiveJsonModel
564
564
  #
565
565
  # @param val either an instance of this model or a Hash like object
566
566
  def active_json_model_cast(val)
567
- if val.is_a?(self)
567
+ # For polymorphic objects, it's possible that there won't be
568
+ # a base-class relationship, so just assume that if the
569
+ # object is an ActiveJsonModel object, it's good.
570
+ if val.respond_to?(:dump_to_json)
568
571
  val
569
572
  elsif val.is_a?(::Hash) || val.is_a?(::HashWithIndifferentAccess)
570
573
  self.load(val)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveJsonModel
4
- VERSION = "0.1.5".freeze
4
+ VERSION = "0.1.6".freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activejsonmodel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Morlok