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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3aed40acbba4ac1426e88a436c565d9cc742a389
|
4
|
+
data.tar.gz: fa25229c80a6e19ba9e1415dbba58c08bf547740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b7ff3b653bb30f2875dd5b72d9eda469403d73988ea56cffef1e19cb86da00ebabe7d198aafc947d865a1d3eb9242eb4506ed988773af15f4b96b0dcd24c52f
|
7
|
+
data.tar.gz: 025f70ac0557b428b0ac6e477a7df940e67e6e35e8046ff69413bf4038c2ee18d324687d1473e494267b39d2318ccdc63414e02d1ad046da9b52106a3e62fb08
|
data/CHANGELOG.md
CHANGED
@@ -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(:
|
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
|
-
|
7
|
-
|
8
|
-
|
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
|
-
|
17
|
-
|
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
|
-
|
13
|
+
def load(obj)
|
14
|
+
@converter.externalize(obj)
|
31
15
|
end
|
16
|
+
end
|
32
17
|
|
33
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
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
|