class Immortal::BelongsToBuilder

Builds a belongs_to association with _with_deleted and _only_deleted readers.

Public Class Methods

define_accessors(mixin, reflection) click to toggle source
Calls superclass method
# File lib/immortal/belongs_to_builder.rb, line 8
def self.define_accessors(mixin, reflection)
  super
  define_deletables(mixin, reflection)
end

Private Class Methods

define_deletables(mixin, reflection) click to toggle source
# File lib/immortal/belongs_to_builder.rb, line 13
def self.define_deletables(mixin, reflection)
  define_with_deleted_reader(mixin, reflection)
  define_only_deleted_reader(mixin, reflection)
end
define_only_deleted_reader(mixin, reflection) click to toggle source
# File lib/immortal/belongs_to_builder.rb, line 30
def self.define_only_deleted_reader(mixin, reflection)
  name = reflection.name

  mixin.redefine_method("#{name}_only_deleted") do |*params|
    assoc = association(name)
    assoc.send(:extend, SingularAssociation)
    assoc.only_deleted_reader(*params)
  end
end
define_with_deleted_reader(mixin, reflection) click to toggle source
# File lib/immortal/belongs_to_builder.rb, line 19
def self.define_with_deleted_reader(mixin, reflection)
  name = reflection.name

  mixin.redefine_method("#{name}_with_deleted") do |*params|
    assoc = association(name)
    assoc.send(:extend, SingularAssociation)
    assoc.with_deleted_reader(*params)
  end
end