Class: Jirarest2Field::MultiHashField
- Inherits:
-
MultiField
- Object
- Field
- MultiField
- Jirarest2Field::MultiHashField
- Defined in:
- lib/jirarest2/field.rb
Overview
to_j is shot
Hash Fields are always somewhat different to normal fields
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ String
readonly
The key element for the answers - It should not be needed - but it’s easer on the checks if it’s exposed.
Attributes inherited from MultiField
Attributes inherited from Field
#allowed_values, #id, #name, #raw_value, #readonly, #required
Instance Method Summary collapse
-
#initialize(id, name, args) ⇒ MultiHashField
constructor
A new instance of MultiHashField.
-
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server.
-
#to_j(value = @value) ⇒ Object
Return for JSON representation if @value == [] or nil and @delete is false set super will return nil.
-
#to_j_inner(value = @value) ⇒ Hash
Representation to be used for json and jira without the fieldID.
Methods inherited from MultiField
#<<, #[], #[]=, #delete, #delete_by_value, #value_allowed?
Methods inherited from Field
#createmeta, #value, #value=, #value_allowed?
Constructor Details
#initialize(id, name, args) ⇒ MultiHashField
Test to not really work for to_j
Hash_identifier is not alway “name”, we should have some “value” fields as well. Whole thing needs to be rewritten work with HashFields as parts
Returns a new instance of MultiHashField.
523 524 525 526 527 528 |
# File 'lib/jirarest2/field.rb', line 523 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} always require a key!" if @key.nil? end |
Instance Attribute Details
#key ⇒ String (readonly)
The key element for the answers - It should not be needed - but it’s easer on the checks if it’s exposed
515 516 517 |
# File 'lib/jirarest2/field.rb', line 515 def key @key end |
Instance Method Details
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server
532 533 534 535 536 537 |
# File 'lib/jirarest2/field.rb', line 532 def parse_value(jvalue) @rawvalue = jvalue jvalue.each{ |item| @value << item[@key] } end |
#to_j(value = @value) ⇒ Object
Return for JSON representation if @value == [] or nil and @delete is false set super will return nil
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/jirarest2/field.rb', line 541 def to_j(value = @value) if ((value == [] || value.nil?) and ! @delete) then super(nil) else value.compact! fields = Array.new if value[0].class < Jirarest2Field::Field then # This is how it should be value.each {|field| fields << field.to_j_inner } else value.each{ |field| f = HashField.new("10000a",field,{:createmeta => {"operations" => ["set"], "allowedValues" => [{@key => field}] } }) fields << f.to_j_inner } end super(fields) end end |
#to_j_inner(value = @value) ⇒ Hash
Representation to be used for json and jira without the fieldID
563 564 565 566 567 568 569 570 |
# File 'lib/jirarest2/field.rb', line 563 def to_j_inner(value = @value) if value.nil? then super(nil) else valuehash = {@key => value} super(valuehash) end end |