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