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 Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#requirements ⇒ Object
readonly
Returns the value of attribute requirements.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ AttributeTranslator
constructor
A new instance of AttributeTranslator.
-
#method_missing(method_name, *args) ⇒ Object
rubocop:disable Style/MethodMissing.
- #respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ AttributeTranslator
Returns a new instance of AttributeTranslator.
9 10 11 12 13 |
# File 'lib/grape/router/attribute_translator.rb', line 9 def initialize(attributes = {}) @attributes = attributes @request_method = attributes[:request_method] @requirements = attributes[:requirements] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
rubocop:disable Style/MethodMissing
19 20 21 22 23 24 25 |
# File 'lib/grape/router/attribute_translator.rb', line 19 def method_missing(method_name, *args) # rubocop:disable Style/MethodMissing if setter?(method_name[-1]) attributes[method_name[0..-1]] = *args else attributes[method_name] end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/grape/router/attribute_translator.rb', line 7 def attributes @attributes end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
7 8 9 |
# File 'lib/grape/router/attribute_translator.rb', line 7 def request_method @request_method end |
#requirements ⇒ Object (readonly)
Returns the value of attribute requirements.
7 8 9 |
# File 'lib/grape/router/attribute_translator.rb', line 7 def requirements @requirements end |
Instance Method Details
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
27 28 29 30 31 32 33 |
# File 'lib/grape/router/attribute_translator.rb', line 27 def respond_to_missing?(method_name, _include_private = false) if setter?(method_name[-1]) true else @attributes.key?(method_name) end end |
#to_h ⇒ Object
15 16 17 |
# File 'lib/grape/router/attribute_translator.rb', line 15 def to_h attributes end |