activerecord-attribute_converter 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5ac88613a83588985a6f7b7729ba74958bd5a53
4
- data.tar.gz: c9d1fb6f43d5c45aeec99088a0c6d6f6252fc057
3
+ metadata.gz: 3aed40acbba4ac1426e88a436c565d9cc742a389
4
+ data.tar.gz: fa25229c80a6e19ba9e1415dbba58c08bf547740
5
5
  SHA512:
6
- metadata.gz: 0302cc8783014305e5de3597c455ce5d72b44fe81cc760eff5ab649c18cd135ae8594f1780bfaef8bf46ac3a5c37bc2063c3f6ba1d174578e815d6e228d37e2c
7
- data.tar.gz: 7aec1c0d8d9b5067dc709180360d9d9ef5dfbe5fc043f73c13c3a6743da3e7a23e52ea8b186f70c9d24e268e75f9707a17ecf70a52d7262dae82e57a011733d9
6
+ metadata.gz: 6b7ff3b653bb30f2875dd5b72d9eda469403d73988ea56cffef1e19cb86da00ebabe7d198aafc947d865a1d3eb9242eb4506ed988773af15f4b96b0dcd24c52f
7
+ data.tar.gz: 025f70ac0557b428b0ac6e477a7df940e67e6e35e8046ff69413bf4038c2ee18d324687d1473e494267b39d2318ccdc63414e02d1ad046da9b52106a3e62fb08
data/CHANGELOG.md CHANGED
@@ -1,2 +1,8 @@
1
- ## 2014-03-17
1
+ ## 0.1.2 (2014-03-18)
2
+ - Use ActiveRecord serializer instead of callbacks
3
+
4
+ ## 0.1.1 (2014-03-18)
5
+ - Require modules eagerly
6
+
7
+ ## 0.1.0 (2014-03-17)
2
8
  - Initial release
@@ -5,7 +5,7 @@ require 'activerecord/attribute_converter/relation'
5
5
  require 'activerecord/attribute_converter/version'
6
6
 
7
7
  ActiveSupport.on_load(:active_record) do
8
- ActiveRecord::Base.send(:include, ActiveRecord::AttributeConverter::Base)
8
+ ActiveRecord::Base.send(:extend, ActiveRecord::AttributeConverter::Base)
9
9
 
10
10
  ActiveRecord::PredicateBuilder.singleton_class.class_eval do
11
11
  include ActiveRecord::AttributeConverter::PredicateBuilder
@@ -1,47 +1,31 @@
1
- require 'active_support/concern'
2
-
3
1
  module ActiveRecord
4
2
  module AttributeConverter
5
3
  module Base
6
- extend ActiveSupport::Concern
7
-
8
- def internalize_attributes
9
- self.class.attribute_converters.each do |attr, converter|
10
- if attributes.has_key?(attr)
11
- send("#{attr}=", converter.internalize(send(attr)))
12
- end
4
+ class Serializer
5
+ def initialize(converter)
6
+ @converter = converter
13
7
  end
14
- end
15
8
 
16
- def externalize_attributes
17
- self.class.attribute_converters.each do |attr, converter|
18
- if attributes.has_key?(attr)
19
- send("#{attr}=", converter.externalize(send(attr)))
20
- end
9
+ def dump(obj)
10
+ @converter.internalize(obj)
21
11
  end
22
- end
23
-
24
- module ClassMethods
25
- def apply_converter(attr, converter)
26
- unless @attribute_converters
27
- install_attribute_converter
28
- end
29
12
 
30
- self.attribute_converters[attr.to_s] = converter
13
+ def load(obj)
14
+ @converter.externalize(obj)
31
15
  end
16
+ end
32
17
 
33
- def install_attribute_converter
18
+ def apply_converter(attr, converter)
19
+ unless @attribute_converters
34
20
  @attribute_converters = {}
35
-
36
- before_save :internalize_attributes
37
-
38
- after_save :externalize_attributes
39
- after_find :externalize_attributes
40
21
  end
41
22
 
42
- def attribute_converters
43
- @attribute_converters || {}
44
- end
23
+ serialize attr, Serializer.new(converter)
24
+ self.attribute_converters[attr.to_s] = converter
25
+ end
26
+
27
+ def attribute_converters
28
+ @attribute_converters || {}
45
29
  end
46
30
  end
47
31
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module AttributeConverter
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-attribute_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki