module Upmin::AutomaticDelegation
Public Instance Methods
delegatable?(method)
click to toggle source
# File lib/upmin/automatic_delegation.rb, line 15 def delegatable?(method) return model.respond_to?(method) end
delegated?(method)
click to toggle source
# File lib/upmin/automatic_delegation.rb, line 19 def delegated?(method) return self.class.delegated?(method) end
method(method_name)
click to toggle source
Calls superclass method
# File lib/upmin/automatic_delegation.rb, line 27 def method(method_name) if delegated?(method_name) return model.method(method_name) else return super(method_name) end rescue NameError => e if delegatable?(method_name) self.class.delegate(method_name, to: :model) return method(method_name) else super(method_name) end end
method_missing(method, *args, &block)
click to toggle source
Delegates missing instance methods to the source model.
Calls superclass method
# File lib/upmin/automatic_delegation.rb, line 6 def method_missing(method, *args, &block) if delegatable?(method) self.class.delegate(method, to: :model) send(method, *args, &block) else return super end end
respond_to?(method)
click to toggle source
Calls superclass method
# File lib/upmin/automatic_delegation.rb, line 23 def respond_to?(method) super || delegatable?(method) end