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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2af5104b81744b9e96b10b97df9b9a1ab6b56d2c
4
- data.tar.gz: 86ceddcf5f9d165b1fe46fbe5900dd451da215e0
3
+ metadata.gz: d25c98717d847a3ea12cb1029bc6eadc777605aa
4
+ data.tar.gz: 9976bffb95211464c3c48576dc6f55768da1013e
5
5
  SHA512:
6
- metadata.gz: 86ca7d1897a1f2e82aa038caf1a384fd6dae0aacc3a7767ee188e349c314695871ba8390e05c948ad45bff418915f59729361a59a790c6463258e237e21195c5
7
- data.tar.gz: 7e7e104d5a267e6fae7cb8eae6d1c9fc08ed9432d24293efda99af702aad2831ea49010a262d241e291cf838dbfc6dd8a70627bac4ef6c43012708174e78e64d
6
+ metadata.gz: ad5ff72c3674430f28c7fc0bb24800b20182941f7c627533156d03cd9986ebe9492a2c062a50e4195bb2023b65d1a981f612486e58738b57aedf6357261512d6
7
+ data.tar.gz: fec80587e01cea7876a26e9e613af2676f9bd4f8205a5186c4f388526b7217227b949da4469bf4c4bd590361704df4be861e315e81fdd02beab228b0e54af826
@@ -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(*attrs)
7
- attrs = attrs.first if attrs.first.class == Array
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 = self.class.data_default_attributes.first if self.class.data_default_attributes.first.class == Array
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
@@ -1,3 +1,3 @@
1
1
  module Flexserializer
2
- VERSION = "1.0.6"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexserializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - woodcrust