Class: ActiveFedora::Associations::Builder::Orders

Inherits:
CollectionAssociation show all
Includes:
ActiveFedora::AutosaveAssociation::AssociationBuilderExtension
Defined in:
lib/active_fedora/associations/builder/orders.rb

Defined Under Namespace

Modules: FixFirstLast

Constant Summary

Constants inherited from CollectionAssociation

CollectionAssociation::CALLBACKS

Constants inherited from Association

Association::VALID_OPTIONS

Class Method Summary collapse

Methods inherited from CollectionAssociation

define_callback, define_callbacks, define_extensions, wrap_scope

Methods inherited from Association

add_destroy_callbacks, better_name, build_scope, check_dependent_options, create_reflection, define_accessors, define_callbacks, define_extensions, define_validations, define_writers, valid_dependent_options, validate_options, wrap_scope

Class Method Details

.build(model, name, options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_fedora/associations/builder/orders.rb', line 25

def self.build(model, name, options)
  options = { unordered_reflection: unordered_reflection(model, name) }.merge(options)
  name = :"ordered_#{name.to_s.singularize}_proxies"
  model.property :head, predicate: ::RDF::Vocab::IANA['first']
  model.property :tail, predicate: ::RDF::Vocab::IANA.last
  model.send(:define_method, :apply_first_and_last) do
    source = send(options[:through])
    source.save
    return if head_ids == source.head_id && tail_ids == source.tail_id
    self.head = source.head_id
    self.tail = source.tail_id
    save! if changed?
  end
  model.include ActiveFedora::Associations::Builder::Orders::FixFirstLast
  super
end

.define_readers(mixin, name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/active_fedora/associations/builder/orders.rb', line 12

def self.define_readers(mixin, name)
  super
  mixin.redefine_method(target_accessor(name)) do
    association(name).target_reader
  end
  mixin.redefine_method("#{target_accessor(name, pluralize: false)}_ids") do
    association(name).target_ids_reader
  end
  mixin.redefine_method("#{target_accessor(name)}=") do |nodes|
    association(name).target_writer(nodes)
  end
end

.macroObject



4
5
6
# File 'lib/active_fedora/associations/builder/orders.rb', line 4

def self.macro
  :orders
end

.valid_options(options) ⇒ Object



8
9
10
# File 'lib/active_fedora/associations/builder/orders.rb', line 8

def self.valid_options(options)
  super + [:through, :unordered_reflection]
end