Class: CanTango::Permits::Permit
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#role_group_match?, #role_match?
#rules_1_4, #rules_1_5
#localhost_manager?, #permit_name, #role
Methods included from Rules
#can, #cannot
#rule_class
Methods included from Rules::Dsl
included, #scope
Constructor Details
#initialize(ability) ⇒ Permit
16
17
18
|
# File 'lib/cantango/permits/permit.rb', line 16
def initialize ability
@ability = ability
end
|
Instance Attribute Details
#ability ⇒ Object
Returns the value of attribute ability.
8
9
10
|
# File 'lib/cantango/permits/permit.rb', line 8
def ability
@ability
end
|
Class Method Details
.account_name(clazz) ⇒ Object
25
26
27
28
|
# File 'lib/cantango/permits/permit.rb', line 25
def self.account_name clazz
return nil if clazz.name == clazz.name.demodulize
clazz.name.gsub(/::.*/,'').gsub(/(.*)Permits/, '\1').underscore.to_sym
end
|
.first_name(clazz) ⇒ Object
20
21
22
|
# File 'lib/cantango/permits/permit.rb', line 20
def self.first_name clazz
clazz.to_s.gsub(/^([A-Za-z]+).*/, '\1').underscore.to_sym end
|
Instance Method Details
#any(reg_exp) ⇒ Object
39
40
41
|
# File 'lib/cantango/permits/permit.rb', line 39
def any reg_exp
config.models.by_reg_exp reg_exp
end
|
#category(label) ⇒ Object
35
36
37
|
# File 'lib/cantango/permits/permit.rb', line 35
def category label
config.models.by_category label
end
|
#execute ⇒ Object
31
32
33
|
# File 'lib/cantango/permits/permit.rb', line 31
def execute
executor.execute!
end
|
#licenses(*names) ⇒ Object
100
101
102
103
104
|
# File 'lib/cantango/permits/permit.rb', line 100
def licenses *names
names.to_strings.each do |name|
try_license name
end
end
|
#localhost? ⇒ Boolean
55
56
57
|
# File 'lib/cantango/permits/permit.rb', line 55
def localhost?
config.localhost_list.include? request.host
end
|
#options ⇒ Object
43
44
45
|
# File 'lib/cantango/permits/permit.rb', line 43
def options
ability.options
end
|
#permit? ⇒ Boolean
In a specific Role based Permit you can use
def permit? user, options = {}
return if !super(user, :in_role)
... permission logic follows
This will call the Permit::Base#permit? instance method (the method below) It will only return true if the user matches the role of the Permit class and the options passed in is set to :in_role
If these confitions are not met, it will return false and thus the outer permit will not run the permission logic to follow
Normally super for #permit? should not be called except for this case, or if subclassing another Permit than Permit::Base
94
95
96
97
98
|
# File 'lib/cantango/permits/permit.rb', line 94
def permit?
static_rules
permit_rules
dynamic_rules
end
|
#publichost? ⇒ Boolean
59
60
61
|
# File 'lib/cantango/permits/permit.rb', line 59
def publichost?
!localhost?
end
|
#rules ⇒ Object
75
76
77
|
# File 'lib/cantango/permits/permit.rb', line 75
def rules
ability.send :rules
end
|
#subject ⇒ Object
63
64
65
|
# File 'lib/cantango/permits/permit.rb', line 63
def subject
ability.subject
end
|
#user ⇒ Object
67
68
69
|
# File 'lib/cantango/permits/permit.rb', line 67
def user
ability.user
end
|
#user_account ⇒ Object
71
72
73
|
# File 'lib/cantango/permits/permit.rb', line 71
def user_account
ability.user_account
end
|