module ActiveRecord::Chemistry::Representable::InstanceMethods

Public Instance Methods

find_by_or_keep_representable() click to toggle source
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 14
def find_by_or_keep_representable
  if representing.new_record? && @findable = representing_model.find_by(self.representing.attributes.reject { |k| ['id', 'created_at', 'updated_at'].include? k })
    self.representing = @findable
    #@findable.association(representing_model.representable_reflection.name.to_sym).add_to_target(self, true)
  end
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 39
def method_missing(method, *args, &block)
  if !self_respond_to?(method) && representing.respond_to?(method)
    representing.send(method, *args, &block)
  else
    super
  end
end
respond_to?(name, include_private = false, as_original_class = false) click to toggle source
Calls superclass method
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 27
def respond_to?(name, include_private = false, as_original_class = false)
  if as_original_class
    super(name, include_private)
  else
    super(name, include_private) || representing.respond_to?(name)
  end
end
self_respond_to?(name, include_private = false) click to toggle source
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 35
def self_respond_to?(name, include_private = false)
  respond_to? name, include_private, true
end
update_or_instantiate_representable() click to toggle source
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 21
def update_or_instantiate_representable
  if representing.changed? && representing.send(representing_model.representable_reflection.name.to_sym).count > 1
    self.representing = representing.dup
  end
end

Protected Instance Methods

representable_must_be_valid() click to toggle source
# File lib/activerecord/chemistry/representable/instance_methods.rb, line 5
def representable_must_be_valid
  unless representing.valid?
    representing.errors.each do |attribute, message|
      errors.add(attribute, message) unless errors[attribute].include?(message)
    end
  end
end