class RestfulSharePoint::Collection

Constants

DEFAULT_OPTIONS

Attributes

connection[RW]
endpoint[W]
options[R]

Public Class Methods

new(parent: nil, connection: nil, collection: nil, options: {}) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 14
def initialize(parent: nil, connection: nil, collection: nil, options: {})
  @parent = parent
  @connection = @parent ? @parent.connection : connection
  self.collection = collection
  self.options = options
end
object_class() click to toggle source
# File lib/restful-sharepoint/collection.rb, line 10
def self.object_class
  Object
end

Public Instance Methods

==(other) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 41
def ==(other)
  other.== collection
end
collection() click to toggle source
# File lib/restful-sharepoint/collection.rb, line 49
def collection
  @collection || self.collection = connection.get(endpoint, options: @options)
end
collection=(collection) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 33
def collection=(collection)
  @collection = collection
  @collection&.each_with_index do |v,i|
    @collection[i] = connection.objectify(v)
  end
  @collection
end
endpoint() click to toggle source
# File lib/restful-sharepoint/collection.rb, line 29
def endpoint
  @endpoint || (raise NotImplementedError, "Endpoint could not be determined")
end
eql?(other) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 45
def eql?(other)
  other.eql? collection
end
next() click to toggle source
# File lib/restful-sharepoint/collection.rb, line 67
def next
  self.new(@connection, @connection.get(collection['__next']))
end
options=(options) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 24
def options=(options)
  @options = self.class::DEFAULT_OPTIONS.merge(options)
end
to_a() click to toggle source
# File lib/restful-sharepoint/collection.rb, line 53
def to_a
  collection.map do |v|
    case v
    when Object
      v.to_h
    when Collection
      v.to_a
    else
      v
    end
  end
end
Also aliased as: to_array
to_array()
Alias for: to_a
to_json(*args, &block) click to toggle source
# File lib/restful-sharepoint/collection.rb, line 71
def to_json(*args, &block)
  collection.to_json(*args, &block)
end