Class: RallyAPI::RallyObject

Inherits:
Object
  • Object
show all
Defined in:
lib/rally_api/rally_object.rb

Overview

RallyObject is a helper class that wraps the JSON.parsed hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rally_rest, json_hash, warnings = {}) ⇒ RallyObject

Returns a new instance of RallyObject.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rally_api/rally_object.rb', line 16

def initialize(rally_rest, json_hash, warnings = {})
  # handle that we might not get a _ref or a _type
 @type = "unknown"
 if json_hash["_type"] && !json_hash["_type"].empty?
   @type = json_hash["_type"]
 elsif json_hash["_ref"] && !json_hash["_ref"].empty?
   @type = json_hash["_ref"].split("/")[-2]
 end
  @rally_object = json_hash
  @rally_rest   = rally_rest
  @warnings     = warnings[:warnings]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object (private)

An attempt to be rally_rest_api user friendly - you can get a field the old way with an underscored field name or the upcase name



146
147
148
149
150
151
152
# File 'lib/rally_api/rally_object.rb', line 146

def method_missing(sym, *args)
  ret_val = get_val(sym.to_s)
  if ret_val.nil? && @rally_rest.rally_rest_api_compat
    ret_val = get_val(camel_case_word(sym))
  end
  ret_val
end

Instance Attribute Details

#rally_objectObject (readonly)

Returns the value of attribute rally_object.



14
15
16
# File 'lib/rally_api/rally_object.rb', line 14

def rally_object
  @rally_object
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/rally_api/rally_object.rb', line 14

def type
  @type
end

#warningsObject (readonly)

Returns the value of attribute warnings.



14
15
16
# File 'lib/rally_api/rally_object.rb', line 14

def warnings
  @warnings
end

Instance Method Details

#<=>(object) ⇒ Object



102
103
104
# File 'lib/rally_api/rally_object.rb', line 102

def <=>(object)
  self.ref <=> object.ref
end

#==(object) ⇒ Object



92
93
94
95
96
# File 'lib/rally_api/rally_object.rb', line 92

def ==(object)
  object.equal?(self) ||
      (object.instance_of?(self.class) &&
          object.ref == ref)
end

#[](field_name) ⇒ Object



43
44
45
# File 'lib/rally_api/rally_object.rb', line 43

def [](field_name)
  get_val(field_name.to_s)
end

#[]=(field_name, value) ⇒ Object



47
48
49
50
# File 'lib/rally_api/rally_object.rb', line 47

def []=(field_name, value)
  return if field_name.nil?
  rally_object[field_name.to_s] = value
end

#camel_case_word(sym) ⇒ Object



66
67
68
# File 'lib/rally_api/rally_object.rb', line 66

def camel_case_word(sym)
  RallyAPI::RallyRestJson.camel_case_word(sym)
end

#deleteObject



138
139
140
# File 'lib/rally_api/rally_object.rb', line 138

def delete()
  @rally_rest.delete(rally_object["_ref"])
end

#elementsObject



70
71
72
73
74
75
76
77
78
# File 'lib/rally_api/rally_object.rb', line 70

def elements
  @rally_object.inject({}) do |elements, (key, value)|
    if key.to_s.start_with?("c_")
      key = key.to_s[2..-1]
    end
    elements[underscore(key).to_sym] = value
    elements
  end
end

#eql?(object) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/rally_api/rally_object.rb', line 98

def eql?(object)
  self == (object)
end

#getrefObject



58
59
60
# File 'lib/rally_api/rally_object.rb', line 58

def getref
  ref
end

#hashObject



106
107
108
# File 'lib/rally_api/rally_object.rb', line 106

def hash
  self.ref.hash
end

#nameObject



110
111
112
# File 'lib/rally_api/rally_object.rb', line 110

def name
  get_val('Name') || get_val('_refObjectName')
end

#oidObject



80
81
82
# File 'lib/rally_api/rally_object.rb', line 80

def oid
  object_i_d
end

#passwordObject



88
89
90
# File 'lib/rally_api/rally_object.rb', line 88

def password
  @rally_rest.rally_password
end

#rank_above(relative_rally_object) ⇒ Object



118
119
120
121
# File 'lib/rally_api/rally_object.rb', line 118

def rank_above(relative_rally_object)
  @rally_object = @rally_rest.rank_above(rally_object["_ref"],relative_rally_object["_ref"]).rally_object
  self
end

#rank_below(relative_rally_object) ⇒ Object



123
124
125
126
# File 'lib/rally_api/rally_object.rb', line 123

def rank_below(relative_rally_object)
  @rally_object = @rally_rest.rank_below(rally_object["_ref"],relative_rally_object["_ref"]).rally_object
  self
end

#rank_to_bottomObject



128
129
130
131
# File 'lib/rally_api/rally_object.rb', line 128

def rank_to_bottom
  @rally_object = @rally_rest.rank_to(rally_object["_ref"], "BOTTOM").rally_object
  self
end

#rank_to_topObject



133
134
135
136
# File 'lib/rally_api/rally_object.rb', line 133

def rank_to_top
  @rally_object = @rally_rest.rank_to(rally_object["_ref"], "TOP").rally_object
  self
end

#read(params = {}) ⇒ Object Also known as: refresh



52
53
54
55
# File 'lib/rally_api/rally_object.rb', line 52

def read(params = {})
  @rally_object = @rally_rest.reread(rally_object, params)
  self
end

#refObject



62
63
64
# File 'lib/rally_api/rally_object.rb', line 62

def ref
  rally_object["_ref"]
end

#to_json(*args) ⇒ Object



39
40
41
# File 'lib/rally_api/rally_object.rb', line 39

def to_json(*args)
  rally_object.to_json
end

#to_qObject



114
115
116
# File 'lib/rally_api/rally_object.rb', line 114

def to_q
  @rally_object["_ref"]
end

#to_s(*args) ⇒ Object



35
36
37
# File 'lib/rally_api/rally_object.rb', line 35

def to_s(*args)
  get_val('Name') || get_val('_refObjectName')
end

#update(fields, params = {}) ⇒ Object



29
30
31
32
33
# File 'lib/rally_api/rally_object.rb', line 29

def update(fields, params = {})
  oid = @rally_object["ObjectID"] || @rally_object["_ref"].split("/")[-1].split(".")[0]
  @rally_object = @rally_rest.update(@type.downcase.to_sym, oid, fields, params).rally_object
  self
end

#usernameObject



84
85
86
# File 'lib/rally_api/rally_object.rb', line 84

def username
  user_name || 
end