flexserializer 1.0.6 → 1.1.0
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 +4 -4
- data/lib/flexserializer/base.rb +9 -11
- data/lib/flexserializer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d25c98717d847a3ea12cb1029bc6eadc777605aa
|
4
|
+
data.tar.gz: 9976bffb95211464c3c48576dc6f55768da1013e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad5ff72c3674430f28c7fc0bb24800b20182941f7c627533156d03cd9986ebe9492a2c062a50e4195bb2023b65d1a981f612486e58738b57aedf6357261512d6
|
7
|
+
data.tar.gz: fec80587e01cea7876a26e9e613af2676f9bd4f8205a5186c4f388526b7217227b949da4469bf4c4bd590361704df4be861e315e81fdd02beab228b0e54af826
|
data/lib/flexserializer/base.rb
CHANGED
@@ -2,10 +2,9 @@ module Flexserializer
|
|
2
2
|
class Base < ActiveModel::Serializer
|
3
3
|
class << self
|
4
4
|
attr_accessor :groups, :data_default_attributes
|
5
|
-
|
6
|
-
def default_attributes(
|
7
|
-
|
8
|
-
self.data_default_attributes = attrs
|
5
|
+
|
6
|
+
def default_attributes(&block)
|
7
|
+
self.data_default_attributes = block
|
9
8
|
end
|
10
9
|
|
11
10
|
def group(group_name, &block)
|
@@ -13,29 +12,28 @@ module Flexserializer
|
|
13
12
|
self.groups[group_name] = block
|
14
13
|
end
|
15
14
|
end
|
16
|
-
|
15
|
+
|
17
16
|
def initialize(object, options = {})
|
18
17
|
self.class.data_default_attributes ||= []
|
19
18
|
define_attributes(options[:group])
|
20
19
|
super(object, options)
|
21
20
|
end
|
22
|
-
|
21
|
+
|
23
22
|
def define_attributes(group)
|
24
23
|
clear_data
|
25
24
|
define_default_attrs
|
26
25
|
return unless self.class.groups.keys.include?(group)
|
27
26
|
define_group_attrs(group)
|
28
27
|
end
|
29
|
-
|
28
|
+
|
30
29
|
def clear_data
|
31
30
|
self.class._attributes_data = {}
|
32
31
|
end
|
33
|
-
|
32
|
+
|
34
33
|
def define_default_attrs
|
35
|
-
self.class.data_default_attributes
|
36
|
-
self.class.data_default_attributes.each { |attr| self.class.attribute(attr) }
|
34
|
+
self.class.data_default_attributes.call
|
37
35
|
end
|
38
|
-
|
36
|
+
|
39
37
|
def define_group_attrs(group)
|
40
38
|
self.class.groups[group].call
|
41
39
|
end
|