Class: CanTango::Configuration::Permits
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#account_hash(name) ⇒ Object
-
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
-
#available_classes ⇒ Object
-
#available_permits ⇒ Object
-
#available_types ⇒ Object
-
#clear_executed! ⇒ Object
-
#default_permits ⇒ 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
#debug
#all, #permits_for, #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
76
77
78
|
# File 'lib/cantango/configuration/permits.rb', line 76
def method_missing method_name, *args
accounts[method_name] ||= PermitRegistry.new
end
|
Instance Attribute Details
#accounts ⇒ Object
Returns the value of attribute accounts.
7
8
9
|
# File 'lib/cantango/configuration/permits.rb', line 7
def accounts
@accounts
end
|
#enabled_types ⇒ Object
Also known as:
enabled
10
11
12
|
# File 'lib/cantango/configuration/permits.rb', line 10
def enabled_types
@enabled_types || available_types
end
|
Instance Method Details
#account_hash(name) ⇒ Object
72
73
74
|
# File 'lib/cantango/configuration/permits.rb', line 72
def account_hash name
accounts[name]
end
|
#allowed(candidate, actions, subjects, *extra_args) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/cantango/configuration/permits.rb', line 87
def allowed candidate, actions, subjects, *
executed_for(candidate).inject([]) do |result, permit|
result << permit.class if permit.can? actions, subjects, *
result
end
end
|
#available_classes ⇒ Object
23
24
25
|
# File 'lib/cantango/configuration/permits.rb', line 23
def available_classes
available_permits.values.compact
end
|
#available_permits ⇒ Object
15
16
17
|
# File 'lib/cantango/configuration/permits.rb', line 15
def available_permits
@available_permits ||= default_permits
end
|
#available_types ⇒ Object
19
20
21
|
# File 'lib/cantango/configuration/permits.rb', line 19
def available_types
available_permits.keys
end
|
#clear_executed! ⇒ Object
113
114
115
|
# File 'lib/cantango/configuration/permits.rb', line 113
def clear_executed!
@executed = nil
end
|
#default_permits ⇒ Object
#denied(candidate, actions, subjects, *extra_args) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/cantango/configuration/permits.rb', line 94
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
45
46
47
48
|
# File 'lib/cantango/configuration/permits.rb', line 45
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
36
37
38
|
# File 'lib/cantango/configuration/permits.rb', line 36
def disable_types *types
@enabled_types = available_types - types.flatten
end
|
#disabled ⇒ Object
55
56
57
|
# File 'lib/cantango/configuration/permits.rb', line 55
def disabled
@disabled ||= {}
end
|
#disabled_for(type) ⇒ Object
59
60
61
|
# File 'lib/cantango/configuration/permits.rb', line 59
def disabled_for type
disabled[type]
end
|
#enable_all! ⇒ Object
63
64
65
66
|
# File 'lib/cantango/configuration/permits.rb', line 63
def enable_all!
@disabled = {}
enable_all_types!
end
|
#enable_all_for(type) ⇒ Object
50
51
52
53
|
# File 'lib/cantango/configuration/permits.rb', line 50
def enable_all_for type
@disabled ||= {}
@disabled[type.to_sym] = nil
end
|
#enable_all_types! ⇒ Object
41
42
43
|
# File 'lib/cantango/configuration/permits.rb', line 41
def enable_all_types!
@enabled_types = available_types
end
|
#executed ⇒ Object
109
110
111
|
# File 'lib/cantango/configuration/permits.rb', line 109
def executed
@executed ||= {}
end
|
#executed_for(ability) ⇒ Object
105
106
107
|
# File 'lib/cantango/configuration/permits.rb', line 105
def executed_for ability
executed[hash_key_for(ability)] ||= []
end
|
#register_permit_class(permit_name, permit_clazz, permit_type, account_name) ⇒ Object
80
81
82
83
84
85
|
# File 'lib/cantango/configuration/permits.rb', line 80
def register_permit_class(permit_name, permit_clazz, permit_type, account_name)
registry = account_name ? get_permit(account_name.to_sym) : self
debug "Registering #{permit_type} permit: #{permit_name} of class #{permit_clazz}"
registry.permits_for(permit_type)[permit_name] = permit_clazz
debug registry.permits_for(permit_type).inspect
end
|
#was_executed(permit, ability) ⇒ Object
101
102
103
|
# File 'lib/cantango/configuration/permits.rb', line 101
def was_executed permit, ability
executed_for(ability) << permit
end
|