Class: Ddr::Auth::Roles::Role
Abstract
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- Ddr::Auth::Roles::Role
show all
- Includes:
- RDF::Isomorphic
- Defined in:
- lib/ddr/auth/roles/role.rb
Overview
An abstract class representing the assignment of a role to an agent within a scope.
Constant Summary
collapse
- AGENT_TYPES =
[:person, :group, :agent]
Class Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Class Attribute Details
.permissions ⇒ Object
Returns the value of attribute permissions.
25
26
27
|
# File 'lib/ddr/auth/roles/role.rb', line 25
def permissions
@permissions
end
|
Class Method Details
Builds a new role object from the hash arguments
34
35
36
37
38
39
40
41
42
|
# File 'lib/ddr/auth/roles/role.rb', line 34
def build(args={})
new.tap do |role|
agent_key = AGENT_TYPES.detect { |k| args.key?(k) }
agent_class = Ddr::Auth.get_agent_class(agent_key)
role.agent = agent_class.build(args[agent_key])
role.scope = args.fetch(:scope, Scopes::DEFAULT)
end
end
|
.has_permission(*permissions) ⇒ Object
27
28
29
|
# File 'lib/ddr/auth/roles/role.rb', line 27
def has_permission(*permissions)
self.permissions += permissions.map { |p| Ddr::Auth::Permission.get(p) }
end
|
.inherited(subclass) ⇒ Object
52
53
54
|
# File 'lib/ddr/auth/roles/role.rb', line 52
def inherited(subclass)
subclass.permissions = []
end
|
.role_type ⇒ Symbol
Return the role “type” (not RDF type) – i.e., a symbol for the role class
This should be the inverse operation of Ddr::Auth::Roles.get_role_class(type)
48
49
50
|
# File 'lib/ddr/auth/roles/role.rb', line 48
def role_type
@role_type ||= self.name.split("::").last.underscore.to_sym
end
|
Instance Method Details
#==(other) ⇒ Boolean
Roles are considered equivalent if the RDF graphs are isomorphic – i.e., if the RDF type, Agent name, scope are all equal.
61
62
63
|
# File 'lib/ddr/auth/roles/role.rb', line 61
def ==(other)
isomorphic_with? other
end
|
#agent_name ⇒ String?
Return the agent name associated with the role
80
81
82
83
84
|
# File 'lib/ddr/auth/roles/role.rb', line 80
def agent_name
if ag = get_agent
ag.agent_name
end
end
|
#agent_type ⇒ Symbol?
Return the agent type associated with the role
88
89
90
91
92
|
# File 'lib/ddr/auth/roles/role.rb', line 88
def agent_type
if ag = get_agent
ag.agent_type
end
end
|
#get_agent ⇒ Object
119
120
121
122
123
|
# File 'lib/ddr/auth/roles/role.rb', line 119
def get_agent
if agent.present?
agent.first
end
end
|
#group_agent? ⇒ Boolean
98
99
100
|
# File 'lib/ddr/auth/roles/role.rb', line 98
def group_agent?
agent_type == :group
end
|
#inspect ⇒ Object
69
70
71
|
# File 'lib/ddr/auth/roles/role.rb', line 69
def inspect
"#<#{self.class.name} agent=#{agent.first.to_h.inspect}, scope=#{scope.first.inspect}>"
end
|
#permissions ⇒ Object
115
116
117
|
# File 'lib/ddr/auth/roles/role.rb', line 115
def permissions
self.class.permissions
end
|
#person_agent? ⇒ Boolean
94
95
96
|
# File 'lib/ddr/auth/roles/role.rb', line 94
def person_agent?
agent_type == :person
end
|
#role_type ⇒ Object
74
75
76
|
# File 'lib/ddr/auth/roles/role.rb', line 74
def role_type
self.class.role_type
end
|
#to_h ⇒ Object
Also known as:
to_hash
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ddr/auth/roles/role.rb', line 102
def to_h
val = {
type: role_type,
scope: scope.first
}
if agent.present?
val[agent_type] = agent_name
end
val
end
|
#to_s ⇒ Object
65
66
67
|
# File 'lib/ddr/auth/roles/role.rb', line 65
def to_s
to_h.to_s
end
|