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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/alba/resource.rb +13 -2
- data/lib/alba/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 405e177e9e1fcadf7dbb164d3ac6924e1b3563547f715fedb698211b527a9604
|
|
4
|
+
data.tar.gz: 2c534708583345ac9090c83b3ddc939b0c8bd335ed77017f554edb28578d0396
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 71f4712ac28d457fe9bf997fb127288ed66d7d2231ffd6dd438b2eb5c1dd82ff9e3e5c4000415c513012a582cda3d3c3e73fdf0beb4cc96b8583ff9a658dfa75
|
|
7
|
+
data.tar.gz: '07439ccffc5b48a0d5d4286236acadf4cc3e89ff1afa0a882a87c1fe5640015096a4cd85839cebdc4d6ef350a77043a494bfe4d7b6cff99f8e7db2ab9f8b3db0'
|
data/Gemfile.lock
CHANGED
data/lib/alba/resource.rb
CHANGED
|
@@ -47,9 +47,16 @@ module Alba
|
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def serializable_hash(with_key: true)
|
|
50
|
-
|
|
51
|
-
attribute
|
|
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
|
data/lib/alba/version.rb
CHANGED