class RestfulSharePoint::Object
Constants
- DEFAULT_OPTIONS
Attributes
connection[RW]
endpoint[W]
options[R]
properties[W]
Public Class Methods
new(parent: nil, connection: nil, properties: nil, id: nil, options: {})
click to toggle source
# File lib/restful-sharepoint/object.rb, line 10 def initialize(parent: nil, connection: nil, properties: nil, id: nil, options: {}) raise Error, "Either a parent or connection must be provided." unless parent || connection @parent = parent @connection = @parent ? @parent.connection : connection self.properties = properties @id = id self.options = options end
Public Instance Methods
==(other)
click to toggle source
# File lib/restful-sharepoint/object.rb, line 46 def ==(other) other.== properties end
[](key, options = {})
click to toggle source
# File lib/restful-sharepoint/object.rb, line 35 def [](key, options = {}) if connection.objectified?(properties[key]) warn "`options` have been ignored as deferred object has already been fetched" unless options.empty? properties[key] elsif properties[key].respond_to?('[]') && properties[key]['__deferred'] properties[key] = fetch_deferred(key, options) else properties[key] = connection.objectify(properties[key]) end end
each() { |k, self| ... }
click to toggle source
# File lib/restful-sharepoint/object.rb, line 77 def each(&block) properties.each do |k,v| yield k, self[k] end end
endpoint()
click to toggle source
# File lib/restful-sharepoint/object.rb, line 26 def endpoint @endpoint || self['__metadata']['uri'] || (raise NotImplementedError, "Endpoint could not be determined") end
eql?(other)
click to toggle source
# File lib/restful-sharepoint/object.rb, line 50 def eql?(other) other.eql? properties end
fetch_deferred(property, options = {})
click to toggle source
# File lib/restful-sharepoint/object.rb, line 69 def fetch_deferred(property, options = {}) connection.get_as_object(@properties[property]['__deferred']['uri'], options: options) end
options=(options)
click to toggle source
# File lib/restful-sharepoint/object.rb, line 21 def options=(options) @options = self.class::DEFAULT_OPTIONS.merge(options) end
properties()
click to toggle source
# File lib/restful-sharepoint/object.rb, line 31 def properties @properties || self.properties = connection.get(endpoint, options: @options) end
to_h()
click to toggle source
# File lib/restful-sharepoint/object.rb, line 54 def to_h hash = {} properties.each do |k,v| hash[k] = case v when Object v.to_h when Collection v.to_a else v end end end
Also aliased as: to_hash
to_json(*args, &block)
click to toggle source
# File lib/restful-sharepoint/object.rb, line 73 def to_json(*args, &block) properties.to_json(*args, &block) end