Module: Priloo::ActiveRecordSupport
- Defined in:
- lib/priloo/active_record_support.rb
Constant Summary
collapse
- PRILOO_SUFFIX_REGEX =
/__priloo__\z/
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
7
8
9
|
# File 'lib/priloo/active_record_support.rb', line 7
def method_missing(method, *)
generate_priloo_method(method) || super
end
|
Instance Method Details
#_preloadable_target ⇒ Object
36
37
38
|
# File 'lib/priloo/active_record_support.rb', line 36
def _preloadable_target
self
end
|
#generate_priloo_method(method) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/priloo/active_record_support.rb', line 17
def generate_priloo_method(method)
index = method =~ PRILOO_SUFFIX_REGEX
return unless index
property = method.slice(0, index).to_sym
preloader =
case
when self.class.reflect_on_association(property)
Preloaders::ArAssociationPreloader.new(self.class, property)
when self.class.respond_to?("#{property}_sql")
Preloaders::BmInjectorPreloader.new(self.class, property)
end
self.class.define_method(method) { preloader }
preloader
end
|
#respond_to_missing?(method, _) ⇒ Boolean
11
12
13
|
# File 'lib/priloo/active_record_support.rb', line 11
def respond_to_missing?(method, _)
!generate_priloo_method(method).nil? || super
end
|