Class: RestObject
- Inherits:
-
Object
- Object
- RestObject
- Extended by:
- Forwardable
- Defined in:
- lib/rally_rest_api/ruport.rb,
lib/rally_rest_api/rest_object.rb
Overview
Ruport can deal with anything that has a #to_hash
Direct Known Subclasses
Instance Attribute Summary collapse
-
#rally_rest ⇒ Object
Returns the value of attribute rally_rest.
Instance Method Summary collapse
- #<=>(object) ⇒ Object
- #==(object) ⇒ Object
-
#body ⇒ Object
return the XML of the resource.
-
#delete ⇒ Object
delete the resource.
-
#elements(read = @elements.nil?) ⇒ Object
:nodoc:.
- #eql?(object) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(rally_rest = nil, document_content = nil) ⇒ RestObject
constructor
A new instance of RestObject.
- #marshal_dump ⇒ Object
- #marshal_load(stuff) ⇒ Object
-
#method_missing(sym, *args) ⇒ Object
:nodoc:.
-
#name ⇒ Object
(also: #to_s)
The name of the object, without having to read the entire body.
-
#oid ⇒ Object
The oid of the underlying resource.
- #parse_document ⇒ Object
-
#ref ⇒ Object
(also: #to_q)
the resource’s URI.
-
#refresh ⇒ Object
re-read the resource.
- #save! ⇒ Object
-
#to_hash ⇒ Object
:nodoc.
-
#type ⇒ Object
The type of the underlying resource.
- #type=(type) ⇒ Object (also: #artifact_type=)
-
#type_as_symbol ⇒ Object
the type as symbol.
-
#typedef ⇒ Object
return the typedef for this resource.
- #underscore(camel_cased_word) ⇒ Object
-
#update(args) ⇒ Object
update the resource.
Constructor Details
#initialize(rally_rest = nil, document_content = nil) ⇒ RestObject
Returns a new instance of RestObject.
36 37 38 39 40 41 |
# File 'lib/rally_rest_api/rest_object.rb', line 36 def initialize(rally_rest = nil, document_content = nil) @changed_values = {} @rally_rest = rally_rest @document_content = document_content parse_document if document_content end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
:nodoc:
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/rally_rest_api/rest_object.rb', line 243 def method_missing(sym, *args) # :nodoc: method = sym if sym.to_s.match(/(.*)=$/) method = $1.intern return @changed_values[method] = args.first end @changed_values[method] || self.elements[method] # Sometimes the xml returned has no element for things that are simply null. Without # asking the typedef, I have no way to know if the element exists, or has been ommited. # It would not be hard to ask the typedef, but they are expensive to load. It should be an option end |
Instance Attribute Details
#rally_rest ⇒ Object
Returns the value of attribute rally_rest.
32 33 34 |
# File 'lib/rally_rest_api/rest_object.rb', line 32 def rally_rest @rally_rest end |
Instance Method Details
#<=>(object) ⇒ Object
219 220 221 |
# File 'lib/rally_rest_api/rest_object.rb', line 219 def <=>(object) self.ref <=> object.ref end |
#==(object) ⇒ Object
205 206 207 208 209 |
# File 'lib/rally_rest_api/rest_object.rb', line 205 def ==(object) object.equal?(self) || (object.instance_of?(self.class) && object.ref == ref) end |
#body ⇒ Object
return the XML of the resource
146 147 148 |
# File 'lib/rally_rest_api/rest_object.rb', line 146 def body @document.to_s end |
#delete ⇒ Object
delete the resource
239 240 241 |
# File 'lib/rally_rest_api/rest_object.rb', line 239 def delete builder.delete_rest(ref, username, password) end |
#elements(read = @elements.nil?) ⇒ Object
:nodoc:
196 197 198 199 200 201 202 203 |
# File 'lib/rally_rest_api/rest_object.rb', line 196 def elements(read = @elements.nil?) #:nodoc: if read @document_content = builder.read_rest(self.ref, username, password) @document = REXML::Document.new @document_content @elements = parse(@document.root) end @elements end |
#eql?(object) ⇒ Boolean
215 216 217 |
# File 'lib/rally_rest_api/rest_object.rb', line 215 def eql?(object) self == (object) end |
#hash ⇒ Object
211 212 213 |
# File 'lib/rally_rest_api/rest_object.rb', line 211 def hash ref.hash end |
#marshal_dump ⇒ Object
52 53 54 |
# File 'lib/rally_rest_api/rest_object.rb', line 52 def marshal_dump [@rally_rest, @document_content, @changed_values] end |
#marshal_load(stuff) ⇒ Object
56 57 58 59 |
# File 'lib/rally_rest_api/rest_object.rb', line 56 def marshal_load(stuff) @rally_rest, @document_content, @changed_values = *stuff parse_document end |
#name ⇒ Object Also known as: to_s
The name of the object, without having to read the entire body
157 158 159 |
# File 'lib/rally_rest_api/rest_object.rb', line 157 def name @changed_values[:name] || @document.root.attributes["refObjectName"] end |
#oid ⇒ Object
The oid of the underlying resource
178 179 180 |
# File 'lib/rally_rest_api/rest_object.rb', line 178 def oid self.elements[:object_i_d] end |
#parse_document ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/rally_rest_api/rest_object.rb', line 43 def parse_document @document = REXML::Document.new @document_content if !ref?(@document.root) @elements = parse(@document.root) else @elements = nil end end |
#ref ⇒ Object Also known as: to_q
the resource’s URI
151 152 153 |
# File 'lib/rally_rest_api/rest_object.rb', line 151 def ref @document.root.attributes["ref"] end |
#refresh ⇒ Object
re-read the resource
191 192 193 194 |
# File 'lib/rally_rest_api/rest_object.rb', line 191 def refresh self.elements(true) self end |
#save! ⇒ Object
225 226 227 228 229 230 |
# File 'lib/rally_rest_api/rest_object.rb', line 225 def save! raise 'missing RallyRestAPI instance' unless rally_rest raise 'missing object type' unless @type @document_content = builder.create_rest(type, @changed_values, username, password) parse_document end |
#to_hash ⇒ Object
:nodoc
11 12 13 |
# File 'lib/rally_rest_api/ruport.rb', line 11 def to_hash # :nodoc elements end |
#type ⇒ Object
The type of the underlying resource
163 164 165 |
# File 'lib/rally_rest_api/rest_object.rb', line 163 def type @type || @document.root.attributes["type"] || @document.root.name end |
#type=(type) ⇒ Object Also known as: artifact_type=
167 168 169 |
# File 'lib/rally_rest_api/rest_object.rb', line 167 def type=(type) @type = type end |
#type_as_symbol ⇒ Object
the type as symbol
173 174 175 |
# File 'lib/rally_rest_api/rest_object.rb', line 173 def type_as_symbol underscore(self.type).intern end |
#typedef ⇒ Object
return the typedef for this resource.
183 184 185 186 187 188 |
# File 'lib/rally_rest_api/rest_object.rb', line 183 def typedef # this is a little ugly as we start to introduce some type specific info into this class. # All WorkspaceDomainObjects have a #workspace, that excludes user, workspace and subscription. return nil if self.type =~ /User|Workspace|Subscription/ TypeDefinition.cached_type_definition(self) end |
#underscore(camel_cased_word) ⇒ Object
141 142 143 |
# File 'lib/rally_rest_api/rest_object.rb', line 141 def underscore(camel_cased_word) camel_cased_word.split(/(?=[A-Z])/).join('_').downcase end |
#update(args) ⇒ Object
update the resource. This will re-read the resource after the update
233 234 235 236 |
# File 'lib/rally_rest_api/rest_object.rb', line 233 def update(args) builder.update_rest(type, ref, args, username, password) self.elements(true) end |