pragma-decorator 2.2.3 → 2.2.4

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: d1f2bd7c761c330889bdc0ade7c83f1e9cd6921fc8c81d5b5fc3352bfdc114a9
4
- data.tar.gz: d2bf1594ada1c8793dee81d0bccb0768ad24b8e6b2a797c148e247c0bde2e4be
3
+ metadata.gz: 1a95d2a912a1328c91c7ba4bd2cb023ebe3772bf67900fed17e7e6119a0e4a1a
4
+ data.tar.gz: 6fe2f0c3e0a87767d25f31e06b4fa8d3dd00fa420456c98f9b47ddb3ee0185a3
5
5
  SHA512:
6
- metadata.gz: e149d329a44e39fe7004bd5a79a5612ef2ef8dd9cf0893f871d009ffe47ebb759ad39ee10d98947a3a11948b9403ce1dd0038f93c8940d9dcf6253cb85fc236a
7
- data.tar.gz: f879896b77db56e45224138a0e0f59289a7ddf8e602d4b4f876ebb7a60fa04a69b57bba64fc7bc93c1a8aa3f6fd064c0e715b129faa4ca84dc03b377b826d0aa
6
+ metadata.gz: 4764e283b3fc8f3d5528f648096a4684dba6f322c0fb59f6a6da32399cfe7bf1c1d56ab9b57e0c6dffa5f658f3dfc17a5509d988adcea15091fb439f0be29101
7
+ data.tar.gz: 1fd589f81ff1e00d7e01ba98fb19ef10a812096ac10e471fe707000f7b71d7feb3604298889b8013503cc418d6c86fcd321578ee9a290cf064d989be0c1ebbc7
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.2.4]
11
+
12
+ ### Fixed
13
+
14
+ - Fixed an issue where expanding a property would expand properties with the same name in associated objects
15
+
10
16
  ## [2.2.3]
11
17
 
12
18
  ### Fixed
@@ -74,7 +80,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
74
80
 
75
81
  First Pragma 2 release.
76
82
 
77
- [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.2...HEAD
83
+ [Unreleased]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.4...HEAD
84
+ [2.2.4]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.3...v2.2.4
78
85
  [2.2.3]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.2...v2.2.3
79
86
  [2.2.2]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.1...v2.2.2
80
87
  [2.2.1]: https://github.com/pragmarb/pragma-decorator/compare/v2.2.0...v2.2.1
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Pragma::Decorator
2
2
 
3
3
  [![Build Status](https://travis-ci.org/pragmarb/pragma-decorator.svg?branch=master)](https://travis-ci.org/pragmarb/pragma-decorator)
4
- [![Dependency Status](https://gemnasium.com/badges/github.com/pragmarb/pragma-decorator.svg)](https://gemnasium.com/github.com/pragmarb/pragma-decorator)
5
4
  [![Coverage Status](https://coveralls.io/repos/github/pragmarb/pragma-decorator/badge.svg?branch=master)](https://coveralls.io/github/pragmarb/pragma-decorator?branch=master)
6
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/e51e8d7489eb72ab97ba/maintainability)](https://codeclimate.com/github/pragmarb/pragma-decorator/maintainability)
7
6
 
@@ -184,7 +183,7 @@ Rendering an invoice will now create the following representation:
184
183
  }
185
184
  ```
186
185
 
187
- You can pass `expand[]=customer` as a request parameter and have the `customer` property expanded
186
+ You can pass `expand[]=customer` as a request parameter and have the `customer` property expanded
188
187
  into a full object!
189
188
 
190
189
  ```json
@@ -197,7 +196,7 @@ into a full object!
197
196
  ```
198
197
 
199
198
  This also works for nested associations. For instance, if the customer decorator had a `company`
200
- association, you could pass `expand[]=customer&expand[]=customer.company` to get the company
199
+ association, you could pass `expand[]=customer&expand[]=customer.company` to get the company
201
200
  expanded too.
202
201
 
203
202
  Note that you will have to pass the associations to expand as a user option when rendering:
@@ -227,9 +226,9 @@ module API
227
226
  class Collection < Pragma::Decorator::Base
228
227
  include Pragma::Decorator::Collection
229
228
  decorate_with Instance # specify the instance decorator
230
-
229
+
231
230
  property :total_cents, exec_context: :decorator
232
-
231
+
233
232
  def total_cents
234
233
  represented.sum(:total_cents)
235
234
  end
@@ -266,7 +265,7 @@ about the entire collection (not just the current page) in the response.
266
265
 
267
266
  ### Pagination
268
267
 
269
- Speaking of pagination, you can use `Pragma::Decorator::Pagination` in combination with
268
+ Speaking of pagination, you can use `Pragma::Decorator::Pagination` in combination with
270
269
  `Collection` to include pagination data in your response:
271
270
 
272
271
  ```ruby
@@ -277,7 +276,7 @@ module API
277
276
  class Collection < Pragma::Decorator::Base
278
277
  include Pragma::Decorator::Collection
279
278
  include Pragma::Decorator::Pagination
280
-
279
+
281
280
  decorate_with Instance
282
281
  end
283
282
  end
@@ -312,9 +311,33 @@ Which will produce the following JSON:
312
311
  }
313
312
  ```
314
313
 
315
- It works with both [will_paginate](https://github.com/mislav/will_paginate) and
314
+ It works with both [will_paginate](https://github.com/mislav/will_paginate) and
316
315
  [Kaminari](https://github.com/kaminari/kaminari)!
317
316
 
317
+ ### Restricting property visibility
318
+
319
+ If you want to show or hide certain properties programmatically, you can do it with the `if` option:
320
+
321
+ ```ruby
322
+ module API
323
+ module V1
324
+ module User
325
+ module Decorator
326
+ class Instance < Pragma::Decorator::Base
327
+ property :id
328
+ property :first_name
329
+ property :last_name
330
+ property :email, if: -> (user_options:, decorated:, **) {
331
+ # Only show the email to admins or to the same user.
332
+ user_options[:current_user].admin? || user_options[:current_user] == decorated
333
+ }
334
+ end
335
+ end
336
+ end
337
+ end
338
+ end
339
+ ```
340
+
318
341
  ## Contributing
319
342
 
320
343
  Bug reports and pull requests are welcome on GitHub at https://github.com/pragmarb/pragma-decorator.
@@ -106,12 +106,8 @@ module Pragma
106
106
 
107
107
  expected_beginning = "#{reflection.property}."
108
108
 
109
- expand.reject { |value| value.to_s == reflection.property.to_s }.map do |value|
110
- if value.start_with?(expected_beginning)
111
- value.sub(expected_beginning, '')
112
- else
113
- value
114
- end
109
+ expand.select { |value| value.start_with?(expected_beginning) }.map do |value|
110
+ value.sub(expected_beginning, '')
115
111
  end
116
112
  end
117
113
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pragma
4
4
  module Decorator
5
- VERSION = '2.2.3'
5
+ VERSION = '2.2.4'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.3
4
+ version: 2.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-27 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: roar
@@ -194,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  requirements: []
196
196
  rubyforge_project:
197
- rubygems_version: 2.7.4
197
+ rubygems_version: 2.7.5
198
198
  signing_key:
199
199
  specification_version: 4
200
200
  summary: Convert your API resources into JSON with minimum hassle.