Class: Ddr::Auth::Agent Abstract
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- Ddr::Auth::Agent
- Includes:
- Hydra::Validations, RDF::Isomorphic
- Defined in:
- lib/ddr/auth/agent.rb
Overview
This class is abstract.
The agent (person or group) to whom a role is granted. Use subclasses for concrete instances.
Class Method Summary collapse
- .agent_type ⇒ Object
-
.build(obj) ⇒ Agent
Factory method Assumes that the string representation of the object may be used as the agent’s name.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Agents are considered equal if their names (and types) are equal.
- #agent_name ⇒ Object
- #agent_type ⇒ Object
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Class Method Details
.agent_type ⇒ Object
60 61 62 |
# File 'lib/ddr/auth/agent.rb', line 60 def agent_type @agent_type ||= self.name.split("::").last.underscore.to_sym end |
.build(obj) ⇒ Agent
Factory method
Assumes that the string representation of the object may be used as the agent's name.
51 52 53 54 55 56 57 58 |
# File 'lib/ddr/auth/agent.rb', line 51 def build(obj) new.tap do |agent| agent.name = obj.to_s if agent.invalid? raise Ddr::Models::Error, "Invalid #{self.name}: #{agent.errors..inspect}" end end end |
Instance Method Details
#==(other) ⇒ Object
Agents are considered equal if their names (and types) are equal
22 23 24 |
# File 'lib/ddr/auth/agent.rb', line 22 def ==(other) isomorphic_with? other end |
#agent_name ⇒ Object
38 39 40 |
# File 'lib/ddr/auth/agent.rb', line 38 def agent_name name.first end |
#agent_type ⇒ Object
42 43 44 |
# File 'lib/ddr/auth/agent.rb', line 42 def agent_type self.class.agent_type end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/ddr/auth/agent.rb', line 34 def inspect "#<#{self.class.name}(#{self})>" end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/ddr/auth/agent.rb', line 30 def to_h {type: agent_type, name: agent_name} end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/ddr/auth/agent.rb', line 26 def to_s agent_name end |