Class: Jiralicious::Issue::Fields
- Inherits:
-
Object
- Object
- Jiralicious::Issue::Fields
- Defined in:
- lib/jiralicious/issue/fields.rb
Overview
The Fields class provides functionality to the Issue class that allows it to easily update or create issues. The class retains the original and the proposed information which could be used for cross validation prior to posting an update.
Instance Attribute Summary collapse
-
#fields_current ⇒ Object
The current fields when a ticket was loaded.
-
#fields_update ⇒ Object
The fields that will be updated or created.
Instance Method Summary collapse
-
#add_comment(comment) ⇒ Object
Adds a comment to the field list.
-
#append_a(field, value) ⇒ Object
Appends the current Array with the provided value.
-
#append_h(field, hash) ⇒ Object
Appends the current Hash with the provided value.
-
#append_s(field, value) ⇒ Object
Appends the current String with the provided value.
-
#count ⇒ Object
Returns the count of fields being updated.
-
#current ⇒ Object
Returns the current fields object.
-
#force_update ⇒ Object
Merges current to updated to allow for a forced update request to process.
-
#format_for_create ⇒ Object
Formats the fields_update object correctly for Jira to perform an create request.
-
#format_for_update ⇒ Object
Formats the fields_update object correctly for Jira to perform an update request.
-
#initialize(fc = nil) ⇒ Fields
constructor
Initialization Method.
-
#length ⇒ Object
Returns the length of fields being updated.
-
#set(field, value) ⇒ Object
Sets the field key with the provided value.
-
#set_current(fc) ⇒ Object
Fills the fields_current object with the provided Hash.
-
#set_id(field, value) ⇒ Object
Sets the field with a id hash.
-
#set_name(field, value) ⇒ Object
Sets the field with a name hash.
-
#updated ⇒ Object
Returns the updated fields object.
Constructor Details
#initialize(fc = nil) ⇒ Fields
Initialization Method
- Arguments
-
:fc (optional) fields to load
23 24 25 26 |
# File 'lib/jiralicious/issue/fields.rb', line 23 def initialize(fc = nil) @fields_current = (fc == nil) ? Hash.new : fc @fields_update = Hash.new end |
Instance Attribute Details
#fields_current ⇒ Object
The current fields when a ticket was loaded
15 16 17 |
# File 'lib/jiralicious/issue/fields.rb', line 15 def fields_current @fields_current end |
#fields_update ⇒ Object
The fields that will be updated or created
13 14 15 |
# File 'lib/jiralicious/issue/fields.rb', line 13 def fields_update @fields_update end |
Instance Method Details
#add_comment(comment) ⇒ Object
Adds a comment to the field list
- Arguments
-
:comment (required) comment text
48 49 50 51 52 53 |
# File 'lib/jiralicious/issue/fields.rb', line 48 def add_comment(comment) if !(@fields_update['comment'].is_a? Array) @fields_update['comment'] = Array.new end @fields_update['comment'].push({"add" => {"body" => comment}}) end |
#append_a(field, value) ⇒ Object
Appends the current Array with the provided value
- Arguments
-
:field (required) field to update
:value (required) value array
79 80 81 82 83 84 85 86 87 |
# File 'lib/jiralicious/issue/fields.rb', line 79 def append_a(field, value) @fields_update[field] = @fields_current[field] if (@fields_update[field] == nil) @fields_update[field] = Array.new if !(@fields_update[field].is_a? Array) if value.is_a? String @fields_update[field].push(value) unless @fields_update[field].include? value else @fields_update[field] |= value end end |
#append_h(field, hash) ⇒ Object
Appends the current Hash with the provided value
- Arguments
-
:field (required) field to update
:value (required) value hash
97 98 99 100 101 |
# File 'lib/jiralicious/issue/fields.rb', line 97 def append_h(field, hash) @fields_update[field] = @fields_current[field] if (@fields_update[field] == nil) @fields_update[field] = Hash.new if !(@fields_update[field].is_a? Hash) @fields_update[field].merge!(hash) end |
#append_s(field, value) ⇒ Object
Appends the current String with the provided value
- Arguments
-
:field (required) field to update
:value (required) value text
63 64 65 66 67 68 69 |
# File 'lib/jiralicious/issue/fields.rb', line 63 def append_s(field, value) if (@fields_update[field] == nil) @fields_update[field] = @fields_current[field] unless @fields_current.nil? @fields_update[field] ||= "" end @fields_update[field] += " " + value.to_s end |
#count ⇒ Object
Returns the count of fields being updated.
31 32 33 |
# File 'lib/jiralicious/issue/fields.rb', line 31 def count return @fields_update.count end |
#current ⇒ Object
Returns the current fields object
161 162 163 |
# File 'lib/jiralicious/issue/fields.rb', line 161 def current return @fields_current end |
#force_update ⇒ Object
Merges current to updated to allow for a forced update request to process.
107 108 109 |
# File 'lib/jiralicious/issue/fields.rb', line 107 def force_update @fields_update.merge!(@fields_current) end |
#format_for_create ⇒ Object
Formats the fields_update object correctly for Jira to perform an create request.
192 193 194 |
# File 'lib/jiralicious/issue/fields.rb', line 192 def format_for_create return {"fields" => @fields_update} end |
#format_for_update ⇒ Object
Formats the fields_update object correctly for Jira to perform an update request.
176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/jiralicious/issue/fields.rb', line 176 def format_for_update up = Hash.new @fields_update.each do |k, v| if k == "comment" up[k] = v else up[k] = [{"set" => v}] end end return {"update" => up} end |
#length ⇒ Object
Returns the length of fields being updated.
38 39 40 |
# File 'lib/jiralicious/issue/fields.rb', line 38 def length return @fields_update.length end |
#set(field, value) ⇒ Object
Sets the field key with the provided value.
- Arguments
-
:field (required) field to update
:value (required) value to add
119 120 121 |
# File 'lib/jiralicious/issue/fields.rb', line 119 def set(field, value) @fields_update[field] = value end |
#set_current(fc) ⇒ Object
Fills the fields_current object with the provided Hash.
- Arguments
-
:fc (optional) fields to load
154 155 156 |
# File 'lib/jiralicious/issue/fields.rb', line 154 def set_current(fc) @fields_current = fc if fc.type == Hash end |
#set_id(field, value) ⇒ Object
Sets the field with a id hash. This is necessary for some objects in Jira.
- Arguments
-
:field (required) field to update
:value (required) value text/int
145 146 147 |
# File 'lib/jiralicious/issue/fields.rb', line 145 def set_id(field, value) @fields_update[field] = {"id" => value} end |
#set_name(field, value) ⇒ Object
Sets the field with a name hash. This is necessary for some objects in Jira.
- Arguments
-
:field (required) field to update
:value (required) value text
132 133 134 |
# File 'lib/jiralicious/issue/fields.rb', line 132 def set_name(field, value) @fields_update[field] = {"name" => value} end |
#updated ⇒ Object
Returns the updated fields object
168 169 170 |
# File 'lib/jiralicious/issue/fields.rb', line 168 def updated return @fields_update end |