Module: ActiveRecord::Chemistry::Representable::InstanceMethods

Defined in:
lib/activerecord/chemistry/representable/instance_methods.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



39
40
41
42
43
44
45
# 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

Instance Method Details

#find_by_or_keep_representableObject



14
15
16
17
18
19
# 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

#respond_to?(name, include_private = false, as_original_class = false) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# 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) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# 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_representableObject



21
22
23
24
25
# 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