Sha256: e8cc28276e4aa3228f06916fad7f9a7d8ab5f17056a0feb09a28b7fa1361f3ab

Contents?: true

Size: 668 Bytes

Versions: 3

Compression:

Stored size: 668 Bytes

Contents

module Grape
  class Router
    # this could be an OpenStruct, but doesn't work in Ruby 2.3.0, see https://bugs.ruby-lang.org/issues/12251
    class AttributeTranslator
      def initialize(attributes = {})
        @attributes = attributes
      end

      def to_h
        @attributes
      end

      def method_missing(m, *args)
        if m[-1] == '='
          @attributes[m[0..-1]] = *args
        else
          @attributes[m]
        end
      end

      def respond_to_missing?(method_name, _include_private = false)
        if method_name[-1] == '='
          true
        else
          @attributes.key?(method_name)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
grape-0.18.0 lib/grape/router/attribute_translator.rb
grape-0.17.0 lib/grape/router/attribute_translator.rb
grape-0.16.2 lib/grape/router/attribute_translator.rb