defaultable 0.0.8 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,33 +1,37 @@
1
- module Defaultable
2
- class Serialization
3
- cattr_accessor :settings_class
1
+ # Include this module to support ActiveRecord serialization
4
2
 
3
+ module Defaultable
4
+ module Serialization
5
5
  # Called to deserialize data to ruby object.
6
- def load(data)
7
- overrides = {}
6
+ extend ActiveSupport::Concern
8
7
 
9
- if data
10
- obj = raw_load(data)
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)
12
- overrides = obj.as_hash
13
- end
8
+ module ClassMethods
9
+ def load(data)
10
+ overrides = {}
14
11
 
15
- self.settings_class.new(overrides)
16
- end
12
+ if data
13
+ obj = raw_load(data)
14
+ raise TypeError, "Deserialized object is not of type #{self.name}. Got #{obj.class}" unless obj.kind_of?(self)
15
+ overrides = obj.as_hash
16
+ end
17
17
 
18
- # Called to convert from ruby object to serialized data.
19
- def dump(obj)
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?
18
+ self.new(overrides)
19
+ end
21
20
 
22
- if obj.nil?
23
- self.class.settings_class.new
24
- else
25
- obj.class.new(obj.registry.as_hash).to_yaml if obj
21
+ # Called to convert from ruby object to serialized data.
22
+ def dump(obj)
23
+ raise TypeError, "Serialization failed: Object is not of type #{self.name}." if !obj.kind_of?(self) && !obj.nil?
24
+
25
+ if obj.nil?
26
+ self.new
27
+ else
28
+ obj.class.new(obj.registry.as_hash).to_yaml if obj
29
+ end
26
30
  end
27
- end
28
31
 
29
- def raw_load(data)
30
- YAML.load(data)
31
- end
32
+ def raw_load(data)
33
+ YAML.load(data)
34
+ end
35
+ end
32
36
  end
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module Defaultable
2
- VERSION = "0.0.8"
2
+ VERSION = "1.0.0"
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.8
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-07 00:00:00.000000000 Z
12
+ date: 2012-03-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
- requirement: &70208167086660 !ruby/object:Gem::Requirement
16
+ requirement: &70147235341740 !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: *70208167086660
24
+ version_requirements: *70147235341740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70208167095520 !ruby/object:Gem::Requirement
27
+ requirement: &70147235341100 !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: *70208167095520
35
+ version_requirements: *70147235341100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: pry
38
- requirement: &70208178015520 !ruby/object:Gem::Requirement
38
+ requirement: &70147235340580 !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: *70208178015520
46
+ version_requirements: *70147235340580
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: awesome_print
49
- requirement: &70208178013640 !ruby/object:Gem::Requirement
49
+ requirement: &70147235340000 !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: *70208178013640
57
+ version_requirements: *70147235340000
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: activerecord
60
- requirement: &70208178010280 !ruby/object:Gem::Requirement
60
+ requirement: &70147235339280 !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: *70208178010280
68
+ version_requirements: *70147235339280
69
69
  description: Defaultable is an extendable class to allow easy method chaining for
70
70
  settings along with defaults.
71
71
  email: