Class: CanTango::Permits::Permit
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#role_group_match?, #role_match?
#rules, #rules_1_4, #rules_1_5
#localhost_manager?, #permit_name, #role
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
#ability_rules ⇒ Object
77
78
79
|
# File 'lib/cantango/permits/permit.rb', line 77
def ability_rules
ability.send(:rules)
end
|
#ability_sync! ⇒ Object
81
82
83
84
|
# File 'lib/cantango/permits/permit.rb', line 81
def ability_sync!
ability_rules << (rules - ability_rules)
ability_rules.flatten!
end
|
#any(reg_exp) ⇒ Object
41
42
43
|
# File 'lib/cantango/permits/permit.rb', line 41
def any reg_exp
config.models.by_reg_exp reg_exp
end
|
#category(label) ⇒ Object
36
37
38
|
# File 'lib/cantango/permits/permit.rb', line 36
def category label
config.models.by_category label
end
|
#execute ⇒ Object
31
32
33
34
|
# File 'lib/cantango/permits/permit.rb', line 31
def execute
executor.execute!
ability_sync!
end
|
#licenses(*names) ⇒ Object
107
108
109
110
111
|
# File 'lib/cantango/permits/permit.rb', line 107
def licenses *names
names.to_strings.each do |name|
try_license name
end
end
|
#localhost? ⇒ Boolean
57
58
59
|
# File 'lib/cantango/permits/permit.rb', line 57
def localhost?
config.localhost_list.include? request.host
end
|
#options ⇒ Object
45
46
47
|
# File 'lib/cantango/permits/permit.rb', line 45
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
101
102
103
104
105
|
# File 'lib/cantango/permits/permit.rb', line 101
def permit?
static_rules
permit_rules
dynamic_rules
end
|
#publichost? ⇒ Boolean
61
62
63
|
# File 'lib/cantango/permits/permit.rb', line 61
def publichost?
!localhost?
end
|
#subject ⇒ Object
65
66
67
|
# File 'lib/cantango/permits/permit.rb', line 65
def subject
ability.subject
end
|
#user ⇒ Object
69
70
71
|
# File 'lib/cantango/permits/permit.rb', line 69
def user
ability.user
end
|
#user_account ⇒ Object
73
74
75
|
# File 'lib/cantango/permits/permit.rb', line 73
def user_account
ability.user_account
end
|