Class: Ddr::Auth::Agent Abstract

Inherits:
ActiveTriples::Resource
  • Object
show all
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.

Direct Known Subclasses

Group, Person

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.agent_typeObject



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.

Parameters:

  • obj (Object)

    the object from which to build the agent

Returns:



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.messages.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_nameObject



38
39
40
# File 'lib/ddr/auth/agent.rb', line 38

def agent_name
  name.first
end

#agent_typeObject



42
43
44
# File 'lib/ddr/auth/agent.rb', line 42

def agent_type
  self.class.agent_type
end

#inspectObject



34
35
36
# File 'lib/ddr/auth/agent.rb', line 34

def inspect
  "#<#{self.class.name}(#{self})>"
end

#to_hObject



30
31
32
# File 'lib/ddr/auth/agent.rb', line 30

def to_h
  {type: agent_type, name: agent_name}
end

#to_sObject



26
27
28
# File 'lib/ddr/auth/agent.rb', line 26

def to_s
  agent_name
end