Sha256: f2f0381c7620bdc080f2270105bb4f8d083beac4f09e344c08463846decd2fb1

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 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"
      }.unshift(
        "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)
        id = id.to_s
        property("uid") == id || 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

9 entries across 9 versions & 1 rubygems

Version Path
restfully-1.0.0.rc2 lib/restfully/media_type/grid5000.rb
restfully-1.0.0.rc1 lib/restfully/media_type/grid5000.rb
restfully-0.8.8 lib/restfully/media_type/grid5000.rb
restfully-0.8.7 lib/restfully/media_type/grid5000.rb
restfully-0.8.6 lib/restfully/media_type/grid5000.rb
restfully-0.8.5 lib/restfully/media_type/grid5000.rb
restfully-0.8.4 lib/restfully/media_type/grid5000.rb
restfully-0.8.3 lib/restfully/media_type/grid5000.rb
restfully-0.8.2 lib/restfully/media_type/grid5000.rb