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, DirectlyContainsOne

Constant Summary

Constants inherited from Association

Association::VALID_OPTIONS

Class Method Summary collapse

Methods inherited from Association

add_destroy_callbacks, better_name, build, build_scope, check_dependent_options, create_reflection, define_callbacks, define_extensions, define_readers, define_validations, define_writers, macro, valid_dependent_options, validate_options, wrap_scope

Class Method Details

.define_accessors(model, reflection) ⇒ Object



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

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

.define_constructors(mixin, name) ⇒ Object



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

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

.valid_options(options) ⇒ Object



3
4
5
# File 'lib/active_fedora/associations/builder/singular_association.rb', line 3

def self.valid_options(options)
  super + [:dependent, :inverse_of, :required]
end