Class: Hydra::AccessControl::CollectionRelationship

Inherits:
Object
  • Object
show all
Defined in:
app/models/hydra/access_control.rb

Instance Method Summary collapse

Constructor Details

#initialize(owner, reflection) ⇒ CollectionRelationship

Returns a new instance of CollectionRelationship.



42
43
44
45
# File 'app/models/hydra/access_control.rb', line 42

def initialize(owner, reflection)
  @owner = owner
  @relationship = @owner.send(reflection)
end

Instance Method Details

#build(attributes) ⇒ Object

adds one to the target.



63
64
65
66
67
# File 'app/models/hydra/access_control.rb', line 63

def build(attributes)
  @relationship.build(attributes) do |record|
    record.access_to = @owner.owner
  end
end

#create(attributes) ⇒ Object



69
70
71
# File 'app/models/hydra/access_control.rb', line 69

def create(attributes)
  build(attributes).tap(&:save!)
end

#find(id) ⇒ Object

TODO: if directly_contained relationships supported find, we could just delegate find.



53
54
55
56
57
58
59
60
# File 'app/models/hydra/access_control.rb', line 53

def find(id)
  return to_a.find { |record| record.id == id } if @relationship.loaded?
  
  unless id.start_with?(@owner.id)
    raise ArgumentError, "requested ACL (#{id}) is not a member of #{@owner.id}"
  end
  ActiveFedora::Base.find(id)
end

#replace(*args) ⇒ Object



73
74
75
# File 'app/models/hydra/access_control.rb', line 73

def replace(*args)
  @relationship.replace(*args)
end