Sha256: c4663fe03cfbcb424450d8dce900e243c66e0911a261c20361c01d7b7045b5fe

Contents?: true

Size: 988 Bytes

Versions: 15

Compression:

Stored size: 988 Bytes

Contents

module Grape
  module Util
    class ReverseStackableValues
      attr_accessor :inherited_values
      attr_accessor :new_values

      def initialize(inherited_values = {})
        @inherited_values = inherited_values
        @new_values = {}
      end

      def [](name)
        [].tap do |value|
          value.concat(@new_values[name] || [])
          value.concat(@inherited_values[name] || [])
        end
      end

      def []=(name, value)
        @new_values[name] ||= []
        @new_values[name].push value
      end

      def delete(key)
        new_values.delete key
      end

      def keys
        (@new_values.keys + @inherited_values.keys).sort.uniq
      end

      def to_hash
        keys.each_with_object({}) do |key, result|
          result[key] = self[key]
        end
      end

      def initialize_copy(other)
        super
        self.inherited_values = other.inherited_values
        self.new_values = other.new_values.dup
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
grape-1.2.4 lib/grape/util/reverse_stackable_values.rb
grape-1.2.3 lib/grape/util/reverse_stackable_values.rb
grape-1.2.2 lib/grape/util/reverse_stackable_values.rb
grape-1.2.1 lib/grape/util/reverse_stackable_values.rb
grape-1.2.0 lib/grape/util/reverse_stackable_values.rb
grape-1.1.0 lib/grape/util/reverse_stackable_values.rb
grape-1.0.3 lib/grape/util/reverse_stackable_values.rb
grape-1.0.2 lib/grape/util/reverse_stackable_values.rb
grape-1.0.1 lib/grape/util/reverse_stackable_values.rb
grape-1.0.0 lib/grape/util/reverse_stackable_values.rb
grape-0.19.2 lib/grape/util/reverse_stackable_values.rb
grape-0.19.1 lib/grape/util/reverse_stackable_values.rb
grape-0.19.0 lib/grape/util/reverse_stackable_values.rb
grape-0.18.0 lib/grape/util/reverse_stackable_values.rb
grape-0.17.0 lib/grape/util/reverse_stackable_values.rb