Sha256: 5d85023d341e7fb532b2558ae627205c0775dc6e4e47c2277a5efc01753cd9cc

Contents?: true

Size: 718 Bytes

Versions: 3

Compression:

Stored size: 718 Bytes

Contents

module Yaks
  class Resource
    include Equalizer.new(:type, :links, :attributes, :subresources)
    include Enumerable

    attr_reader :type, :attributes, :links, :subresources

    def initialize(options)
      @type         = options.fetch(:type, nil)
      @attributes   = options.fetch(:attributes, {})
      @links        = options.fetch(:links, [])
      @subresources = options.fetch(:subresources, {})
    end

    def [](attr)
      attributes[attr]
    end

    # def type
    # end

    def each
      return to_enum unless block_given?
      yield self
    end

    def collection?
      false
    end

    def self_link
      links.find do |link|
        link.rel == :self
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
yaks-0.4.1 lib/yaks/resource.rb
yaks-0.4.0 lib/yaks/resource.rb
yaks-0.4.0.rc1 lib/yaks/resource.rb