Class: Grape::Router::AttributeTranslator
- Inherits:
-
Object
- Object
- Grape::Router::AttributeTranslator
- Defined in:
- lib/grape/router/attribute_translator.rb
Overview
this could be an OpenStruct, but doesn’t work in Ruby 2.3.0, see bugs.ruby-lang.org/issues/12251
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ AttributeTranslator
constructor
A new instance of AttributeTranslator.
- #method_missing(m, *args) ⇒ Object
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ AttributeTranslator
Returns a new instance of AttributeTranslator.
5 6 7 |
# File 'lib/grape/router/attribute_translator.rb', line 5 def initialize(attributes = {}) @attributes = attributes end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/grape/router/attribute_translator.rb', line 13 def method_missing(m, *args) if m[-1] == '=' @attributes[m[0..-1]] = *args elsif m[-1] != '=' @attributes[m] end end |
Instance Method Details
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
21 22 23 24 25 26 27 |
# File 'lib/grape/router/attribute_translator.rb', line 21 def respond_to_missing?(method_name, _include_private = false) if method_name[-1] == '=' true else @attributes.key?(method_name) end end |
#to_h ⇒ Object
9 10 11 |
# File 'lib/grape/router/attribute_translator.rb', line 9 def to_h @attributes end |