Class: Jiralicious::Field

Inherits:
Base
  • Object
show all
Defined in:
lib/jiralicious/field.rb

Overview

The Field class is used in multiple classes as a support object. This class is designed as a Object Oriented Method of viewing the Jira JSON/Hash.

Instance Attribute Summary

Attributes inherited from Base

#loaded

Instance Method Summary collapse

Methods inherited from Base

#all, #endpoint_name, endpoint_name, fetch, find, find_all, handler, issueKey_test, #loaded?, #method_missing, #numeric?, parent_name, #parent_name, #properties_from_hash, #reload

Methods included from Parsers::FieldParser

#parse!

Constructor Details

#initialize(decoded_json) ⇒ Field

Initialization Method

Builds the dynamic Field object from either a Hash or Array. The decoded JSON object can be nested as deep as necessary but it is recommended that JSON objects are no deeper then 5 levels maximum.

Arguments

:decoded_json (optional) rubyized json object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jiralicious/field.rb', line 20

def initialize(decoded_json)
  @loaded = false
  if decoded_json.is_a? Hash
    decoded_json = properties_from_hash(decoded_json)
    super(decoded_json)
    parse!(decoded_json)
    self.each do |k, v|
      if v.is_a? Hash
        self[k] = self.class.new(v)
      elsif v.is_a? Array
        v.each_index do |i|
          if v[i].is_a? Hash
            v[i] = self.class.new(v[i])
          end
        end
        self[k] = v
      end
    end
    @loaded = true
  else
    i = 0;
    decoded_json.each do |list|
      if !list['id'].nil?
        if numeric? list['id']
          id =  :"id_#{list['id']}"
        else
          id = :"#{list['id']}"
        end
  else
        id = :"_#{i}"
        i += 1
  end
      self.class.property id
     self[id] = self.class.new(list)
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Jiralicious::Base