Module: Dependo::Mixin
- Defined in:
- lib/dependo.rb
Overview
Allows dependencies to be injected into your classes. This can be done using both “include” or “extend”, depending on whether you need to use the dependencies as instance methods or class methods. Note that you can also do both.
Instance Method Summary collapse
-
#method_missing(key) ⇒ Object
The injected dependency in the Dependo::Registry with the given name.
-
#respond_to?(key, include_private = false) ⇒ Boolean
True if the Dependo::Registry has this method, otherwise check the actual object (using super).
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(key) ⇒ Object
Returns the injected dependency in the Dependo::Registry with the given name.
46 47 48 49 50 51 52 |
# File 'lib/dependo.rb', line 46 def method_missing(key) if Dependo::Registry.has_key?(key) Dependo::Registry[key] else raise NoMethodError, "undefined method '#{key.to_s}' for #{self.to_s}" end end |
Instance Method Details
#respond_to?(key, include_private = false) ⇒ Boolean
Returns true if the Dependo::Registry has this method, otherwise check the actual object (using super).
57 58 59 60 61 62 63 |
# File 'lib/dependo.rb', line 57 def respond_to?(key, include_private=false) if Dependo::Registry.has_key?(key) true else super(key, include_private) end end |