moat 0.4 → 0.5

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
  SHA1:
3
- metadata.gz: 8650ce60afaf8d84d2f26e215e9d9a7ff5bc393a
4
- data.tar.gz: 14c91842fc823ce114c0eb19daac0070e5dae1b8
3
+ metadata.gz: 27fe35c24015fbbda8f21da12a438c55e96fe64f
4
+ data.tar.gz: f0b05ea91ff3a9281fa6dd0527b94a067c3ed088
5
5
  SHA512:
6
- metadata.gz: b31364a24bc83743555b7fb89f69591cf88ea2c544dad9e01a7e8e0cb02424b47a231da46dc2ba246fad0df987464f7cf472ced12fad0a6242ba3f1bd5098bdf
7
- data.tar.gz: 5ce3ba9dfb382042104995713ecc6a528aaf1282189ff35931d0de9d4700bb23fca1b7d03b4c407f5bf27c0e0999666316a94091d7a0f2cdf4121248b0b957dc
6
+ metadata.gz: f8f8feb0e33f5e3851d564b125c5e5eb764995993efc0b9d474e8558485adcf9990ab2da1f420dd158ad01a83d70859c2f0932ad0c0869ee8cb6fdf63e86dd76
7
+ data.tar.gz: 98d4481b9be0e0629de4243fcc8cf87c07e79f9950b682c44b5ba4dd13c9f226f9de8d9dc7dfdd1a14fafd1071da66930ffc5b2bb7f2a73369c9cb76226f65e7
data/README.md CHANGED
@@ -323,14 +323,16 @@ describe ThingPolicy do
323
323
  end
324
324
  ```
325
325
 
326
- If a non-standard scope is required for filters, it can be overridden. It
327
- defaults to the `all` relation for ActiveRecord models or a simple Array
328
- otherwise.
326
+ If a non-standard scope is required for filters, it can be overridden. It defaults to the `all` relation for ActiveRecord models or a simple Array otherwise.
329
327
 
330
328
  ```ruby
331
329
  scope { resource.container }
332
330
  ```
333
331
 
332
+ The current role can be referenced with `current_role`, or `role` for just the role name as a symbol.
333
+
334
+ When using `context` or `description` in combination with `roles`, we recommend that `roles` be the outermost nesting level. We've found that most of the time it's easier to maintain in the long term.
335
+
334
336
  ## Ensure all policies have full test coverage
335
337
 
336
338
  ```ruby
@@ -130,15 +130,19 @@ module Moat
130
130
  ::RSpec.current_example.metadata.fetch(:role)
131
131
  end
132
132
 
133
+ def current_role
134
+ public_send(role)
135
+ end
136
+
133
137
  def permitted_authorizations(policy_class)
134
- policy_instance = policy_class::Authorization.new(public_send(role), policy_example_resource)
138
+ policy_instance = policy_class::Authorization.new(current_role, policy_example_resource)
135
139
  policy_authorizations.select do |authorization|
136
140
  policy_instance.public_send(authorization)
137
141
  end
138
142
  end
139
143
 
140
144
  def permitted_through_filters(policy_class)
141
- policy_instance = policy_class::Filter.new(public_send(role), policy_example_scope)
145
+ policy_instance = policy_class::Filter.new(current_role, policy_example_scope)
142
146
  policy_filters.select do |filter|
143
147
  policy_instance.public_send(filter).include?(policy_example_resource)
144
148
  end
@@ -1,3 +1,3 @@
1
1
  module Moat
2
- VERSION = "0.4".freeze
2
+ VERSION = "0.5".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moat
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Poll Everywhere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-18 00:00:00.000000000 Z
11
+ date: 2018-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec