Class: CommonRepositoryModel::Collection

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PersistenceBase

#active_model_serializer, register_attribute

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



100
101
102
103
104
105
106
# File 'lib/common_repository_model/collection.rb', line 100

def area
  if is_root?
    __area
  else
    parent_areas.first
  end
end

#area=(an_area) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/common_repository_model/collection.rb', line 92

def area=(an_area)
  if is_root?
    self.__area = an_area
  else
    self.__area = parent_areas.first
  end
end

#area_nameObject



108
109
110
# File 'lib/common_repository_model/collection.rb', line 108

def area_name
  area.name
end

#find_or_build_data_for_given_slot_names(slot_names) ⇒ Object



143
144
145
146
147
# File 'lib/common_repository_model/collection.rb', line 143

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)


84
85
86
# File 'lib/common_repository_model/collection.rb', line 84

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

#parent_areasObject



88
89
90
# File 'lib/common_repository_model/collection.rb', line 88

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