Class: CommonRepositoryModel::Collection

Inherits:
PersistenceBase
  • Object
show all
Defined in:
lib/common_repository_model/collection.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PersistenceBase

#active_model_serializer, find

Class Method Details

.has_members(method_name, options = {}) ⇒ Object



39
40
41
42
# File 'lib/common_repository_model/collection.rb', line 39

def self.has_members(method_name, options = {})
  membership_registry.has_members << method_name
  has_many(method_name, options)
end

.is_member_of(method_name, options = {}) ⇒ Object

Creates the :break_relation_with_<macro_name> method which is useful for managing both the ActiveFedora association and relationship.

NOTE: I believe this is actually masking an ActiveFedora bug, at some point, I would imagine that the :break_relation_with method would be deprecated and ultimately be an alias for object.<association_name>.delete(obj1,obj2)



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/common_repository_model/collection.rb', line 51

def self.is_member_of(method_name, options = {})
  membership_registry.is_member_of << method_name
  define_method "break_relation_with_#{method_name}" do |*args|
    send(method_name).delete(*args)
    args.each do |obj|
      remove_relationship(options[:property], obj)
      remove_relationship(:is_member_of, obj)
    end
  end
  has_and_belongs_to_many(method_name, options)
end

.membership_registryObject



31
32
33
# File 'lib/common_repository_model/collection.rb', line 31

def self.membership_registry
  @membership_registry ||= MembershipRegistry.new
end

Instance Method Details

#areaObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/common_repository_model/collection.rb', line 108

def area
  if is_root?
    __area
  else
    parent_areas.first
  end ||
  CommonRepositoryModel::Area.find_by_name!(name_of_area_to_assign)
rescue CommonRepositoryModel::ObjectNotFoundError
  nil
end

#area_nameObject



119
120
121
# File 'lib/common_repository_model/collection.rb', line 119

def area_name
  area.name
end

#find_or_build_data_for_given_slot_names(slot_names) ⇒ Object



149
150
151
152
153
# File 'lib/common_repository_model/collection.rb', line 149

def find_or_build_data_for_given_slot_names(slot_names)
  slot_names.collect { |name|
    data.detect { |d| d.slot_name == name } || data.build(slot_name: name)
  }
end

#is_root?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/common_repository_model/collection.rb', line 100

def is_root?
  parent_collections.size == 0
end

#membership_registryObject



35
36
37
# File 'lib/common_repository_model/collection.rb', line 35

def membership_registry
  self.class.membership_registry
end

#name_of_area_to_assignObject



76
77
78
# File 'lib/common_repository_model/collection.rb', line 76

def name_of_area_to_assign
  'NDLIB'
end

#parent_areasObject



104
105
106
# File 'lib/common_repository_model/collection.rb', line 104

def parent_areas
  parent_collections.collect(&:__area).uniq
end