Sha256: ab1d73a1dbf7c2c7e00306cc9e1246df922f3320b5f1651847675c162e3f261a

Contents?: true

Size: 1.23 KB

Versions: 63

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require "yaml"

YAML.add_builtin_type("omap") do |type, val|
  ActiveSupport::OrderedHash[val.map { |v| v.to_a.first }]
end

module ActiveSupport
  # DEPRECATED: <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
  # insertion order.
  #
  #   oh = ActiveSupport::OrderedHash.new
  #   oh[:a] = 1
  #   oh[:b] = 2
  #   oh.keys # => [:a, :b], this order is guaranteed
  #
  # Also, maps the +omap+ feature for YAML files
  # (See http://yaml.org/type/omap.html) to support ordered items
  # when loading from yaml.
  #
  # <tt>ActiveSupport::OrderedHash</tt> is namespaced to prevent conflicts
  # with other implementations.
  class OrderedHash < ::Hash
    def to_yaml_type
      "!tag:yaml.org,2002:omap"
    end

    def encode_with(coder)
      coder.represent_seq "!omap", map { |k, v| { k => v } }
    end

    def select(*args, &block)
      dup.tap { |hash| hash.select!(*args, &block) }
    end

    def reject(*args, &block)
      dup.tap { |hash| hash.reject!(*args, &block) }
    end

    def nested_under_indifferent_access
      self
    end

    # Returns true to make sure that this hash is extractable via <tt>Array#extract_options!</tt>
    def extractable_options?
      true
    end
  end
end

Version data entries

63 entries across 57 versions & 9 rubygems

Version Path
activesupport-5.2.4.rc1 lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.1 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.9.0 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.3 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/activesupport-6.0.0/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.2 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
activesupport-6.0.0 lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.1 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
zuora_connect_ui-0.8.0 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
spiral_form-0.1.1 vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
spiral_form-0.1.0 vendor/bundle/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb
activesupport-6.0.0.rc2 lib/active_support/ordered_hash.rb
zuora_connect_ui-0.7.1 vendor/ruby/2.6.0/gems/activesupport-5.2.3/lib/active_support/ordered_hash.rb