role_authorization 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,8 +19,30 @@ module RoleAuthorization
19
19
  output.join("\n")
20
20
  end
21
21
 
22
+ def with_options(options, &block)
23
+ unless block.nil?
24
+ @with_options = options
25
+ instance_eval(&block)
26
+ @with_options = nil
27
+ end
28
+ end
29
+
22
30
  def add_to_rules(rule_name, *options, &block)
23
- rule = RoleAuthorization::Rules::Rule.new(*options, &block)
31
+ extracted_options, extracted_role = if options.is_a?(Hash)
32
+ [options, nil]
33
+ elsif options.last.is_a?(Hash)
34
+ [options.pop, options.first]
35
+ else
36
+ [{}, options.first]
37
+ end
38
+
39
+ merged_options = if @with_options.nil?
40
+ extracted_options
41
+ else
42
+ @with_options.merge(extracted_options)
43
+ end
44
+
45
+ rule = RoleAuthorization::Rules::Rule.new(extracted_role, merged_options, &block)
24
46
 
25
47
  actions = ([rule.options[:only] || [:all]]).flatten.map(&:to_sym)
26
48
 
@@ -7,15 +7,10 @@ module RoleAuthorization
7
7
  # for calls to authorized?
8
8
  attr_accessor :controller_instance, :controller, :action, :id
9
9
 
10
- def initialize(*options, &block)
10
+ def initialize(role, options, &block)
11
11
  @returning = block
12
- @options, @role = if options.is_a?(Hash)
13
- [options, nil]
14
- elsif options.last.is_a?(Hash)
15
- [options.pop, options.first]
16
- else
17
- [{}, options.first]
18
- end
12
+ @role = role
13
+ @options = options
19
14
 
20
15
  self
21
16
  end
@@ -1,3 +1,3 @@
1
1
  module RoleAuthorization
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: role_authorization
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - John 'asceth' Long