Sha256: 3a35462ac63d03f01891895fa2724ee49652e9f24123af737d74e16af4faac39

Contents?: true

Size: 762 Bytes

Versions: 11

Compression:

Stored size: 762 Bytes

Contents

module ActiveFedora::Associations::Builder
  class SingularAssociation < Association #:nodoc:
    self.valid_options += [:dependent, :inverse_of]

    def self.constructable?
      true
    end

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

    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
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
active-fedora-9.7.3 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.7.2 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.9.1 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.9.0 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.8.2 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.8.1 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.8.0 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.7.1 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.7.0 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.6.2 lib/active_fedora/associations/builder/singular_association.rb
active-fedora-9.6.1 lib/active_fedora/associations/builder/singular_association.rb