defaultable 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,24 @@
1
1
  module Defaultable
2
2
  class Serialization
3
- class_attribute :settings_class
3
+ cattr_accessor :settings_class
4
4
 
5
5
  # Called to deserialize data to ruby object.
6
6
  def load(data)
7
+ overrides = {}
8
+
7
9
  if data
8
10
  obj = raw_load(data)
9
-
10
11
  raise TypeError, "Deserialized object is not of type #{self.class.settings_class.name}. Got #{obj.class}" unless obj.is_a?(self.class.settings_class)
11
-
12
- # The reason we do the following is because defaults may have changed
13
- # after the point of serialization. To avoid not having them, we instantiate the class
14
- # again, we the previous values. This prevents not having data.
15
- obj.class.new(obj.as_hash)
12
+ overrides = obj.as_hash
16
13
  end
14
+
15
+ self.settings_class.new(overrides)
17
16
  end
18
17
 
19
18
  # Called to convert from ruby object to serialized data.
20
19
  def dump(obj)
21
20
  raise TypeError, "Serialization failed: Object is not of type #{self.class.settings_class.name}." if !obj.is_a?(self.class.settings_class) && !obj.nil?
22
21
 
23
- # We need to use the registry because we don't want to store defaults that weren't overwritten
24
22
  if obj.nil?
25
23
  self.class.settings_class.new
26
24
  else
@@ -1,3 +1,3 @@
1
1
  module Defaultable
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defaultable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70100058426160 !ruby/object:Gem::Requirement
16
+ requirement: &70208167086660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.2'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70100058426160
24
+ version_requirements: *70208167086660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70100058423640 !ruby/object:Gem::Requirement
27
+ requirement: &70208167095520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '2.7'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70100058423640
35
+ version_requirements: *70208167095520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &70100058421280 !ruby/object:Gem::Requirement
38
+ requirement: &70208178015520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70100058421280
46
+ version_requirements: *70208178015520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: awesome_print
49
- requirement: &70100058437380 !ruby/object:Gem::Requirement
49
+ requirement: &70208178013640 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70100058437380
57
+ version_requirements: *70208178013640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activerecord
60
- requirement: &70100058432520 !ruby/object:Gem::Requirement
60
+ requirement: &70208178010280 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.2'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70100058432520
68
+ version_requirements: *70208178010280
69
69
  description: Defaultable is an extendable class to allow easy method chaining for
70
70
  settings along with defaults.
71
71
  email: