Module: ActiveRecord::Null::Mimic

Extended by:
ActiveSupport::Concern
Defined in:
lib/activerecord/null/mimic.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/activerecord/null/mimic.rb', line 57

def method_missing(method, ...)
  reflections = mimic_model_class.reflect_on_all_associations
  if (reflection = reflections.find { |r| r.name == method })
    case reflection.macro
    when :has_many
      define_memoized_association(method, reflection.klass.none)
    when :has_one, :belongs_to
      define_memoized_association(method, reflection.klass.null)
    else
      super
    end
  else
    super
  end
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



36
37
38
# File 'lib/activerecord/null/mimic.rb', line 36

def id
  @id
end

Instance Method Details

#[]Object



38
39
# File 'lib/activerecord/null/mimic.rb', line 38

def [](*)
end

#destroyed?Boolean

Returns:

  • (Boolean)


51
# File 'lib/activerecord/null/mimic.rb', line 51

def destroyed? = false

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
45
46
47
# File 'lib/activerecord/null/mimic.rb', line 41

def is_a?(klass)
  if klass == mimic_model_class
    true
  else
    super
  end
end

#mimic_model_classObject



34
# File 'lib/activerecord/null/mimic.rb', line 34

def mimic_model_class = self.class.mimic_model_class

#new_record?Boolean

Returns:

  • (Boolean)


53
# File 'lib/activerecord/null/mimic.rb', line 53

def new_record? = false

#null?Boolean

Returns:

  • (Boolean)


49
# File 'lib/activerecord/null/mimic.rb', line 49

def null? = true

#persisted?Boolean

Returns:

  • (Boolean)


55
# File 'lib/activerecord/null/mimic.rb', line 55

def persisted? = false

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/activerecord/null/mimic.rb', line 73

def respond_to_missing?(method, include_private = false)
  mimic_model_class.reflect_on_all_associations.map(&:name).include?(method) || super
end