Class: Jiralicious::Issue::Transitions

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

Overview

The Transitions Class provides all of the functionality to retrieve, and use a transition associated with an Issue.

Instance Attribute Summary collapse

Attributes inherited from Base

#loaded

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#endpoint_name, endpoint_name, fetch, 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 = nil, default = nil) ⇒ Transitions

Initialization Method

Arguments

:decoded_json (optional) rubyized json object

:default (optional) default issue key



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
# File 'lib/jiralicious/issue/transitions.rb', line 22

def initialize(decoded_json = nil, default = nil)
  @loaded = false
  @meta = nil
  if decoded_json.is_a? Array
    if decoded_json.length == 1
      decoded_json = decoded_json[0]
    end
  end
  unless decoded_json.nil?
    if decoded_json.is_a? String
      self.class.property :jira_key
      self.jira_key = decoded_json
    elsif decoded_json.is_a? Hash
      properties_from_hash(decoded_json)
      super(decoded_json)
      parse!(decoded_json)
      @loaded = true
    else
      self.class.property :jira_key
      self.jira_key = default
      decoded_json.each do |list|
        self.class.property :"id_#{list['id']}"
        self.merge!({"id_#{list['id']}" => self.class.new(list)})
      end
    end
  end
end

Dynamic Method Handling

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

Instance Attribute Details

#metaObject

Retrieves the meta data for the Transition based on the options, Issue Key and Transition ID provided.



12
13
14
# File 'lib/jiralicious/issue/transitions.rb', line 12

def meta
  @meta
end

Class Method Details

.find(key) ⇒ Object Also known as: find_all

Retrieves the associated Transitions based on the Issue Key

Arguments

:key (required) issue key



57
58
59
60
61
62
63
64
# File 'lib/jiralicious/issue/transitions.rb', line 57

def find(key)
  issueKey_test(key)
  response = fetch({:parent => parent_name, :parent_key => key})
  response.parsed_response['transitions'].each do |t|
    t['jira_key'] = key
  end
  return new(response.parsed_response['transitions'], key)
end

.find_by_key_and_id(key, id) ⇒ Object

Retrieves the Transition based on the Issue Key and Transition ID

Arguments

:key (required) issue key

:id (required) transition id



74
75
76
77
78
79
80
81
# File 'lib/jiralicious/issue/transitions.rb', line 74

def find_by_key_and_id(key, id)
  issueKey_test(key)
  response = fetch({:parent => parent_name, :parent_key => key, :body => {"transitionId" => id}, :body_to_params => true })
  response.parsed_response['transitions'].each do |t|
    t['jira_key'] = key
  end
  return new(response.parsed_response['transitions'])
end

.go(key, id, options = {}) ⇒ Object

Processes the Transition based on the provided options

Arguments

:key (required) issue key

:id (required) transaction id

:comment (optional) comment to be added with transition

:fields (mixed) the fields that are required or optional

based on the individual transition


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/jiralicious/issue/transitions.rb', line 96

def go(key, id, options = {})
  issueKey_test(key)
  transition = {"transition" => {"id" => id}}
  if options[:comment].is_a? String
    transition.merge!({"update" => {"comment" => [{"add" => {"body" => options[:comment].to_s}}]}})
  elsif options[:comment].is_a? Jiralicious::Issue::Fields
    transition.merge!(options[:comment].format_for_update)
  elsif options[:comment].is_a? Hash
    transition.merge!({"update" => options[:comment]})
  end
  if options[:fields].is_a? Jiralicious::Issue::Fields
    transition.merge!(options[:fields].format_for_create)
  elsif options[:fields].is_a? Hash
    transition.merge!({"fields" => options[:fields]})
  end
  fetch({:method => :post, :parent => parent_name, :parent_key => key, :body => transition})
end

.meta(key, id, options = {}) ⇒ Object

Retrieves the meta data for the Transition based on the options, Issue Key and Transition ID provided.

Arguments

:key (required) issue key

:id (required) transaction id

:return (optional) boolean flag to determine if an object or hash is returned



125
126
127
128
129
130
131
132
133
# File 'lib/jiralicious/issue/transitions.rb', line 125

def meta(key, id, options = {})
  issueKey_test(key)
  response = fetch({:method => :get, :parent => parent_name, :parent_key => key, :body_to_params => true,
      :body => {"transitionId" => id, "expand" => "transitions.fields"}})
  response.parsed_response['transitions'].each do |t|
    t['jira_key'] = key
  end
  return (options[:return].nil?) ?  new(response.parsed_response['transitions'], key) : response
end

Instance Method Details

#allObject

Retrieves the associated Transitions based on the Issue Key



141
142
143
# File 'lib/jiralicious/issue/transitions.rb', line 141

def all
  self.class.all(self.jira_key) if self.jira_key
end

#go(options = {}) ⇒ Object

Processes the Transition based on the provided options

Arguments

:options are passed on to the ‘class.go’ function



151
152
153
# File 'lib/jiralicious/issue/transitions.rb', line 151

def go(options = {})
  self.class.go(self.jira_key, self.id, options)
end