Class: RestfulSharePoint::Collection

Inherits:
CommonBase show all
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

Methods inherited from CommonBase

#objectify

Constructor Details

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

Returns a new instance of Collection.



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

def initialize(parent: nil, connection: nil, collection: nil, options: {})
  @parent = parent
  @connection = connection || @parent.connection # Iterate collection and coerce each into into a ListItem
  self.collection = collection
  self.options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



52
53
54
# File 'lib/restful-sharepoint/collection.rb', line 52

def method_missing(method, *args, &block)
  collection.respond_to?(method) ? collection.send(method, *args, &block) : super
end

Instance Attribute Details

#connectionObject

Returns the value of attribute connection.



16
17
18
# File 'lib/restful-sharepoint/collection.rb', line 16

def connection
  @connection
end

#endpointObject



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

def endpoint
  @endpoint || (raise NotImplementedError, "Endpoint needs to be set")
end

#optionsObject

Returns the value of attribute options.



18
19
20
# File 'lib/restful-sharepoint/collection.rb', line 18

def options
  @options
end

Class Method Details

.object_classObject



5
6
7
# File 'lib/restful-sharepoint/collection.rb', line 5

def self.object_class
  Object
end

Instance Method Details

#collectionObject



36
37
38
# File 'lib/restful-sharepoint/collection.rb', line 36

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

#collection=(collection) ⇒ Object



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

def collection=(collection)
  @collection = collection
  @collection&.each_with_index do |v,i|
    @collection[i] = objectify(v)
  end
  @properties
end

#nextObject



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

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

#respond_to_missing?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/restful-sharepoint/collection.rb', line 56

def respond_to_missing?(method, include_all = false)
  collection.respond_to?(method, include_all)
end

#to_json(*args, &block) ⇒ Object



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

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

#valuesObject



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

def values
  collection.dup.each { |k,v| properties[k] = v.values if v.is_a?(Object) || v.is_a?(Collection) }
end