Class: Jiralicious::Base
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#parse!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
100
101
102
103
104
105
106
107
108
|
# File 'lib/jiralicious/base.rb', line 100
def method_missing(meth, *args, &block)
if !loaded?
self.loaded = true
reload
self.send(meth, *args, &block)
else
super
end
end
|
Instance Attribute Details
#loaded ⇒ Object
Returns the value of attribute loaded.
8
9
10
|
# File 'lib/jiralicious/base.rb', line 8
def loaded
@loaded
end
|
Class Method Details
.endpoint_name ⇒ Object
37
38
39
|
# File 'lib/jiralicious/base.rb', line 37
def endpoint_name
self.name.split('::').last.downcase
end
|
.fetch(options = {}) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/jiralicious/base.rb', line 46
def fetch(options = {})
options[:method] = :get unless [:get, :post, :put, :delete].include?(options[:method])
options[:parent_uri] = "#{parent_name}/#{options[:parent_key]}/" unless options[:parent].nil?
if !options[:body_override]
options[:body_uri] = (options[:body].is_a? Hash) ? options[:body] : {:body => options[:body]}
else
options[:body_uri] = options[:body]
end
if options[:body_to_params]
options[:params_uri] = "?#{options[:body].to_params}" unless options[:body].nil? || options[:body].empty?
options[:body_uri] = nil
end
options[:url_uri] = options[:url].nil? ? "#{Jiralicious.rest_path}/#{options[:parent_uri]}#{endpoint_name}/#{options[:key]}#{options[:params_uri]}" : options[:url]
Jiralicious.session.request(options[:method], options[:url_uri], :handler => handler, :body => options[:body_uri].to_json)
end
|
.find(key, options = {}) ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/jiralicious/base.rb', line 23
def find(key, options = {})
response = fetch({:key => key})
if options[:reload] == true
response
else
new(response.parsed_response)
end
end
|
.find_all ⇒ Object
Also known as:
all
32
33
34
35
|
# File 'lib/jiralicious/base.rb', line 32
def find_all
response = fetch()
new(response)
end
|
.handler ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/jiralicious/base.rb', line 62
def handler
Proc.new do |response|
case response.code
when 200..204
response
when 400
raise Jiralicious::TransitionError.new(response['errorMessages'].join('\n'))
when 404
raise Jiralicious::IssueNotFound.new(response['errorMessages'].join('\n'))
else
raise Jiralicious::JiraError.new(response['errorMessages'].join('\n'))
end
end
end
|
.parent_name ⇒ Object
41
42
43
44
|
# File 'lib/jiralicious/base.rb', line 41
def parent_name
arr = self.name.split('::')
arr[arr.length-2].downcase
end
|
Instance Method Details
#all ⇒ Object
89
90
91
|
# File 'lib/jiralicious/base.rb', line 89
def all
self.class.all
end
|
#endpoint_name ⇒ Object
81
82
83
|
# File 'lib/jiralicious/base.rb', line 81
def endpoint_name
self.class.endpoint_name
end
|
#loaded? ⇒ Boolean
93
94
95
|
# File 'lib/jiralicious/base.rb', line 93
def loaded?
self.loaded
end
|
#numeric?(object) ⇒ Boolean
110
111
112
|
# File 'lib/jiralicious/base.rb', line 110
def numeric?(object)
true if Float(object) rescue false
end
|
#parent_name ⇒ Object
85
86
87
|
# File 'lib/jiralicious/base.rb', line 85
def parent_name
self.class.parent_name
end
|
#properties_from_hash(hash) ⇒ Object
Trash Extention Methods ###
11
12
13
14
15
16
17
18
19
|
# File 'lib/jiralicious/base.rb', line 11
def properties_from_hash(hash)
hash.inject({}) do |newhash, (k, v)|
k = k.gsub("-", "_")
k = "_#{k.to_s}" if k =~ /^\d/
self.class.property :"#{k}"
newhash[k] = v
newhash
end
end
|
#reload ⇒ Object
97
98
|
# File 'lib/jiralicious/base.rb', line 97
def reload
end
|