Class: EasyNavProxy
- Inherits:
-
Object
- Object
- EasyNavProxy
- Extended by:
- Forwardable
- Defined in:
- lib/opswalrus/patches.rb
Instance Method Summary collapse
- #easynav ⇒ Object
-
#initialize(indexable_obj) ⇒ EasyNavProxy
constructor
indexable_obj must implement #respond_to? and #has_key?.
- #method_missing(method, *args, **kwargs, &block) ⇒ Object
- #respond_to_missing?(method) ⇒ Boolean
-
#to_json(*args) ⇒ Object
Serialize Foo object with its class name and arguments.
Constructor Details
#initialize(indexable_obj) ⇒ EasyNavProxy
indexable_obj must implement #respond_to? and #has_key?
12 13 14 |
# File 'lib/opswalrus/patches.rb', line 12 def initialize(indexable_obj) @obj = indexable_obj end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **kwargs, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/opswalrus/patches.rb', line 25 def method_missing(method, *args, **kwargs, &block) if @obj.respond_to?(method) @obj.method(method).call(*args, **kwargs, &block) elsif @obj.has_key?(method) value = self[method] case value when Array, Hash EasyNavProxy.new(value) else value end end end |
Instance Method Details
#easynav ⇒ Object
18 19 20 |
# File 'lib/opswalrus/patches.rb', line 18 def easynav self end |
#respond_to_missing?(method) ⇒ Boolean
22 23 24 |
# File 'lib/opswalrus/patches.rb', line 22 def respond_to_missing?(method, *) @obj.respond_to?(method) || @obj.has_key?(method) end |
#to_json(*args) ⇒ Object
Serialize Foo object with its class name and arguments
40 41 42 |
# File 'lib/opswalrus/patches.rb', line 40 def to_json(*args) @obj.to_json(*args) end |