Sha256: 00c0fb36d24166ad8d7ed716e58dc7154c68aede086747e60c69968b792e455d

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Yaks
  class NullResource < Resource
    include attributes.add(collection: false),
            Equalizer.new(:rels, :collection)

    def initialize(opts = {})
      _opts = {}
      _opts[:rels]       = opts[:rels]       if opts.key?(:rels)
      _opts[:collection] = opts[:collection] if opts.key?(:collection)
      super(_opts)
    end

    def each
      to_enum
    end

    def collection?
      @collection
    end

    def null_resource?
      true
    end

    def seq
      []
    end

    def map
      return [] if collection?
      raise UnsupportedOperationError, "Operation #{__method__} not supported on #{self.class}"
    end

    def update_attributes(_new_attrs)
      raise UnsupportedOperationError, "Operation #{__method__} not supported on #{self.class}"
    end

    def add_link(_link)
      raise UnsupportedOperationError, "Operation #{__method__} not supported on #{self.class}"
    end

    def add_form(_form)
      raise UnsupportedOperationError, "Operation #{__method__} not supported on #{self.class}"
    end

    def add_subresource(_subresource)
      raise UnsupportedOperationError, "Operation #{__method__} not supported on #{self.class}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
yaks-0.7.7 lib/yaks/null_resource.rb