Module: ActiveRecord::QuickRead::LiteBase

Defined in:
lib/activerecord/quick_read/lite_base.rb

Instance Method Summary collapse

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_instanceObject

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_modelObject

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

#reloadObject



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

Returns:

  • (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