alba 0.6.0 → 0.7.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
  SHA256:
3
- metadata.gz: efa21967c65ad6880f19fbb2ec2fd795ed1b71f477084056068b23984df60834
4
- data.tar.gz: 556f95a3ad12a7fdc591f8b7e336a7bc2d6c4b99710198f9bdc4e36b1389e0d2
3
+ metadata.gz: 405e177e9e1fcadf7dbb164d3ac6924e1b3563547f715fedb698211b527a9604
4
+ data.tar.gz: 2c534708583345ac9090c83b3ddc939b0c8bd335ed77017f554edb28578d0396
5
5
  SHA512:
6
- metadata.gz: 9f2bc512373e64a1ecda15c5797a5e9a1944f9fdc2a81f34f4af063d54c288fa53710bba9645fdbdec922b2642491bf0983830b7b806c3e6706099d48ed31c29
7
- data.tar.gz: 99c355f1ad8d2c26786b79d3f7889ac00b08444f72352a14f300eb25049efbe81792242d48c0c9bf760e5bce3e93d61f408a99ac38a93a252ca55954c0880162
6
+ metadata.gz: 71f4712ac28d457fe9bf997fb127288ed66d7d2231ffd6dd438b2eb5c1dd82ff9e3e5c4000415c513012a582cda3d3c3e73fdf0beb4cc96b8583ff9a658dfa75
7
+ data.tar.gz: '07439ccffc5b48a0d5d4286236acadf4cc3e89ff1afa0a882a87c1fe5640015096a4cd85839cebdc4d6ef350a77043a494bfe4d7b6cff99f8e7db2ab9f8b3db0'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alba (0.6.0)
4
+ alba (0.7.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -47,9 +47,16 @@ module Alba
47
47
  end
48
48
 
49
49
  def serializable_hash(with_key: true)
50
- serializable_hash = @_attributes.transform_values do |attribute|
51
- attribute.to_hash(@_resource)
50
+ get_attribute = lambda do |resource|
51
+ @_attributes.transform_values do |attribute|
52
+ attribute.to_hash(resource)
53
+ end
52
54
  end
55
+ serializable_hash = if collection?
56
+ @_resource.map(&get_attribute)
57
+ else
58
+ get_attribute.call(@_resource)
59
+ end
53
60
  with_key && @_key ? {@_key => serializable_hash} : serializable_hash
54
61
  end
55
62
  alias to_hash serializable_hash
@@ -65,6 +72,10 @@ module Alba
65
72
  klass.class_eval(&with)
66
73
  klass
67
74
  end
75
+
76
+ def collection?
77
+ @_resource.is_a?(Enumerable)
78
+ end
68
79
  end
69
80
 
70
81
  # Class methods
@@ -1,3 +1,3 @@
1
1
  module Alba
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - OKURA Masafumi