shreddies 0.4.0 → 0.5.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/README.md +18 -0
- data/lib/shreddies/json.rb +8 -0
- data/lib/shreddies/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7084791be003f88c17be2b03597510c729b0394ff604fb2d212884b63a41ede
|
4
|
+
data.tar.gz: 3b3209280042108e5e69edef03d68753984258db142367bc8e63538918cf5949
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71e3dcafc78e8f775ba62fdb17de776162348ccb30449425736653108b8bd2d5288adaeaa5b71b35ceb278ddf71ce2d28bea7c34f1239740e1836c382f8a3e41
|
7
|
+
data.tar.gz: 3a4a854d56c8c773bd0d5ea42802688fc95779741a69d88a91718f54eca47aa16b33c883291caf66d6c9f0f71137f4de76a4cb18cecc552f04fec10c6023d30f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -165,6 +165,24 @@ The `Collection` and `Single` modules can be defined and they will be automatica
|
|
165
165
|
|
166
166
|
If false, the returned keys will not be transformed. The default is to deeply transform all keys to camelCase.
|
167
167
|
|
168
|
+
#### `except`
|
169
|
+
|
170
|
+
Pass one or more attribute names as a Symbol or Array of Symbols, and these will be excluded from the results:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
User.all.as_json(except: [:first_name, :age])
|
174
|
+
```
|
175
|
+
|
176
|
+
#### `only`
|
177
|
+
|
178
|
+
Pass one or more attribute names as a Symbol or Array of Symbols, and _ONLY_ these will be included in the results:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
User.all.as_json(only: :first_name)
|
182
|
+
```
|
183
|
+
|
184
|
+
> Attributes must still be defined within the Serializer.
|
185
|
+
|
168
186
|
#### `index_by`
|
169
187
|
|
170
188
|
Give this option a property of your serialized subject as a Symbol, and the returned collection will be a Hash keyed by that property.
|
data/lib/shreddies/json.rb
CHANGED
@@ -65,6 +65,14 @@ module Shreddies
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# Filter out methods using the `only` or `except` options.
|
69
|
+
if options[:only]
|
70
|
+
options[:only] = Array(options[:only])
|
71
|
+
methods = methods.select { |x| options[:only].include? x }
|
72
|
+
elsif options[:except]
|
73
|
+
methods = methods.excluding(options[:except])
|
74
|
+
end
|
75
|
+
|
68
76
|
methods.map do |attr|
|
69
77
|
res = public_send(attr)
|
70
78
|
if res.is_a?(ActiveRecord::Relation) || res.is_a?(ActiveRecord::Base)
|
data/lib/shreddies/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shreddies
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Moss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|