shreddies 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 362313f00cf053782a4cce7d2ce46b83e8ae078e6812c7c8bb485440f967c3a5
4
- data.tar.gz: e1f3f78c27fc4def477bfc1f3adb13fb101a57fbc6870add99dbac9f8efb0db4
3
+ metadata.gz: c7084791be003f88c17be2b03597510c729b0394ff604fb2d212884b63a41ede
4
+ data.tar.gz: 3b3209280042108e5e69edef03d68753984258db142367bc8e63538918cf5949
5
5
  SHA512:
6
- metadata.gz: 67d80f7708e475b54d8e99a5b24d4198091d0ccfef45a84c131539985bdc682bad234e3df12eb4e8351b3648296a2adffc71e796cd8b149a8336a85495d3acb3
7
- data.tar.gz: 62e767958dd0b0cd314204a2a7cd573ae7d4df0dd27bdf23a528e64eb4574c2b3e45a5aa9879674a9264c7b57c462f784741a8926e0a82108043396a6caded9e
6
+ metadata.gz: 71e3dcafc78e8f775ba62fdb17de776162348ccb30449425736653108b8bd2d5288adaeaa5b71b35ceb278ddf71ce2d28bea7c34f1239740e1836c382f8a3e41
7
+ data.tar.gz: 3a4a854d56c8c773bd0d5ea42802688fc95779741a69d88a91718f54eca47aa16b33c883291caf66d6c9f0f71137f4de76a4cb18cecc552f04fec10c6023d30f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shreddies (0.3.0)
4
+ shreddies (0.4.0)
5
5
  activerecord (>= 5)
6
6
  railties (>= 5)
7
7
 
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.
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Shreddies
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
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.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-15 00:00:00.000000000 Z
11
+ date: 2020-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord