Class: Jirarest2Field::Field
- Inherits:
-
Object
- Object
- Jirarest2Field::Field
- Defined in:
- lib/jirarest2/field.rb
Overview
Superclass for all fields
Direct Known Subclasses
CascadingField, DateField, MultiField, TextField, TimetrackingField
Instance Attribute Summary collapse
-
#allowed_values ⇒ Array
Allowed values for the fields.
-
#id ⇒ String
readonly
The field id in JIRA(tm).
-
#name ⇒ String
readonly
The name given to the field (not unique in jira!).
-
#raw_value ⇒ Hash
readonly
The raw value.
-
#readonly ⇒ Boolean
readonly
Is this field readonly?.
-
#required ⇒ Boolean
readonly
Is this field mandatory?.
Instance Method Summary collapse
-
#createmeta(structure) ⇒ Object
Interpret the result of createmeta for one field If there is only one value allowed this value will be set.
-
#initialize(id, name, args) ⇒ Field
constructor
A new instance of Field.
-
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server.
-
#to_j(value = @value) ⇒ Hash, Nil
Representation to be used for json and jira.
-
#value(raw = false) ⇒ String, Object
Get the value of the field.
-
#value=(content) ⇒ Object
Set the value of the field.
-
#value_allowed?(value) ⇒ Boolean
Checks if the value is in the list of allowed values.
Constructor Details
#initialize(id, name, args) ⇒ Field
Returns a new instance of Field.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/jirarest2/field.rb', line 45 def initialize(id,name,args) @id = id @name = name if args[:required] then @required = true else @required = false end @allowed_values = [] if args[:allowed_values] then allowed_values = args[:allowed_values] end @value = nil @readonly = false if args[:createmeta] then (args[:createmeta]) end end |
Instance Attribute Details
#allowed_values ⇒ Array
Allowed values for the fields
40 41 42 |
# File 'lib/jirarest2/field.rb', line 40 def allowed_values @allowed_values end |
#id ⇒ String (readonly)
The field id in JIRA(tm)
31 32 33 |
# File 'lib/jirarest2/field.rb', line 31 def id @id end |
#name ⇒ String (readonly)
The name given to the field (not unique in jira!)
34 35 36 |
# File 'lib/jirarest2/field.rb', line 34 def name @name end |
#raw_value ⇒ Hash (readonly)
The raw value
37 38 39 |
# File 'lib/jirarest2/field.rb', line 37 def raw_value @raw_value end |
#readonly ⇒ Boolean (readonly)
Is this field readonly?
28 29 30 |
# File 'lib/jirarest2/field.rb', line 28 def readonly @readonly end |
#required ⇒ Boolean (readonly)
Is this field mandatory?
25 26 27 |
# File 'lib/jirarest2/field.rb', line 25 def required @required end |
Instance Method Details
#createmeta(structure) ⇒ Object
change @allowed_values here. -> suggestion has to go to and build the correct type
Interpret the result of createmeta for one field If there is only one value allowed this value will be set
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/jirarest2/field.rb', line 107 def (structure) @readonly = true if structure["operations"] == [] if structure["allowedValues"] then structure["allowedValues"].flatten!(1) if ! structure["allowedValues"][0].nil? then if structure["allowedValues"][0].has_key?("value") then @key = "value" elsif structure["allowedValues"][0].has_key?("key") then @key = "key" elsif structure["allowedValues"][0].has_key?("name") then @key = "name" else @key = "id" end structure["allowedValues"].each{ |suggestion| @allowed_values << suggestion[@key] } if structure["allowedValues"].size == 1 && !structure["allowedValues"][0].instance_of?(Array) then # If there is only one value allowed it might as well be set at the earliest convenience @value = structure["allowedValues"][0][@key] end else @key = "" @allowed_values == [] end end end |
#parse_value(jvalue) ⇒ Object
Parse the value of this field as sent by the server
136 137 138 139 |
# File 'lib/jirarest2/field.rb', line 136 def parse_value(jvalue) @rawvalue = jvalue @value = jvalue end |
#to_j(value = @value) ⇒ Hash, Nil
Representation to be used for json and jira
95 96 97 98 99 100 101 |
# File 'lib/jirarest2/field.rb', line 95 def to_j(value = @value) if value.nil? then return nil else return {@id => value} end end |
#value(raw = false) ⇒ String, Object
Get the value of the field
68 69 70 |
# File 'lib/jirarest2/field.rb', line 68 def value(raw = false) return @value end |
#value=(content) ⇒ Object
Set the value of the field
87 88 89 |
# File 'lib/jirarest2/field.rb', line 87 def value=(content) @value = content if value_allowed?(content) 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
76 77 78 79 80 81 82 83 |
# File 'lib/jirarest2/field.rb', line 76 def value_allowed?(value) return true if @allowed_values == [] # If there is no list get out of here fast if @allowed_values.include?(value) then return true else raise Jirarest2::ValueNotAllowedException.new(@name,@allowed_values), "#{value} is not a valid value. Please use one of #{@allowed_values.join("; ").to_s}" end end |