Module: ActiveRecord::QuickRead::LiteBase
- Defined in:
- lib/activerecord/quick_read/lite_base.rb
Instance Method Summary collapse
-
#_ar_instance ⇒ Object
Private.
-
#_ar_model ⇒ Object
Since the struct that includes this module is defined within the model’s namespace.
- #method_missing(name, *args, &block) ⇒ Object
- #reload ⇒ Object
- #respond_to_missing?(*args) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
4 5 6 7 8 |
# File 'lib/activerecord/quick_read/lite_base.rb', line 4 def method_missing(name, *args, &block) return super unless _ar_instance.respond_to?(name) _ar_instance.send(name, *args, &block) end |
Instance Method Details
#_ar_instance ⇒ Object
Private
25 26 27 |
# File 'lib/activerecord/quick_read/lite_base.rb', line 25 def _ar_instance @_ar_instance ||= _ar_model.from_hash(to_h) end |
#_ar_model ⇒ Object
Since the struct that includes this module is defined within the model’s namespace
30 31 32 |
# File 'lib/activerecord/quick_read/lite_base.rb', line 30 def _ar_model self.class.module_parent end |
#reload ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/activerecord/quick_read/lite_base.rb', line 14 def reload(*) source = @_ar_instance&.reload source ||= _ar_model.unscoped.where(id: id).quick_read return false unless source members.each { |attr| send(:"#{attr}=", source.send(attr)) } self end |
#respond_to_missing?(*args) ⇒ Boolean
10 11 12 |
# File 'lib/activerecord/quick_read/lite_base.rb', line 10 def respond_to_missing?(*args) _ar_instance.respond_to?(*args) || super end |