Class: Sawyer::Relation::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/sawyer/relation.rb

Instance Method Summary collapse

Constructor Details

#initializeMap

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



6
7
8
# File 'lib/sawyer/relation.rb', line 6

def initialize
  @map = {}
end

Instance Method Details

#<<(rel) ⇒ Object

Adds a Relation to the map.

rel - A Relation.

Returns nothing.



15
16
17
# File 'lib/sawyer/relation.rb', line 15

def <<(rel)
  @map[rel.name] = rel if rel
end

#[](key) ⇒ Object

Gets the raw Relation by its name.

key - The Symbol name of the Relation.

Returns a Relation.



24
25
26
# File 'lib/sawyer/relation.rb', line 24

def [](key)
  @map[key.to_sym]
end

#inspectObject



42
43
44
# File 'lib/sawyer/relation.rb', line 42

def inspect
  %(#<#{self.class}: #{@map.keys.inspect}>)
end

#keysObject

Gets a list of the Relation names.

Returns an Array of Symbols in no specific order.



38
39
40
# File 'lib/sawyer/relation.rb', line 38

def keys
  @map.keys
end

#sizeObject

Gets the number of mapped Relations.

Returns an Integer.



31
32
33
# File 'lib/sawyer/relation.rb', line 31

def size
  @map.size
end