class Sawyer::Relation::Map

Public Class Methods

new() click to toggle source

Tracks the available next actions for a resource, and issues requests for them.

# File lib/sawyer/relation.rb, line 6
def initialize
  @map = {}
end

Public Instance Methods

<<(rel) click to toggle source

Adds a Relation to the map.

rel - A Relation.

Returns nothing.

# File lib/sawyer/relation.rb, line 15
def <<(rel)
  @map[rel.name] = rel if rel
end
[](key) click to toggle source

Gets the raw Relation by its name.

key - The Symbol name of the Relation.

Returns a Relation.

# File lib/sawyer/relation.rb, line 24
def [](key)
  @map[key.to_sym]
end
inspect() click to toggle source
# File lib/sawyer/relation.rb, line 49
def inspect
  hash = to_hash
  hash.respond_to?(:pretty_inspect) ? hash.pretty_inspect : hash.inspect
end
keys() click to toggle source

Gets a list of the Relation names.

Returns an Array of Symbols in no specific order.

# File lib/sawyer/relation.rb, line 38
def keys
  @map.keys
end
size() click to toggle source

Gets the number of mapped Relations.

Returns an Integer.

# File lib/sawyer/relation.rb, line 31
def size
  @map.size
end
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/sawyer/relation.rb, line 41
def to_hash
  pairs = @map.map do |k, v|
    [(k.to_s + "_url").to_sym, v.href]
  end
  Hash[pairs]
end
Also aliased as: to_h