Class: RestfulSharePoint::Collection

Inherits:
CommonBase show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/restful-sharepoint/collection.rb

Direct Known Subclasses

Attachments, ListItems, Lists, Webs

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent: nil, connection: nil, collection: nil, options: {}) ⇒ Collection

Returns a new instance of Collection.



14
15
16
17
18
19
# 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

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



21
22
23
# File 'lib/restful-sharepoint/collection.rb', line 21

def connection
  @connection
end

#endpointObject



29
30
31
# File 'lib/restful-sharepoint/collection.rb', line 29

def endpoint
  @endpoint || (raise NotImplementedError, "Endpoint could not be determined")
end

#optionsObject

Returns the value of attribute options.



23
24
25
# File 'lib/restful-sharepoint/collection.rb', line 23

def options
  @options
end

Class Method Details

.object_classObject



10
11
12
# File 'lib/restful-sharepoint/collection.rb', line 10

def self.object_class
  Object
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/restful-sharepoint/collection.rb', line 41

def ==(other)
  other.== collection
end

#collectionObject



49
50
51
# File 'lib/restful-sharepoint/collection.rb', line 49

def collection
  @collection || self.collection = connection.get(endpoint, options: @options)
end

#collection=(collection) ⇒ Object



33
34
35
36
37
38
39
# 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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/restful-sharepoint/collection.rb', line 45

def eql?(other)
  other.eql? collection
end

#nextObject



67
68
69
# File 'lib/restful-sharepoint/collection.rb', line 67

def next
  self.new(@connection, @connection.get(collection['__next']))
end

#to_aObject Also known as: to_array



53
54
55
56
57
58
59
60
61
62
63
64
# 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

#to_json(*args, &block) ⇒ Object



71
72
73
# File 'lib/restful-sharepoint/collection.rb', line 71

def to_json(*args, &block)
  collection.to_json(*args, &block)
end