Sha256: 858d2e2170e5411ec3f5a057554db76eb1b27bceedff6929ae13d3a2b2f9b277

Contents?: true

Size: 775 Bytes

Versions: 36

Compression:

Stored size: 775 Bytes

Contents

# frozen_string_literal: true

require 'uri_template'

module LinkedRails
  class URITemplate < URITemplate::RFC6570
    ARRAY_SUFFIX = '%5B%5D'

    private

    def normalize_variables(vars)
      variables
        .select { |var| var.ends_with?(ARRAY_SUFFIX) }
        .each_with_object(super.with_indifferent_access) do |var, hash|
        key = var.sub(ARRAY_SUFFIX, '')
        hash[var] = normalize_array_value(hash[key]) if hash.key?(key)
      end
    end

    def normalize_array_value(original_value)
      return original_value unless original_value.is_a?(Hash)

      original_value.map do |key, values|
        (values.is_a?(Array) ? values : [values]).map do |value|
          "#{CGI.escape(key.to_s)}=#{value}"
        end
      end.flatten
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
linked_rails-0.0.4.pre.g3aeec2263 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gacd5f04d4 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gb0b6aea40 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g792a1b887 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g58af47992 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g0ec6e30ca lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g9e3bcac55 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g222bfeeca lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gb254a2893 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g2c6c26e86 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.ge881247c3 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gfabf7e9f5 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g8c045be3a lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g8d7195543 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gfe77aae19 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.gc866c1806 lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g3e8f5731a lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g58e27be7f lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g96885856b lib/linked_rails/uri_template.rb
linked_rails-0.0.4.pre.g1faca9643 lib/linked_rails/uri_template.rb