Class: RestPack::Service::Command
- Inherits:
-
Mutations::Command
- Object
- Mutations::Command
- RestPack::Service::Command
show all
- Defined in:
- lib/restpack_service/command.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
5
6
7
|
# File 'lib/restpack_service/command.rb', line 5
def response
@response
end
|
Class Method Details
.inherited(command) ⇒ Object
67
68
69
70
|
# File 'lib/restpack_service/command.rb', line 67
def self.inherited(command)
namespaces = command.to_s.split('::') add_module_aliases(command, namespaces)
end
|
Instance Method Details
#field_error(key, message) ⇒ Object
55
56
57
|
# File 'lib/restpack_service/command.rb', line 55
def field_error(key, message)
add_error key, key, message
end
|
#init ⇒ Object
40
41
|
# File 'lib/restpack_service/command.rb', line 40
def init
end
|
#Model ⇒ Object
63
64
65
|
# File 'lib/restpack_service/command.rb', line 63
def Model
self.class.model_class
end
|
#run ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/restpack_service/command.rb', line 7
def run
@response = RestPack::Service::Response.new
begin
init
mutation = super
if mutation.errors
mutation.errors.message.each do |error|
@response.add_error(error[0], error[1].gsub(error[0].capitalize, ''))
end
@response.status ||= :unprocessable_entity
else
@response.status ||= :ok
end
if @response.status == :ok
@response.result = mutation.result if mutation.result
end
rescue Exception => e
puts "---COMMAND EXCEPTION---"
puts e.message puts e.backtrace
puts "-----------------------"
@response.add_error(:base, 'Service Error')
@response.status = :internal_service_error
end
@response
end
|
#Serializer ⇒ Object
59
60
61
|
# File 'lib/restpack_service/command.rb', line 59
def Serializer
self.class.serializer_class
end
|
#service_error(message) ⇒ Object
51
52
53
|
# File 'lib/restpack_service/command.rb', line 51
def service_error(message)
field_error :base, message
end
|
#status(status) ⇒ Object
43
44
45
|
# File 'lib/restpack_service/command.rb', line 43
def status(status)
@response.status = status
end
|
#valid? ⇒ Boolean
47
48
49
|
# File 'lib/restpack_service/command.rb', line 47
def valid?
!has_errors?
end
|