regulator 0.1.0 → 0.1.1

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: b3db854196ef6578280ed448fe9fdf888c91742a
4
- data.tar.gz: 88a9856bac4ae6d00216011a05e7ed543fafc17e
3
+ metadata.gz: debaf2d2834f1f40dfb69f5d16f20a8b0f887d7e
4
+ data.tar.gz: a894788600e922d6fca85ae7897a08f76d7fdbcd
5
5
  SHA512:
6
- metadata.gz: 2b588448c03f5b60d767b6b0b790968a6cccad90be5274a687dc84a6f79de96ecaafce62338655768c8d97ebbceece0abf6d2dd94de5274479d71121527ddd3c
7
- data.tar.gz: 96770fb5bb9a7639eea0bfe695a3c98d109e2f904fc51fde933f9d36f535c5d024a3761a518ffed57715e9d73e51aa3b34718b0507bc799d2bcac99ac8244cf4
6
+ metadata.gz: 10a08ae8dc44b46b4a3bde10f5802ea32543b3f9ae55668ceae101439dc594dd0ef11f25a548706a44e07e8928527198a7a5369f6f4742c4db80dde8e00c1178
7
+ data.tar.gz: fe9af60ae01fd42e0ce9ad509c4feff5c696d244bf57318603844f3908a35955f7760b7449a48fb17ce552fdc21715869d8bd0d77eca22461f8bac302de405b0
data/.travis.yml CHANGED
@@ -1,11 +1,10 @@
1
1
  language: ruby
2
2
  before_install: gem install bundler -v 1.10.5
3
3
  rvm:
4
+ - 2.2.0
4
5
  - 2.0.0
5
6
  - 2.1.5
6
- - 2.2.0
7
7
  - jruby-19mode
8
- - rbx-2
9
8
  env:
10
9
  - RSPEC_VERSION="<2.99"
11
10
  - RSPEC_VERSION="~>3.0
data/CHANGELOG.md CHANGED
@@ -1,6 +1,13 @@
1
1
  # Regulator
2
2
 
3
+ ## 0.1.1 (2015-07-23)
4
+ - Regulator.authorize support for controller namespacing
5
+ - Regulator can accept a controller instance or an explicity modules name
6
+ - Regulator.policy!(user,resource, my_controller_instance)
7
+ - Regulator.policy!(user,resource, Api::V2)
8
+
3
9
  ## 0.1.0 (2015-07-23)
4
10
  - initial release
5
11
  - pundit compatible
6
12
  - controller based policy namespacing
13
+ ActiveAdmin.application.regulator_policy_namespace
data/README.md CHANGED
@@ -16,7 +16,9 @@ Why not contribute to pundit? [It's](https://github.com/elabs/pundit/issues/12)
16
16
  ## TODOs
17
17
  * [ ] generators
18
18
  * [ ] activeadmin-regulator-adapter gem or generator
19
- * [ ] documentation (Usage section below, mock pundits)
19
+ * [ ] documentation
20
+ * [ ] Usage section below, mock pundit's
21
+ * [ ] yard doc
20
22
  * [ ] Lotus examples
21
23
  * [ ] Grape examples
22
24
  * [ ] ROM examples
@@ -2,10 +2,17 @@ module Regulator
2
2
  class PolicyFinder
3
3
  attr_reader :object
4
4
  attr_reader :controller
5
+ attr_reader :namespace
5
6
 
6
- def initialize(object, controller = nil)
7
+ def initialize(object, controller_or_namespace = nil)
7
8
  @object = object
8
- @controller = controller
9
+
10
+ if controller_or_namespace.is_a?(Module)
11
+ @namespace = controller_or_namespace
12
+ elsif controller_or_namespace
13
+ @controller = controller_or_namespace
14
+ @namespace = @controller.policy_namespace
15
+ end
9
16
  end
10
17
 
11
18
  def scope
@@ -64,11 +71,7 @@ module Regulator
64
71
 
65
72
  policy_name = "#{klass}#{SUFFIX}"
66
73
 
67
- if controller
68
- "#{controller.policy_namespace}::#{policy_name}"
69
- else
70
- policy_name
71
- end
74
+ namespace ? "#{namespace}::#{policy_name}" : policy_name
72
75
  end
73
76
  end
74
77
 
@@ -1,3 +1,3 @@
1
1
  module Regulator
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/regulator.rb CHANGED
@@ -20,6 +20,7 @@ module Regulator
20
20
  @query = options[:query]
21
21
  @record = options[:record]
22
22
  @policy = options[:policy]
23
+ @controller_or_namespace = options[:controller_or_namespace]
23
24
 
24
25
  message = options.fetch(:message) { "not allowed to #{query} this #{record.inspect}" }
25
26
  end
@@ -34,32 +35,32 @@ module Regulator
34
35
  extend ActiveSupport::Concern
35
36
 
36
37
  class << self
37
- def authorize(user, record, query)
38
- policy = policy!(user, record)
38
+ def authorize(user, record, query, controller_or_namespace = nil)
39
+ policy = policy!(user, record, controller_or_namespace)
39
40
 
40
41
  unless policy.public_send(query)
41
- raise NotAuthorizedError.new(query: query, record: record, policy: policy)
42
+ raise NotAuthorizedError.new(query: query, record: record, policy: policy, controller_or_namespace: controller_or_namespace)
42
43
  end
43
44
 
44
45
  true
45
46
  end
46
47
 
47
- def policy_scope(user, scope, controller = nil)
48
- policy_scope = PolicyFinder.new(scope,controller).scope
48
+ def policy_scope(user, scope, controller_or_namespace = nil)
49
+ policy_scope = PolicyFinder.new(scope,controller_or_namespace).scope
49
50
  policy_scope.new(user, scope).resolve if policy_scope
50
51
  end
51
52
 
52
- def policy_scope!(user, scope, controller = nil)
53
- PolicyFinder.new(scope,controller).scope!.new(user, scope).resolve
53
+ def policy_scope!(user, scope, controller_or_namespace = nil)
54
+ PolicyFinder.new(scope,controller_or_namespace).scope!.new(user, scope).resolve
54
55
  end
55
56
 
56
- def policy(user, record, controller = nil)
57
- policy = PolicyFinder.new(record,controller).policy
57
+ def policy(user, record, controller_or_namespace = nil)
58
+ policy = PolicyFinder.new(record,controller_or_namespace).policy
58
59
  policy.new(user, record) if policy
59
60
  end
60
61
 
61
- def policy!(user, record, controller = nil)
62
- PolicyFinder.new(record,controller).policy!.new(user, record)
62
+ def policy!(user, record, controller_or_namespace = nil)
63
+ PolicyFinder.new(record,controller_or_namespace).policy!.new(user, record)
63
64
  end
64
65
  end
65
66
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory O'Daniel