Class: ActiveFedora::Associations::Builder::SingularAssociation

Inherits:
Association
  • Object
show all
Defined in:
lib/active_fedora/associations/builder/singular_association.rb

Overview

:nodoc:

Direct Known Subclasses

BelongsTo, Contains

Instance Attribute Summary

Attributes inherited from Association

#mixin, #model, #name, #options

Class Method Summary collapse

Methods inherited from Association

build, #build, #configure_dependency, define_callbacks, define_readers, define_writers, #initialize, #predicate, #translate_property_to_predicate, #validate_options

Constructor Details

This class inherits a constructor from ActiveFedora::Associations::Builder::Association

Class Method Details

.constructable?Boolean


5
6
7
# File 'lib/active_fedora/associations/builder/singular_association.rb', line 5

def self.constructable?
  true
end

.define_accessors(model, reflection) ⇒ Object


9
10
11
12
# File 'lib/active_fedora/associations/builder/singular_association.rb', line 9

def self.define_accessors(model, reflection)
  super
  define_constructors(model.generated_association_methods, reflection.name)  if constructable?
end

.define_constructors(mixin, name) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/active_fedora/associations/builder/singular_association.rb', line 14

def self.define_constructors(mixin, name)
  mixin.redefine_method("build_#{name}") do |*params|
    association(name).build(*params)
  end

  mixin.redefine_method("create_#{name}") do |*params|
    association(name).create(*params)
  end

  mixin.redefine_method("create_#{name}!") do |*params|
    association(name).create!(*params)
  end
end