Sha256: d121b81bea4576a3ee7cbad2a4fccc9e8af59cd5760fe312be0e3393a33d1a5b

Contents?: true

Size: 590 Bytes

Versions: 14

Compression:

Stored size: 590 Bytes

Contents

module JsonApiClient
  class LinkDefinition

    def initialize(spec)
      @spec = {}.with_indifferent_access
      spec.each do |type, definition|
        @spec[type.split(".").last] = definition.merge({slurp: type})
      end
    end

    def has_link?(type)
      @spec.has_key?(type)
    end

    def attribute_name_for(type)
      @spec.fetch(type).fetch("type")
    end

    def url_for(type, ids)
      definition = @spec.fetch(type)
      href = definition.fetch("href")
      slurp = definition.fetch("slurp")
      href.gsub("{#{slurp}}", Array(ids).join(","))
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
json_api_client-0.9.6 lib/json_api_client/link_definition.rb
json_api_client-0.9.5 lib/json_api_client/link_definition.rb
json_api_client-0.9.4 lib/json_api_client/link_definition.rb
json_api_client-0.9.3 lib/json_api_client/link_definition.rb
json_api_client-0.9.2 lib/json_api_client/link_definition.rb
json_api_client-0.9.0 lib/json_api_client/link_definition.rb
json_api_client-0.8.1 lib/json_api_client/link_definition.rb
json_api_client-0.8.0 lib/json_api_client/link_definition.rb
json_api_client-0.7.1 lib/json_api_client/link_definition.rb
json_api_client-0.7.0 lib/json_api_client/link_definition.rb
json_api_client-0.6.0 lib/json_api_client/link_definition.rb
json_api_client-0.5.1 lib/json_api_client/link_definition.rb
json_api_client-0.5.0 lib/json_api_client/link_definition.rb
json_api_client-0.4.0 lib/json_api_client/link_definition.rb