Sha256: a914a3d7376a6960d66a4af5c0e9aa81f3770e8e3b984efda896352635e3b479

Contents?: true

Size: 1.2 KB

Versions: 50

Compression:

Stored size: 1.2 KB

Contents

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

50 entries across 48 versions & 8 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/activesupport-5.0.7.1/lib/active_support/ordered_hash.rb
activesupport-5.0.7.2 lib/active_support/ordered_hash.rb
activesupport-5.0.7.1 lib/active_support/ordered_hash.rb
activesupport-5.0.7 lib/active_support/ordered_hash.rb
activesupport-5.0.6 lib/active_support/ordered_hash.rb
activesupport-5.0.6.rc1 lib/active_support/ordered_hash.rb
activesupport-5.0.5 lib/active_support/ordered_hash.rb
activesupport-5.0.5.rc2 lib/active_support/ordered_hash.rb
activesupport-5.0.5.rc1 lib/active_support/ordered_hash.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
tdiary-5.0.5 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
activesupport-5.0.4 lib/active_support/ordered_hash.rb
activesupport-5.0.4.rc1 lib/active_support/ordered_hash.rb
activesupport-5.0.3 lib/active_support/ordered_hash.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
lazy_record-0.2.1 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
lazy_record-0.2.0 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
lazy_record-0.1.9 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
lazy_record-0.1.8 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb
lazy_record-0.1.7 vendor/bundle/gems/activesupport-5.0.2/lib/active_support/ordered_hash.rb