Class: Restfully::MediaType::Grid5000

Inherits:
AbstractMediaType show all
Defined in:
lib/restfully/media_type/grid5000.rb

Instance Attribute Summary

Attributes inherited from AbstractMediaType

#io, #session

Instance Method Summary collapse

Methods inherited from AbstractMediaType

#banner, #complete?, default_type, defaults, #initialize, #links, parent, parser, #property, serialize, set, signature, supports?, unserialize, #unserialized

Constructor Details

This class inherits a constructor from Restfully::MediaType::AbstractMediaType

Instance Method Details

#collection?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/restfully/media_type/grid5000.rb', line 45

def collection?
  !!(property("items") && property("total") && property("offset"))
end

#direct_fetch_uri(symbol) ⇒ Object



49
50
51
52
53
# File 'lib/restfully/media_type/grid5000.rb', line 49

def direct_fetch_uri(symbol)
  self_link = links.find{|l| l.self?}
  return nil if self_link.nil?
  URI.parse([self_link.href, symbol.to_s].join("/"))
end

#each(*args, &block) ⇒ Object

Only for collections



69
70
71
72
73
# File 'lib/restfully/media_type/grid5000.rb', line 69

def each(*args, &block)
  (property("items") || []).map{|i|
    self.class.new(self.class.serialize(i), @session)
  }.each(*args, &block)
end


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/restfully/media_type/grid5000.rb', line 33

def extract_links
  (property.delete("links") || []).map do |link|
    l = Link.new(
      :rel => link['rel'],
      :type => link['type'],
      :href => link['href'],
      :title => link["title"],
      :id => link["title"]
    )
  end
end

#metaObject



55
56
57
58
59
60
61
# File 'lib/restfully/media_type/grid5000.rb', line 55

def meta
  if collection?
    property("items")
  else
    property
  end
end

#represents?(id) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
# File 'lib/restfully/media_type/grid5000.rb', line 63

def represents?(id)
  id = id.to_s
  property("uid") == id || property("uid") == id.to_i
end