Class: Sharepoint::Object

Inherits:
ObjectProperties show all
Defined in:
lib/sharepoint-object.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from ObjectProperties

#data, #site, #updated_data

Instance Method Summary collapse

Methods inherited from ObjectProperties

#add_properties, #add_property, #available_properties

Constructor Details

#initialize(site, data) ⇒ Object



100
101
102
103
# File 'lib/sharepoint-object.rb', line 100

def initialize site, data
  @parent = nil
  super site, data
end

Class Attribute Details

.fieldsObject

Returns the value of attribute fields



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

def fields
  @fields
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent



98
99
100
# File 'lib/sharepoint-object.rb', line 98

def parent
  @parent
end

Instance Method Details

#copy(new_object = nil) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/sharepoint-object.rb', line 133

def copy new_object = nil
  updating     = !new_object.nil?
  new_object ||= self.class.new @site
  self.class.fields.each do |field|
    next unless @data.keys.include? field[:name].to_s
    next if (field[:access] & [ :write, :initialize ]).count == 0
    value = @data[field[:name].to_s]
    if updating == false
      new_object.data[field[:name].to_s]         = value
    elsif new_object.data[field[:name].to_s] != value
      new_object.updated_data[field[:name].to_s] = value
    end
  end
  new_object
end

#destroyObject



126
127
128
129
130
131
# File 'lib/sharepoint-object.rb', line 126

def destroy
  @site.query :post, resource_uri do |curl|
    curl.headers['X-HTTP-Method'] = 'DELETE'
    curl.headers['If-Match']      = ['etag']
  end
end

#guidObject



105
106
107
108
109
110
111
112
# File 'lib/sharepoint-object.rb', line 105

def guid
  return @guid unless @guid.nil?
  ['id'].scan(/guid'([^']+)'/) do ||
    @guid = $1
    break
  end
  @guid
end

#reloadObject



114
115
116
# File 'lib/sharepoint-object.rb', line 114

def reload
  @site.query :get, ['uri']
end

#saveObject



118
119
120
121
122
123
124
# File 'lib/sharepoint-object.rb', line 118

def save
  if @data['__metadata'].nil? or @data['__metadata']['id'].nil?
    create
  elsif @updated_data.keys.count > 0
    update
  end
end