Class: Jirarest2Field::CascadingField
- Defined in:
- lib/jirarest2/field.rb
Overview
error message is more than just a bit misleading
The class to represent CascadingSelectFields
Instance Attribute Summary collapse
- #allowed_values ⇒ Object writeonly
-
#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.
-
#value ⇒ Object
writeonly
Set the value of the field.
Attributes inherited from Field
#allowed_values, #id, #name, #raw_value, #readonly, #required
Instance Method Summary collapse
-
#createmeta(structure) ⇒ Object
Interpret the result of createmeta for one field.
-
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server.
-
#to_j ⇒ Hash, Nil
Representation to be used for json and jira.
-
#value_allowed?(value) ⇒ Boolean
Checks if the value is in the list of allowed values.
Methods inherited from Field
Constructor Details
This class inherits a constructor from Jirarest2Field::Field
Instance Attribute Details
#allowed_values=(value) ⇒ Object (writeonly)
428 429 430 |
# File 'lib/jirarest2/field.rb', line 428 def allowed_values=(value) @allowed_values = value end |
#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
425 426 427 |
# File 'lib/jirarest2/field.rb', line 425 def key @key end |
#value=(value) ⇒ Object (writeonly)
Set the value of the field
453 454 455 456 457 458 |
# File 'lib/jirarest2/field.rb', line 453 def value=(content) if ! content.instance_of?(Array) or content.size != 2 then raise Jirarest2::ValueNotAllowedException.new(@name,"Array"), "needs to be an Array with exactly 2 parameters. Was #{content.class}." end super(content) end |
Instance Method Details
#createmeta(structure) ⇒ Object
The implementation is awkward with only one element in the array and the fields as Hashes in element 0. See if this is should be rewritten.
fills allowed_values with a straight list of allowed values.
Interpret the result of createmeta for one field
487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
# File 'lib/jirarest2/field.rb', line 487 def (structure) @readonly = true if structure["operations"] == [] @key = "value" if structure["allowedValues"] then @allowed_values << Hash.new structure["allowedValues"].each{ |suggestion| subentries = Array.new if suggestion.has_key?("children") then suggestion["children"].each{ |entry| subentries << entry["value"] } else subentries << nil end @allowed_values[0][suggestion[@key]] = subentries } end end |
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server
478 479 480 481 |
# File 'lib/jirarest2/field.rb', line 478 def parse_value(jvalue) super @value = [jvalue["value"],jvalue["child"]["value"]] end |
#to_j ⇒ Hash, Nil
Representation to be used for json and jira
464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/jirarest2/field.rb', line 464 def to_j if @value.nil? then super(nil) else if @value[1].nil? then super({"value" => @value[0]}) # If there is no child the server prefers not to be bothered else super({"value" => @value[0], "child" => {"value" => @value[1]}}) end end end |
#value_allowed?(value) ⇒ Boolean
Checks if the value is in the list of allowed values. If the list is empty every value is allowed
436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'lib/jirarest2/field.rb', line 436 def value_allowed?(value) return true if @allowed_values == [] # If there is no list get out of here fast # Special case to ensure that we can use the string "nil" if the is really an allowed value if value[1] == "nil" && ( @allowed_values[0].has_key?(value[0]) && @allowed_values[0][value[0]] == [nil] ) then value[1] = nil end if @allowed_values[0].has_key?(value[0]) && @allowed_values[0][value[0]].include?(value[1]) then return true else raise Jirarest2::ValueNotAllowedException.new(@name,@allowed_values), "#{value.to_s} is not a valid value. Please use one of #{@allowed_values}" end end |