authority 2.6.0 → 2.7.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
  SHA1:
3
- metadata.gz: 0486fc9d457c9b5624e3f424edfae6f6cf95d97f
4
- data.tar.gz: 1d0e25a2ae7c561ab1552f5eb4a0bbf4b0f530e6
3
+ metadata.gz: b3bb0dcfadb29c3e61cf717eca48de2be68259b9
4
+ data.tar.gz: 5d8299cf62e1c9adabcc1c86bde6706592af9433
5
5
  SHA512:
6
- metadata.gz: a6d5fe92ed2f6a0291e8d8837ac4d846effede53fca5303369294e3e6aa20d167539cf4d9bfb27a6c5e0b8e44058e3fee3d5bd26ac71b87741e7f1797948deb1
7
- data.tar.gz: 897deb92bd285807303b6b67511c46dbca0e4ebc3937a0b980d9b7283f8c478402bf803584048e8b80dafa9e6060123d98bb295a605cded512991680a04350b3
6
+ metadata.gz: 9543396964cdc739ba4b41929cf5cde18de52e65c2c392f132c9b2f880c27469ceeeb6ccc6c622c4724d6458023baa981cb668440a6d3c3cab3dc7627aeadff8
7
+ data.tar.gz: 9a73e9a4dee9d62b0a5a2ec4597ad3ec15293fec5eeef1379d5e2830513960b9af7729da0f8a0f46e0471662f179e1ca6b27799b753ebf811e9202753256fad2
data/CHANGELOG.markdown CHANGED
@@ -2,10 +2,14 @@
2
2
 
3
3
  Authority does its best to use [semantic versioning](http://semver.org).
4
4
 
5
+ ## 2.7.0
6
+
7
+ Allows setting authorizer by class (`authorizer = FooAuthorizer`) as well as by name (`authorizer_name = 'FooAuthorizer'`), thanks to [mguymon](https://github.com/mguymon)
8
+
5
9
  ## v2.6.0
6
10
 
7
- - Now dependent on ActiveSupport, not all of Rails, as a step toward easier use with other frameworks
8
- - Testing with Rails 4.0
11
+ - Now dependent on ActiveSupport, not all of Rails, as a step toward easier use with other frameworks. Thanks to [christhekeele](https://github.com/christhekeele)
12
+ - Testing with Rails 4.0, thanks to [sanemat](https://github.com/sanemat)
9
13
  - Clearer backtraces in certain situations
10
14
 
11
15
  ## v2.5.0
@@ -44,7 +48,7 @@ Controller method `authorize_actions_for` can now be given a method name to dyna
44
48
 
45
49
  ## v2.2.0
46
50
 
47
- Allow passing options hash to `authorize_action_for`, like `authorize_action_for(@llama, :sporting => @hat_style)`.
51
+ Allow passing options hash to `authorize_action_for`, like `authorize_action_for(@llama, :sporting => @hat_style)`. Thanks to [MP211](https://github.com/MP211).
48
52
 
49
53
  ## v2.1.0
50
54
 
@@ -61,7 +65,7 @@ Documentation and test cleanup.
61
65
 
62
66
  ## v1.1.0
63
67
 
64
- - Added `Authority::Authorizer.default` class method which is called before the `default_strategy` proc and delegates to that proc. This can be overridden per authorizer.
68
+ - Added `Authority::Authorizer.default` class method which is called before the `default_strategy` proc and delegates to that proc. This can be overridden per authorizer. Thanks to [kevmoo](https://github.com/kevmoo)
65
69
 
66
70
  ## v1.0.0
67
71
 
data/README.markdown CHANGED
@@ -71,7 +71,12 @@ All you have to do is define the methods you need on your authorizers. You have
71
71
 
72
72
  Authority encapsulates all authorization logic in `Authorizer` classes. Want to do something with a model? **Ask its authorizer**.
73
73
 
74
- You can specify a model's authorizer using the class method `authorizer_name=`. If you don't specify it, it will:
74
+ You can specify a model's authorizer one of two ways:
75
+
76
+ - specify the class itself: `authorizer = SomeAuthorizer`
77
+ - specify the class's name: `authorizer_name = 'SomeAuthorizer'` (useful if the constant isn't yet loaded)
78
+
79
+ If you don't specify an authorizer, the model will:
75
80
 
76
81
  - Look for an authorizer with its name. Eg, `Comment` will look for `CommentAuthorizer`.
77
82
  - If that's not found, it will use `ApplicationAuthorizer`.
@@ -17,12 +17,13 @@ module Authority
17
17
  # - Look for an authorizer named like the model inside the model's namespace.
18
18
  # - If there is none, use 'ApplicationAuthorizer'
19
19
  self.authorizer_name = begin
20
- "#{base.name}Authorizer".constantize.name
21
- rescue NameError => e
22
- "ApplicationAuthorizer"
23
- end
20
+ "#{base.name}Authorizer".constantize.name
21
+ rescue NameError => e
22
+ "ApplicationAuthorizer"
23
+ end
24
24
  end
25
25
 
26
+
26
27
  def authorizer
27
28
  self.class.authorizer.new(self) # instantiate on every check, in case model has changed
28
29
  end
@@ -40,16 +41,21 @@ module Authority
40
41
  module ClassMethods
41
42
  include Definitions
42
43
 
44
+ def authorizer=(authorizer_class)
45
+ @authorizer = authorizer_class
46
+ self.authorizer_name = @authorizer.name
47
+ end
48
+
43
49
  # @return [Class] of the designated authorizer
44
50
  def authorizer
45
51
  @authorizer ||= authorizer_name.constantize # Get an actual reference to the authorizer class
46
52
  rescue NameError
47
53
  raise Authority::NoAuthorizerError.new(
48
- "#{authorizer_name} is set as the authorizer for #{self}, but the constant is missing"
49
- )
54
+ "#{authorizer_name} is set as the authorizer for #{self}, but the constant is missing"
55
+ )
50
56
  end
51
57
 
52
58
  end
53
59
 
54
60
  end
55
- end
61
+ end
@@ -1,3 +1,3 @@
1
1
  module Authority
2
- VERSION = "2.6.0"
2
+ VERSION = "2.7.0"
3
3
  end
@@ -46,6 +46,27 @@ describe Authority::Abilities do
46
46
 
47
47
  end
48
48
 
49
+ describe "authorizer=" do
50
+
51
+ let(:test_class) { Class.new {include Authority::Abilities} }
52
+
53
+ it "has a class attribute setter" do
54
+ expect(test_class).to respond_to(:authorizer=)
55
+ end
56
+
57
+ it "sets authorizer" do
58
+ test_class.authorizer = ExampleResourceAuthorizer
59
+ expect(test_class.authorizer).to eq(ExampleResourceAuthorizer)
60
+ end
61
+
62
+ it "also sets authorizer_name" do
63
+ test_class.authorizer_name = 'FooAuthorizer'
64
+ test_class.authorizer = ExampleResourceAuthorizer
65
+ expect(test_class.authorizer_name).to eq("ExampleResourceAuthorizer")
66
+ end
67
+
68
+ end
69
+
49
70
  describe "authorizer" do
50
71
 
51
72
  it "constantizes the authorizer name as the authorizer" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: authority
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.0
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Long
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-24 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport