Class: Accessly::Policy::Base
- Inherits:
-
Object
- Object
- Accessly::Policy::Base
show all
- Defined in:
- lib/accessly/policy/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(actor) ⇒ Base
Returns a new instance of Base.
7
8
9
|
# File 'lib/accessly/policy/base.rb', line 7
def initialize(actor)
@actor = actor
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Determines whether the caller is trying to call an action method in the format ‘action_name?`. If so, this calls that method with the given arguments.
116
117
118
119
120
121
122
123
|
# File 'lib/accessly/policy/base.rb', line 116
def method_missing(method_name, *args)
action_method_name = _resolve_action_method_name(method_name)
if action_method_name.nil?
super
else
send(action_method_name, *args)
end
end
|
Instance Attribute Details
#actor ⇒ Object
Returns the value of attribute actor.
5
6
7
|
# File 'lib/accessly/policy/base.rb', line 5
def actor
@actor
end
|
Class Method Details
.actions(actions) ⇒ Object
11
12
13
14
15
16
|
# File 'lib/accessly/policy/base.rb', line 11
def self.actions(actions)
_actions.merge!(actions)
actions.each do |action, action_id|
_define_action_methods(action, action_id)
end
end
|
.actions_on_objects(actions_on_objects) ⇒ Object
18
19
20
21
22
23
|
# File 'lib/accessly/policy/base.rb', line 18
def self.actions_on_objects(actions_on_objects)
_actions_on_objects.merge!(actions_on_objects)
actions_on_objects.each do |action, action_id|
_define_action_methods(action, action_id)
end
end
|
.model_scope ⇒ Object
33
34
35
|
# File 'lib/accessly/policy/base.rb', line 33
def self.model_scope
raise ArgumentError.new("#model_scope is not defined on #{self.name}.")
end
|
.namespace ⇒ Object
25
26
27
|
# File 'lib/accessly/policy/base.rb', line 25
def self.namespace
String(self)
end
|
Instance Method Details
#accessly_query ⇒ Object
81
82
83
84
85
86
87
|
# File 'lib/accessly/policy/base.rb', line 81
def accessly_query
@_accessly_query ||= begin
query = Accessly::Query.new(actors)
query.on_segment(segment_id) unless segment_id.nil?
query
end
end
|
#actors ⇒ Object
Specifies all the actors used in permission lookups. Override this method in child policy classes to specify other actors that the actor given in the initializer may inherit permissions from.
45
46
47
|
# File 'lib/accessly/policy/base.rb', line 45
def actors
actor
end
|
#can?(action, object = nil) ⇒ Boolean
57
58
59
60
61
62
63
|
# File 'lib/accessly/policy/base.rb', line 57
def can?(action, object = nil)
if object.nil?
send("#{action}?")
else
send("#{action}?", object)
end
end
|
#grant!(action, object = nil) ⇒ Object
69
70
71
72
73
|
# File 'lib/accessly/policy/base.rb', line 69
def grant!(action, object = nil)
object_id = _get_object_id(object)
action_id = _get_action_id(action, object_id)
grant_object.grant!(action_id, namespace, object_id)
end
|
#grant_object ⇒ Object
89
90
91
92
93
94
|
# File 'lib/accessly/policy/base.rb', line 89
def grant_object
grant_object = Accessly::Permission::Grant.new(actor)
grant_object.on_segment(segment_id) unless segment_id.nil?
grant_object
end
|
#list(action) ⇒ Object
65
66
67
|
# File 'lib/accessly/policy/base.rb', line 65
def list(action)
send(action)
end
|
#model_scope ⇒ Object
37
38
39
|
# File 'lib/accessly/policy/base.rb', line 37
def model_scope
self.class.model_scope
end
|
#namespace ⇒ Object
29
30
31
|
# File 'lib/accessly/policy/base.rb', line 29
def namespace
self.class.namespace
end
|
#revoke!(action, object = nil) ⇒ Object
75
76
77
78
79
|
# File 'lib/accessly/policy/base.rb', line 75
def revoke!(action, object = nil)
object_id = _get_object_id(object)
action_id = _get_action_id(action, object_id)
revoke_object.revoke!(action_id, namespace, object_id)
end
|
#revoke_object ⇒ Object
96
97
98
99
100
101
|
# File 'lib/accessly/policy/base.rb', line 96
def revoke_object
revoke_object = Accessly::Permission::Revoke.new(actor)
revoke_object.on_segment(segment_id) unless segment_id.nil?
revoke_object
end
|
#segment_id ⇒ Object
53
54
55
|
# File 'lib/accessly/policy/base.rb', line 53
def segment_id
nil
end
|
#unrestricted? ⇒ Boolean
49
50
51
|
# File 'lib/accessly/policy/base.rb', line 49
def unrestricted?
false
end
|