Class: JIRA::Resource::Issue
- Defined in:
- lib/jira/resource/issuelink.rb,
lib/jira/resource/issue.rb
Overview
Because of circular dependency Issue->IssueLink->Issue we have to declare JIRA::Resource::Issue class.
Constant Summary
Constants inherited from Base
Base::QUERY_PARAMS_FOR_SEARCH, Base::QUERY_PARAMS_FOR_SINGLE_FETCH
Instance Attribute Summary
Attributes inherited from Base
#attrs, #client, #deleted, #expanded
Class Method Summary collapse
- .all(client) ⇒ Object
- .jql(client, jql, options = {fields: nil, start_at: nil, max_results: nil, expand: nil, validate_query: true}) ⇒ Object
Instance Method Summary collapse
- #editmeta ⇒ Object
-
#fetch(reload = false, query_params = {}) ⇒ Object
Fetches the attributes for the specified resource from JIRA unless the resource is already expanded and the optional force reload flag is not set.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to?(method_name, include_all = false) ⇒ Boolean
Methods inherited from Base
belongs_to, belongs_to_relationships, build, collection_attributes_are_nested, collection_path, #collection_path, #delete, endpoint_name, find, #has_errors?, has_many, has_one, #id, #initialize, key_attribute, #key_value, nested_collections, #new_record?, parse_json, #patched_url, #path_component, #save, #save!, #set_attrs, #set_attrs_from_response, singular_path, #to_json, #to_s, #to_sym, #url
Constructor Details
This class inherits a constructor from JIRA::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/jira/resource/issue.rb', line 107 def method_missing(method_name, *args, &block) if attrs.keys.include?('fields') if attrs['fields'].keys.include?(method_name.to_s) attrs['fields'][method_name.to_s] else official_name=client.Field.name_to_id(method_name) if attrs['fields'].keys.include?(official_name) attrs['fields'][official_name] else super(method_name, *args, &block) end end else super(method_name, *args, &block) end end |
Class Method Details
.all(client) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/jira/resource/issue.rb', line 42 def self.all(client) url = client.[:rest_base_path] + "/search?expand=transitions.fields" response = client.get(url) json = parse_json(response.body) json['issues'].map do |issue| client.Issue.build(issue) end end |
.jql(client, jql, options = {fields: nil, start_at: nil, max_results: nil, expand: nil, validate_query: true}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jira/resource/issue.rb', line 51 def self.jql(client, jql, = {fields: nil, start_at: nil, max_results: nil, expand: nil, validate_query: true}) url = client.[:rest_base_path] + "/search?jql=#{CGI.escape(jql)}" url << "&fields=#{[:fields].map{ |value| CGI.escape(client.Field.name_to_id(value)) }.join(',')}" if [:fields] url << "&startAt=#{CGI.escape([:start_at].to_s)}" if [:start_at] url << "&maxResults=#{CGI.escape([:max_results].to_s)}" if [:max_results] url << "&validateQuery=false" if [:validate_query] === false if [:expand] [:expand] = [[:expand]] if [:expand].is_a?(String) url << "&expand=#{[:expand].to_a.map{ |value| CGI.escape(value.to_s) }.join(',')}" end response = client.get(url) json = parse_json(response.body) if [:max_results] and [:max_results] == 0 return json['total'] end json['issues'].map do |issue| client.Issue.build(issue) end end |
Instance Method Details
#editmeta ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/jira/resource/issue.rb', line 91 def = client.[:rest_base_path] + "/#{self.class.endpoint_name}/#{key}/editmeta" response = client.get() json = self.class.parse_json(response.body) json['fields'] end |
#fetch(reload = false, query_params = {}) ⇒ Object
Fetches the attributes for the specified resource from JIRA unless the resource is already expanded and the optional force reload flag is not set
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jira/resource/issue.rb', line 77 def fetch(reload = false, query_params = {}) return if && !reload response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) if @attrs and @attrs['fields'] and @attrs['fields']['worklog'] and @attrs['fields']['worklog']['total'] > @attrs['fields']['worklog']['maxResults'] worklog_url = client.[:rest_base_path] + "/#{self.class.endpoint_name}/#{id}/worklog" response = client.get(worklog_url) unless response.body.nil? or response.body.length < 2 set_attrs({'fields' => { 'worklog' => self.class.parse_json(response.body) }}, false) end end @expanded = true end |
#respond_to?(method_name, include_all = false) ⇒ Boolean
99 100 101 102 103 104 105 |
# File 'lib/jira/resource/issue.rb', line 99 def respond_to?(method_name, include_all=false) if attrs.keys.include?('fields') && [method_name.to_s, client.Field.name_to_id(method_name)].any? {|k| attrs['fields'].key?(k)} true else super(method_name) end end |