Class: CanTango::Configuration::Permits
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#account_hash(name) ⇒ Object
-
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
-
#available_types ⇒ Object
-
#clear_executed! ⇒ Object
-
#denied(candidate, actions, subjects, *extra_args) ⇒ Object
-
#disable_for(type, *names) ⇒ Object
-
#disable_types(*types) ⇒ Object
(also: #disable)
-
#disabled ⇒ Object
-
#disabled_for(type) ⇒ Object
-
#enable_all! ⇒ Object
-
#enable_all_for(type) ⇒ Object
-
#enable_all_types! ⇒ 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
#all, #registered_by, #registered_for, #show_all
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
58
59
60
|
# File 'lib/cantango/configuration/permits.rb', line 58
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
|
#enabled_types ⇒ Object
Also known as:
enabled
9
10
11
|
# File 'lib/cantango/configuration/permits.rb', line 9
def enabled_types
@enabled_types || available_types
end
|
Instance Method Details
#account_hash(name) ⇒ Object
54
55
56
|
# File 'lib/cantango/configuration/permits.rb', line 54
def account_hash name
accounts[name]
end
|
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
69
70
71
72
73
74
|
# File 'lib/cantango/configuration/permits.rb', line 69
def allowed candidate, actions, subjects, *
executed_for(candidate).inject([]) do |result, permit|
result << permit.class if permit.can? actions, subjects, *
result
end
end
|
#available_types ⇒ Object
14
15
16
|
# File 'lib/cantango/configuration/permits.rb', line 14
def available_types
[:user, :account, :role, :role_group, :special]
end
|
#clear_executed! ⇒ Object
95
96
97
|
# File 'lib/cantango/configuration/permits.rb', line 95
def clear_executed!
@executed = nil
end
|
#denied(candidate, actions, subjects, *extra_args) ⇒ Object
76
77
78
79
80
81
|
# File 'lib/cantango/configuration/permits.rb', line 76
def denied candidate, actions, subjects, *
executed_for(candidate).inject([]) do |result, permit|
result << permit.class if permit.cannot? actions, subjects, *
result
end
end
|
#disable_for(type, *names) ⇒ Object
27
28
29
30
|
# File 'lib/cantango/configuration/permits.rb', line 27
def disable_for type, *names
@disabled ||= {}
@disabled[type.to_sym] = names.flatten.select_labels.map{|n| n.to_s.underscore}
end
|
#disable_types(*types) ⇒ Object
Also known as:
disable
18
19
20
|
# File 'lib/cantango/configuration/permits.rb', line 18
def disable_types *types
@enabled_types = available_types - types.flatten
end
|
#disabled ⇒ Object
37
38
39
|
# File 'lib/cantango/configuration/permits.rb', line 37
def disabled
@disabled ||= {}
end
|
#disabled_for(type) ⇒ Object
41
42
43
|
# File 'lib/cantango/configuration/permits.rb', line 41
def disabled_for type
disabled[type]
end
|
#enable_all! ⇒ Object
45
46
47
48
|
# File 'lib/cantango/configuration/permits.rb', line 45
def enable_all!
@disabled = {}
enable_all_types!
end
|
#enable_all_for(type) ⇒ Object
32
33
34
35
|
# File 'lib/cantango/configuration/permits.rb', line 32
def enable_all_for type
@disabled ||= {}
@disabled[type.to_sym] = nil
end
|
#enable_all_types! ⇒ Object
23
24
25
|
# File 'lib/cantango/configuration/permits.rb', line 23
def enable_all_types!
@enabled_types = available_types
end
|
#executed ⇒ Object
91
92
93
|
# File 'lib/cantango/configuration/permits.rb', line 91
def executed
@executed ||= {}
end
|
#executed_for(ability) ⇒ Object
87
88
89
|
# File 'lib/cantango/configuration/permits.rb', line 87
def executed_for ability
executed[hash_key_for(ability)] ||= []
end
|
#register_permit_class(permit_name, permit_clazz, permit_type, account_name) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/cantango/configuration/permits.rb', line 62
def register_permit_class(permit_name, permit_clazz, permit_type, account_name)
registry = account_name ? self.send(account_name.to_sym) : self
puts "Registering #{permit_type} permit: #{permit_name} of class #{permit_clazz}" if CanTango.debug?
registry.send(permit_type)[permit_name] = permit_clazz
puts registry.send(permit_type).inspect if CanTango.debug?
end
|
#was_executed(permit, ability) ⇒ Object
83
84
85
|
# File 'lib/cantango/configuration/permits.rb', line 83
def was_executed permit, ability
executed_for(ability) << permit
end
|