Class: DroidServices::Response
- Inherits:
-
Object
- Object
- DroidServices::Response
show all
- Defined in:
- lib/droid_services/response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(resource_name, result) ⇒ Response
Returns a new instance of Response.
4
5
6
7
8
9
10
|
# File 'lib/droid_services/response.rb', line 4
def initialize(resource_name, result)
@resource_name = resource_name
@result = result
@message = nil
@errors = []
@assignments = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
42
43
44
45
|
# File 'lib/droid_services/response.rb', line 42
def method_missing(method, *args, &block)
super unless assignments.has_key?(method)
assignments[method]
end
|
Instance Attribute Details
#assignments ⇒ Object
Returns the value of attribute assignments.
2
3
4
|
# File 'lib/droid_services/response.rb', line 2
def assignments
@assignments
end
|
#errors ⇒ Object
Returns the value of attribute errors.
2
3
4
|
# File 'lib/droid_services/response.rb', line 2
def errors
@errors
end
|
#message ⇒ Object
Returns the value of attribute message.
2
3
4
|
# File 'lib/droid_services/response.rb', line 2
def message
@message
end
|
#resource_name ⇒ Object
Returns the value of attribute resource_name.
2
3
4
|
# File 'lib/droid_services/response.rb', line 2
def resource_name
@resource_name
end
|
#result ⇒ Object
Returns the value of attribute result.
2
3
4
|
# File 'lib/droid_services/response.rb', line 2
def result
@result
end
|
Instance Method Details
#error ⇒ Object
34
35
36
|
# File 'lib/droid_services/response.rb', line 34
def error
message || errors.first if failure?
end
|
#failure? ⇒ Boolean
26
27
28
|
# File 'lib/droid_services/response.rb', line 26
def failure?
!success?
end
|
#has_error?(error) ⇒ Boolean
38
39
40
|
# File 'lib/droid_services/response.rb', line 38
def has_error?(error)
errors && errors.include?(error)
end
|
#notice ⇒ Object
30
31
32
|
# File 'lib/droid_services/response.rb', line 30
def notice
message if success?
end
|
#success? ⇒ Boolean
22
23
24
|
# File 'lib/droid_services/response.rb', line 22
def success?
@errors.nil? || @errors.empty?
end
|
#with_errors(errors) ⇒ Object
12
13
14
15
|
# File 'lib/droid_services/response.rb', line 12
def with_errors(errors)
@errors = errors
self
end
|
#with_message(message) ⇒ Object
17
18
19
20
|
# File 'lib/droid_services/response.rb', line 17
def with_message(message)
@message = message
self
end
|