can_opener 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +2 -2
- data/lib/can_opener/ability.rb +10 -10
- data/lib/can_opener/version.rb +1 -1
- data/spec/can_opener_spec.rb +1 -1
- metadata +4 -4
data/README.markdown
CHANGED
@@ -55,11 +55,11 @@ Remember that CanCan processes abilities in a top down fashion, so add your gene
|
|
55
55
|
|
56
56
|
### But I want to check the IP Address, Project, etc, in the ability!
|
57
57
|
|
58
|
-
Inherit `CanOpener::Ability` , setup your accessors, use the `
|
58
|
+
Inherit `CanOpener::Ability` , setup your accessors, use the `additional_ability_arguments` class method. Consider the following contrived example:
|
59
59
|
|
60
60
|
class TakesIpAddress < CanOpener::Ability
|
61
61
|
attr_reader :ip_address
|
62
|
-
|
62
|
+
additional_ability_arguments :ip_address
|
63
63
|
end
|
64
64
|
|
65
65
|
class SuperAdmin < TakesIpAddress
|
data/lib/can_opener/ability.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module CanOpener
|
2
2
|
class Ability
|
3
3
|
extend Forwardable
|
4
|
-
|
4
|
+
|
5
5
|
def_delegators :@base, *CanCan::Ability.public_instance_methods
|
6
6
|
|
7
7
|
attr_accessor :user
|
8
8
|
protected :user=
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(base, *args)
|
11
11
|
@base = base
|
12
12
|
setup_vars(*args)
|
13
13
|
abilities
|
14
14
|
end
|
15
|
-
|
16
|
-
def self.
|
17
|
-
@@
|
15
|
+
|
16
|
+
def self.additional_ability_arguments(*args)
|
17
|
+
@@initializer_arguments = [:user]
|
18
18
|
args.each_with_index do |arg, idx|
|
19
19
|
raise ArgumentError, "user cannot be an additional argument as it is required as the first arg" if arg.to_sym == :user
|
20
|
-
@@
|
20
|
+
@@initializer_arguments << arg.to_sym
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
protected
|
25
|
-
|
25
|
+
|
26
26
|
def setup_vars(*args)
|
27
|
-
if @@
|
28
|
-
@@
|
27
|
+
if @@initializer_arguments && @@initializer_arguments.length > 0
|
28
|
+
@@initializer_arguments.each_with_index do |arg, idx|
|
29
29
|
self.class.send(:attr_accessor, arg)
|
30
30
|
self.send("#{arg}=", args[idx])
|
31
31
|
end
|
data/lib/can_opener/version.rb
CHANGED
data/spec/can_opener_spec.rb
CHANGED
@@ -142,7 +142,7 @@ describe CanOpener do
|
|
142
142
|
describe "passing objects to the ability" do
|
143
143
|
class TakesIpAddress < CanOpener::Ability
|
144
144
|
attr_reader :ip_address
|
145
|
-
|
145
|
+
additional_ability_arguments :ip_address
|
146
146
|
end
|
147
147
|
|
148
148
|
class SuperAdmin < TakesIpAddress
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_opener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brendon Murphy
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-01-
|
18
|
+
date: 2011-01-21 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|