Sha256: ba2753abaa38c9116c65487aba74f631e1538f2453d0cdbf3b2293e4a843c417

Contents?: true

Size: 1.19 KB

Versions: 104

Compression:

Stored size: 1.19 KB

Contents

module Hike
  # `NormalizedArray` is an internal abstract wrapper class that calls
  # a callback `normalize_element` anytime an element is added to the
  # Array.
  #
  # `Extensions` and `Paths` are subclasses of `NormalizedArray`.
  class NormalizedArray < Array
    def initialize
      super()
    end

    def []=(*args)
      value = args.pop

      if value.respond_to?(:to_ary)
        value = normalize_elements(value)
      else
        value = normalize_element(value)
      end

      super(*args.concat([value]))
    end

    def <<(element)
      super normalize_element(element)
    end

    def collect!
      super do |element|
        result = yield element
        normalize_element(result)
      end
    end

    alias_method :map!, :collect!

    def insert(index, *elements)
      super index, *normalize_elements(elements)
    end

    def push(*elements)
      super(*normalize_elements(elements))
    end

    def replace(elements)
      super normalize_elements(elements)
    end

    def unshift(*elements)
      super(*normalize_elements(elements))
    end

    def normalize_elements(elements)
      elements.map do |element|
        normalize_element(element)
      end
    end
  end
end

Version data entries

104 entries across 82 versions & 21 rubygems

Version Path
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
railscast-assets-0.0.2 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
backbone-deep-rails-0.0.1 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
challah-0.9.1.beta vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/hike-1.2.1/lib/hike/normalized_array.rb
challah-0.9.0 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.3 vendor/bundle/gems/jquery_regex-0.0.3/vendor/bundle/gems/jquery_regex-0.0.2/vendor/bundle/gems/jquery_regex-0.0.1/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
jquery_regex-0.0.1 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
challah-rolls-0.2.0 vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/hike-1.2.1/lib/hike/normalized_array.rb