Sha256: e432a28b57832d11b47eccc8417c6183efcbe65555181d8f2e8d7e94f59b6745

Contents?: true

Size: 711 Bytes

Versions: 6

Compression:

Stored size: 711 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
        elsif m[-1] != '='
          @attributes[m]
        else
          super
        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

6 entries across 6 versions & 2 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/grape-1.2.5/lib/grape/router/attribute_translator.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/grape-1.2.5/lib/grape/router/attribute_translator.rb
grape-1.2.5 lib/grape/router/attribute_translator.rb
grape-1.2.4 lib/grape/router/attribute_translator.rb
grape-1.2.3 lib/grape/router/attribute_translator.rb
grape-1.2.2 lib/grape/router/attribute_translator.rb