sinja 1.0.0.pre1 → 1.0.0.pre2

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
  SHA1:
3
- metadata.gz: 1ca76b5776f261ca35dbf3d7728b8f6c5e17b720
4
- data.tar.gz: eb1238aab2e77a50558b6445a0cd5055e3fe9f39
3
+ metadata.gz: 7c550d3cff0b520955dbd6add3f45fe426d0ba03
4
+ data.tar.gz: 2c0273185088e63db97d8a1de1e6c8612f9999c8
5
5
  SHA512:
6
- metadata.gz: 9134e5396394e7b0f92305e88df7777e4abbd39e0f1b0da839e5382629dd59d97bdd41c72cc45bd2455578bc332d2381b6aa49548653333b21f7965fe4db5e28
7
- data.tar.gz: 6907c31c9ecbe601b2eb1f93accedf39288d2cf20be57df6e96a295a1baddc8dbc4f662d1a50e367eb0806718d69e8daf8d77fe54e971ea3a7c1e6ccc89ff71f
6
+ metadata.gz: beaec25e26829f91f373e886449a64d10629f4905c1fb809576522aa866cd7843bd61c263fb219e566fe17fe2f31c59d0565c5c4230d10e9acd23bd4b09dc781
7
+ data.tar.gz: d7d470ba61bc03da60129b9e8566b5bd98fdcf7e6223f4e59e72c112bca2fdbfc8d026e209aeb4a651493281a6e38e0f247733ddd906dbefd4c2bce66ee44177
data/README.md CHANGED
@@ -277,6 +277,17 @@ end
277
277
  : Returns the `data` key of the deserialized request payload (with symbolized
278
278
  names).
279
279
 
280
+ **dedasherize**
281
+ : Takes a string or symbol and returns the string or symbol with any and all
282
+ dashes transliterated to underscores.
283
+
284
+ **dedasherize_names**
285
+ : Takes a hash and returns the hash with its keys dedasherized (deeply).
286
+
287
+ **role?**
288
+ : Takes a list of role(s) and returns true if it has members in common with the
289
+ current user's role(s).
290
+
280
291
  **serialize_model**
281
292
  : Takes a model (and optional hash of JSONAPI::Serializers options) and returns
282
293
  a serialized model.
@@ -295,13 +306,6 @@ end
295
306
  and returns a serialized collection if non-empty, or the root metadata if
296
307
  present, or a HTTP status 204.
297
308
 
298
- **dedasherize**
299
- : Takes a string or symbol and returns the string or symbol with any and all
300
- dashes transliterated to underscores.
301
-
302
- **dedasherize_names**
303
- : Takes a hash and returns the hash with its keys dedasherized (deeply).
304
-
305
309
  **sideloaded?**
306
310
  : Returns true if the request was invoked from another action helper.
307
311
 
@@ -626,8 +630,8 @@ end
626
630
  ```
627
631
 
628
632
  You may invoke an action helper keyword without a block to modify the options
629
- (i.e. roles) of a previously-registered action helper while preseving the
630
- existing behavior:
633
+ (i.e. roles and sideloading) of a previously-registered action helper while
634
+ preseving the existing behavior:
631
635
 
632
636
  ```ruby
633
637
  resource :bars do
@@ -68,20 +68,24 @@ module Sinja
68
68
 
69
69
  # Walk the tree and try to exclude based on fetch and pluck permissions
70
70
  included.keep_if do |termstr|
71
- # Start cursor at root of current resource
72
- roles = settings._resource_roles
73
-
74
- termstr.split('.').all? do |term|
75
- break true unless roles
76
-
77
- rel_roles =
78
- roles.dig(:has_many, term.to_sym, :fetch) ||
79
- roles.dig(:has_one, term.to_sym, :pluck)
71
+ catch :keep? do
72
+ *terms, last_term = termstr.split('.')
73
+
74
+ # Start cursor at root of current resource
75
+ roles = settings._resource_roles
76
+ terms.each do |term|
77
+ # Move cursor through each term, avoiding the default proc,
78
+ # halting if no roles found, i.e. client asked to include
79
+ # something that Sinja doesn't know about
80
+ throw :keep?, true \
81
+ unless roles = settings._sinja.resource_roles.fetch(term.pluralize.to_sym, nil)
82
+ end
80
83
 
81
- # Move cursor ahead for next iteration (if necessary), avoiding default proc
82
- roles = settings._sinja.resource_roles.fetch(term.pluralize.to_sym, nil)
84
+ roles =
85
+ roles.dig(:has_many, last_term.pluralize.to_sym, :fetch) ||
86
+ roles.dig(:has_one, last_term.singularize.to_sym, :pluck)
83
87
 
84
- rel_roles && (rel_roles.empty? || rel_roles === memoized_role)
88
+ throw :keep?, roles && (roles.empty? || roles === memoized_role)
85
89
  end
86
90
  end
87
91
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sinja
3
- VERSION = '1.0.0.pre1'
3
+ VERSION = '1.0.0.pre2'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinja
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre1
4
+ version: 1.0.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Pastore