pragma-operation 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a892b513da3edcb6fd3fbf84964cb4773671d4f5
|
4
|
+
data.tar.gz: 2dd06285a00dcb6ed694d8050efde1c346e985c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 545a8a3f2db0168d4bfa8b1ebfd14e212dc1f44de3408c2f65ca0320e8dff52cefa274abbd9e16701af7755c14b55983989759cc60ebf093e181fea83718824a
|
7
|
+
data.tar.gz: 0ca767a0c19c14961a2b78be730b39d568d777890156982e67bf98354d56a77541e045145766798343e38358074167f2d242d75dde56f5e87df4af4a621e0f1f
|
data/doc/01-basic-usage.md
CHANGED
@@ -9,7 +9,14 @@ module API
|
|
9
9
|
module Operation
|
10
10
|
class Create < Pragma::Operation::Base
|
11
11
|
def call
|
12
|
-
|
12
|
+
# The `status` parameter is optional (the default is `:ok`).
|
13
|
+
respond_with(
|
14
|
+
status: :ok,
|
15
|
+
resource: { pong: params[:pong] },
|
16
|
+
headers: {
|
17
|
+
'X-Ping-Time' => Time.now.to_i
|
18
|
+
}
|
19
|
+
)
|
13
20
|
end
|
14
21
|
end
|
15
22
|
end
|
@@ -25,6 +32,7 @@ result = API::V1::Ping::Operation::Create.call(params: { pong: 'HELLO' })
|
|
25
32
|
|
26
33
|
result.status # => :ok
|
27
34
|
result.resource # => { pong: 'HELLO' }
|
35
|
+
result.headers # => { 'X-Ping-Time' => 1482927872 }
|
28
36
|
```
|
29
37
|
|
30
38
|
As you can see, an operation takes parameters as input and responds with:
|
@@ -114,27 +114,26 @@ module Pragma
|
|
114
114
|
|
115
115
|
# Sets the status and resource to respond with.
|
116
116
|
#
|
117
|
-
# You can achieve the same result by setting +context.status
|
118
|
-
# you want in {#call}.
|
117
|
+
# You can achieve the same result by setting +context.status+, +context.headers+ and
|
118
|
+
# +context.resource+ wherever you want in {#call}.
|
119
119
|
#
|
120
120
|
# Note that calling this method doesn't halt the execution of the operation and that this
|
121
121
|
# method can be called multiple times, overriding the previous context.
|
122
122
|
#
|
123
123
|
# @param status [Integer|Symbol] an HTTP status code
|
124
|
+
# @param headers [Hash] HTTP headers
|
124
125
|
# @param resource [Object] an object responding to +#to_json+
|
125
|
-
def respond_with(status
|
126
|
+
def respond_with(status: :ok, headers: {}, resource:)
|
126
127
|
context.status = status
|
128
|
+
context.headers = headers.to_h
|
127
129
|
context.resource = resource
|
128
130
|
end
|
129
131
|
|
130
132
|
# Same as {#respond_with}, but also halts the execution of the operation.
|
131
133
|
#
|
132
|
-
# @param status [Integer|Symbol] an HTTP status code
|
133
|
-
# @param resource [Object] an object responding to +#to_json+
|
134
|
-
#
|
135
134
|
# @see #respond_with
|
136
|
-
def respond_with!(
|
137
|
-
respond_with
|
135
|
+
def respond_with!(*args)
|
136
|
+
respond_with *args
|
138
137
|
fail Halt
|
139
138
|
end
|
140
139
|
|
@@ -187,6 +186,7 @@ module Pragma
|
|
187
186
|
|
188
187
|
def setup_context
|
189
188
|
context.params ||= {}
|
189
|
+
context.headers = {}
|
190
190
|
end
|
191
191
|
|
192
192
|
def handle_halt(interactor)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragma-operation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: interactor
|