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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/activerecord/null/mimic.rb', line 65
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
#id ⇒ Object
Returns the value of attribute id.
36
37
38
|
# File 'lib/activerecord/null/mimic.rb', line 36
def id
@id
end
|
Instance Method Details
#[](key) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/activerecord/null/mimic.rb', line 38
def [](key)
normalized_key = key.to_sym
association_names = mimic_model_class.reflect_on_all_associations.map(&:name)
return nil if association_names.include?(normalized_key)
respond_to?(normalized_key) ? send(normalized_key) : nil
end
|
#_read_attribute(_) ⇒ Object
63
|
# File 'lib/activerecord/null/mimic.rb', line 63
def _read_attribute(_) = nil
|
#destroyed? ⇒ Boolean
57
|
# File 'lib/activerecord/null/mimic.rb', line 57
def destroyed? = false
|
#is_a?(klass) ⇒ Boolean
47
48
49
50
51
52
53
|
# File 'lib/activerecord/null/mimic.rb', line 47
def is_a?(klass)
if klass == mimic_model_class
true
else
super
end
end
|
#mimic_model_class ⇒ Object
34
|
# File 'lib/activerecord/null/mimic.rb', line 34
def mimic_model_class = self.class.mimic_model_class
|
#new_record? ⇒ Boolean
59
|
# File 'lib/activerecord/null/mimic.rb', line 59
def new_record? = false
|
#null? ⇒ Boolean
55
|
# File 'lib/activerecord/null/mimic.rb', line 55
def null? = true
|
#persisted? ⇒ Boolean
61
|
# File 'lib/activerecord/null/mimic.rb', line 61
def persisted? = false
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
81
82
83
|
# File 'lib/activerecord/null/mimic.rb', line 81
def respond_to_missing?(method, include_private = false)
mimic_model_class.reflect_on_all_associations.map(&:name).include?(method) || super
end
|