Class: CanTango::Configuration::Permits
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#account_hash(name) ⇒ Object
-
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
-
#clear_executed! ⇒ Object
-
#denied(candidate, actions, subjects, *extra_args) ⇒ Object
-
#executed ⇒ Object
-
#executed_for(ability) ⇒ Object
-
#method_missing(method_name, *args) ⇒ Object
-
#register_permit_class(permit_name, permit_clazz, permit_type, account_name) ⇒ Object
-
#was_executed(permit, ability) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
16
17
18
|
# File 'lib/cantango/configuration/permits.rb', line 16
def method_missing method_name, *args
accounts[method_name] ||= PermitRegistry.new
end
|
Instance Attribute Details
#accounts ⇒ Object
Returns the value of attribute accounts.
6
7
8
|
# File 'lib/cantango/configuration/permits.rb', line 6
def accounts
@accounts
end
|
Instance Method Details
#account_hash(name) ⇒ Object
12
13
14
|
# File 'lib/cantango/configuration/permits.rb', line 12
def account_hash name
accounts[name]
end
|
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
25
26
27
28
29
30
|
# File 'lib/cantango/configuration/permits.rb', line 25
def allowed candidate, actions, subjects, *
executed_for(candidate).inject([]) do |result, permit|
result << permit.class if permit.can? actions, subjects, *
result
end
end
|
#clear_executed! ⇒ Object
51
52
53
|
# File 'lib/cantango/configuration/permits.rb', line 51
def clear_executed!
@executed = nil
end
|
#denied(candidate, actions, subjects, *extra_args) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/cantango/configuration/permits.rb', line 32
def denied candidate, actions, subjects, *
executed_for(candidate).inject([]) do |result, permit|
result << permit.class if permit.cannot? actions, subjects, *
result
end
end
|
#executed ⇒ Object
47
48
49
|
# File 'lib/cantango/configuration/permits.rb', line 47
def executed
@executed ||= {}
end
|
#executed_for(ability) ⇒ Object
43
44
45
|
# File 'lib/cantango/configuration/permits.rb', line 43
def executed_for ability
executed[hash_key_for(ability)] ||= []
end
|
#register_permit_class(permit_name, permit_clazz, permit_type, account_name) ⇒ Object
20
21
22
23
|
# File 'lib/cantango/configuration/permits.rb', line 20
def register_permit_class(permit_name, permit_clazz, permit_type, account_name)
registry = account_name ? self.send(account_name.to_sym) : self
registry.send(permit_type)[permit_name] = permit_clazz
end
|
#was_executed(permit, ability) ⇒ Object
39
40
41
|
# File 'lib/cantango/configuration/permits.rb', line 39
def was_executed permit, ability
executed_for(ability) << permit
end
|