Class: Hydra::AccessControls::Permission

Inherits:
AccessControlList show all
Defined in:
app/models/hydra/access_controls/permission.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Permission

Returns a new instance of Permission.

Parameters:

  • args (Hash)

Options Hash (args):

  • :name (#to_s)

    name of agent

  • :type (#to_s)

    type of agent: group/person

  • :access (String)

    description of access: read/edit/discover



12
13
14
15
16
# File 'app/models/hydra/access_controls/permission.rb', line 12

def initialize(args)
  super()
  build_agent(args[:name].to_s, args[:type].to_s)
  build_access(args[:access])
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
# File 'app/models/hydra/access_controls/permission.rb', line 28

def ==(other)
  other.is_a?(Permission) && id == other.id && access_to_id == other.access_to_id &&
    agent.first.rdf_subject == other.agent.first.rdf_subject && mode.first.rdf_subject == other.mode.first.rdf_subject
end

#accessObject



56
57
58
# File 'app/models/hydra/access_controls/permission.rb', line 56

def access
  @access ||= mode.first.rdf_subject.to_s.split('#').last.downcase.sub('write', 'edit')
end

#agent_nameObject



43
44
45
# File 'app/models/hydra/access_controls/permission.rb', line 43

def agent_name
  URI.decode(parsed_agent.last)
end

#assign_attributes(attributes) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/models/hydra/access_controls/permission.rb', line 33

def assign_attributes(attributes)
  attrs = attributes.dup
  name = attrs.delete(:name)
  type = attrs.delete(:type)
  build_agent(name, type) if name && type
  access = attrs.delete(:access)
  build_access(access) if access
  super(attrs)
end

#inspectObject



22
23
24
25
26
# File 'app/models/hydra/access_controls/permission.rb', line 22

def inspect
  agent_value = agent.first.rdf_subject.to_s.inspect if agent.first
  mode_value = mode.first.rdf_subject.to_s.inspect if mode.first
  "<#{self.class.name} id: #{id} agent: #{agent_value} mode: #{mode_value} access_to: #{access_to_id.inspect}>"
end

#resetObject



51
52
53
54
# File 'app/models/hydra/access_controls/permission.rb', line 51

def reset
  @access = nil
  @parsed_agent = nil
end

#to_hashObject



18
19
20
# File 'app/models/hydra/access_controls/permission.rb', line 18

def to_hash
  { name: agent_name, type: type, access: access }
end

#typeObject



60
61
62
# File 'app/models/hydra/access_controls/permission.rb', line 60

def type
  parsed_agent.first
end

#updateObject



47
48
49
# File 'app/models/hydra/access_controls/permission.rb', line 47

def update(*)
  super.tap { reset }
end