Class: Jirarest2Field::HashField

Inherits:
TextField show all
Defined in:
lib/jirarest2/field.rb

Overview

A Field that presents its value in an hash that has additional information (“name”,“id”,“key”,“value”)

Direct Known Subclasses

UserField, VersionField

Instance Attribute Summary collapse

Attributes inherited from Field

#allowed_values, #id, #name, #raw_value, #readonly, #required

Instance Method Summary collapse

Methods inherited from Field

#createmeta, #value, #value=, #value_allowed?

Constructor Details

#initialize(id, name, args) ⇒ HashField

Returns a new instance of HashField.

Raises:



271
272
273
274
275
276
# File 'lib/jirarest2/field.rb', line 271

def initialize(id,name,args)
  @key ||= nil # Trying to initialize without overwriting something that might come from the subclass
  @key = args[:key].downcase  if ( ! args[:createmeta] && args[:key])
  super
  raise Jirarest2::HashKeyMissingException, "HashTypes like in #{id} alway require a key!" if @key.nil? 
end

Instance Attribute Details

#keyString (readonly)

The key element for the answers - It should not be needed - but it’s easer on the checks if it’s exposed

Returns:

  • (String)

    The key element for the way to Jira



264
265
266
# File 'lib/jirarest2/field.rb', line 264

def key
  @key
end

Instance Method Details

#parse_value(jvalue) ⇒ Object

Parse the value of this field as sent by the server



291
292
293
294
295
296
297
298
# File 'lib/jirarest2/field.rb', line 291

def parse_value(jvalue)
  super
  if jvalue.nil? then 
    @value = nil 
  else
    @value = jvalue[key] 
  end
end

#to_j(value = @value) ⇒ Hash

Representation to be used for json and jira

Returns:

  • (Hash)

    if value is set



280
281
282
283
284
285
286
287
# File 'lib/jirarest2/field.rb', line 280

def to_j(value = @value)
  if value.nil? then
    super(nil)
  else
    valuehash = {@key => value}
    super(valuehash)
  end
end

#to_j_inner(value = @value) ⇒ Hash

Representation to be used for json and jira without the fieldID

Returns:

  • (Hash)

    if value is set



302
303
304
305
306
307
308
309
# File 'lib/jirarest2/field.rb', line 302

def to_j_inner(value = @value)
  if value.nil? then
    super(nil)
  else
    valuehash = {@key => value}
    super(valuehash)
  end
end