Sha256: 7e38440508a39520544660a54bedfc973d72a207679539ab2fe8cb41a18ea048

Contents?: true

Size: 1.35 KB

Versions: 8

Compression:

Stored size: 1.35 KB

Contents

require 'json'

module Restfully
  module MediaType
    class Grid5000 < AbstractMediaType

      set :signature, %w{
        grid
        site
        cluster
        node
        nodeStatus
        version
        collection
        timeseries
        versions
        user
        metric
        job
        deployment
        notification
      }.map{|n|
        "application/vnd.fr.grid5000.api.#{n}+json"
      }.push(
        "application/vnd.grid5000+json"
      )
      set :parser, ApplicationJson::JSONParser

      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

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

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

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

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

    end
    
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
restfully-0.7.1.rc6 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.rc5 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.rc4 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.rc3 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.rc2 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.rc1 lib/restfully/media_type/grid5000.rb
restfully-0.7.1.pre lib/restfully/media_type/grid5000.rb
restfully-0.7.0.pre lib/restfully/media_type/grid5000.rb