Module: Upmin::AutomaticDelegation::ClassMethods
- Defined in:
- lib/upmin/automatic_delegation.rb
Instance Method Summary collapse
-
#before_remove_const ⇒ Object
Avoids reloading the model class when ActiveSupport clears autoloaded dependencies in development mode.
- #delegatable?(method) ⇒ Boolean
- #delegate(method, *args) ⇒ Object
- #delegated?(method) ⇒ Boolean
-
#method_missing(method, *args, &block) ⇒ Object
Proxies missing class methods to the source class.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Proxies missing class methods to the source class.
44 45 46 47 48 |
# File 'lib/upmin/automatic_delegation.rb', line 44 def method_missing(method, *args, &block) return super unless delegatable?(method) model_class.send(method, *args, &block) end |
Instance Method Details
#before_remove_const ⇒ Object
Avoids reloading the model class when ActiveSupport clears autoloaded dependencies in development mode.
71 72 |
# File 'lib/upmin/automatic_delegation.rb', line 71 def before_remove_const end |
#delegatable?(method) ⇒ Boolean
50 51 52 53 54 55 56 |
# File 'lib/upmin/automatic_delegation.rb', line 50 def delegatable?(method) @test ||={} @test[method] ||= 0 @test[method] += 1 return false if @test[method] > 2 model_class? && model_class.respond_to?(method) end |
#delegate(method, *args) ⇒ Object
58 59 60 61 62 |
# File 'lib/upmin/automatic_delegation.rb', line 58 def delegate(method, *args) @delegated ||= [] @delegated << method.to_sym super(method, *args) end |
#delegated?(method) ⇒ Boolean
64 65 66 67 |
# File 'lib/upmin/automatic_delegation.rb', line 64 def delegated?(method) @delegated ||= [] return @delegated.include?(method.to_sym) end |