functions_framework 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/docs/overview.md +1 -1
- data/docs/writing-functions.md +1 -1
- data/lib/functions_framework/function.rb +6 -8
- data/lib/functions_framework/testing.rb +36 -10
- data/lib/functions_framework/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d09fadc9facfc650793e4c6c30f8dab5f2e5909d0d068d18e0da0bd8a748115d
|
4
|
+
data.tar.gz: 7b99ab480e94f1ed4eae784121030a07106451cdc1ddd0de5e5b1d7edabbe41f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4cc30e0acb40f3de6e9a412b240c2f910a539d9b9e76085bcb701d605f657b5239b4bbeabf9a7f5e78c220ff4931ae34c7f21d028d4e472874308c91d26d997
|
7
|
+
data.tar.gz: d059a1fc586dfb12bbd06a757abf46227f0dcfc54c8653365198b596045a0c34d3fd4d00fcddc331a19d5bb028f5e52f5684aa022136b1258ce59a31ec195bd2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
### v0.3.1 / 2020-06-27
|
4
|
+
|
5
|
+
* Fixed crash when using "return" directly in a function block.
|
6
|
+
* Added a more flexible request generation helper in the testing module.
|
7
|
+
* Fixed several typos in the documentation.
|
8
|
+
|
3
9
|
### v0.3.0 / 2020-06-26
|
4
10
|
|
5
11
|
* Updated the CloudEvent data format for converted pubsub events to conform to Cloud Run's conversion.
|
data/README.md
CHANGED
data/docs/overview.md
CHANGED
data/docs/writing-functions.md
CHANGED
@@ -43,7 +43,7 @@ now cover these in a bit more detail.
|
|
43
43
|
|
44
44
|
An HTTP function is passed a request, which is an object of type
|
45
45
|
[Rack::Request](https://rubydoc.info/gems/rack/Rack/Request). This object
|
46
|
-
provides methods
|
46
|
+
provides methods for obtaining request information such as the method,
|
47
47
|
path, query parameters, body content, and headers. You can also obtain the raw
|
48
48
|
Rack environment using the `env` method. The following example includes some
|
49
49
|
request information in the response:
|
@@ -30,7 +30,9 @@ module FunctionsFramework
|
|
30
30
|
def initialize name, type, &block
|
31
31
|
@name = name
|
32
32
|
@type = type
|
33
|
-
@
|
33
|
+
@execution_context_class = Class.new do
|
34
|
+
define_method :call, &block
|
35
|
+
end
|
34
36
|
end
|
35
37
|
|
36
38
|
##
|
@@ -43,11 +45,6 @@ module FunctionsFramework
|
|
43
45
|
#
|
44
46
|
attr_reader :type
|
45
47
|
|
46
|
-
##
|
47
|
-
# @return [Proc] The function code as a proc
|
48
|
-
#
|
49
|
-
attr_reader :block
|
50
|
-
|
51
48
|
##
|
52
49
|
# Call the function. You must pass an argument appropriate to the type
|
53
50
|
# of function.
|
@@ -62,11 +59,12 @@ module FunctionsFramework
|
|
62
59
|
# @return [Object]
|
63
60
|
#
|
64
61
|
def call argument
|
62
|
+
execution_context = @execution_context_class.new
|
65
63
|
case type
|
66
64
|
when :event
|
67
|
-
|
65
|
+
execution_context.call argument.data, argument
|
68
66
|
else
|
69
|
-
|
67
|
+
execution_context.call argument
|
70
68
|
end
|
71
69
|
end
|
72
70
|
end
|
@@ -116,30 +116,52 @@ module FunctionsFramework
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
##
|
120
|
+
# Make a Rack request, for passing to a function test.
|
121
|
+
#
|
122
|
+
# @param url [URI,String] The URL to get, including query params.
|
123
|
+
# @param method [String] The HTTP method (defaults to "GET").
|
124
|
+
# @param body [String] The HTTP body, if any.
|
125
|
+
# @param headers [Array,Hash] HTTP headers. May be given as a hash (of
|
126
|
+
# header names mapped to values), an array of strings (where each
|
127
|
+
# string is of the form `Header-Name: Header value`), or an array of
|
128
|
+
# two-element string arrays.
|
129
|
+
# @return [Rack::Request]
|
130
|
+
#
|
131
|
+
def make_request url, method: ::Rack::GET, body: nil, headers: []
|
132
|
+
env = Testing.build_standard_env URI(url), headers
|
133
|
+
env[::Rack::REQUEST_METHOD] = method
|
134
|
+
env[::Rack::RACK_INPUT] = ::StringIO.new body if body
|
135
|
+
::Rack::Request.new env
|
136
|
+
end
|
137
|
+
|
119
138
|
##
|
120
139
|
# Make a simple GET request, for passing to a function test.
|
121
140
|
#
|
122
141
|
# @param url [URI,String] The URL to get.
|
142
|
+
# @param headers [Array,Hash] HTTP headers. May be given as a hash (of
|
143
|
+
# header names mapped to values), an array of strings (where each
|
144
|
+
# string is of the form `Header-Name: Header value`), or an array of
|
145
|
+
# two-element string arrays.
|
123
146
|
# @return [Rack::Request]
|
124
147
|
#
|
125
148
|
def make_get_request url, headers = []
|
126
|
-
|
127
|
-
env[::Rack::REQUEST_METHOD] = ::Rack::GET
|
128
|
-
::Rack::Request.new env
|
149
|
+
make_request url, headers: headers
|
129
150
|
end
|
130
151
|
|
131
152
|
##
|
132
153
|
# Make a simple POST request, for passing to a function test.
|
133
154
|
#
|
134
155
|
# @param url [URI,String] The URL to post to.
|
135
|
-
# @param
|
156
|
+
# @param body [String] The body to post.
|
157
|
+
# @param headers [Array,Hash] HTTP headers. May be given as a hash (of
|
158
|
+
# header names mapped to values), an array of strings (where each
|
159
|
+
# string is of the form `Header-Name: Header value`), or an array of
|
160
|
+
# two-element string arrays.
|
136
161
|
# @return [Rack::Request]
|
137
162
|
#
|
138
|
-
def make_post_request url,
|
139
|
-
|
140
|
-
env[::Rack::REQUEST_METHOD] = ::Rack::POST
|
141
|
-
env[::Rack::RACK_INPUT] = ::StringIO.new data
|
142
|
-
::Rack::Request.new env
|
163
|
+
def make_post_request url, body, headers = []
|
164
|
+
make_request url, method: ::Rack::POST, body: body, headers: headers
|
143
165
|
end
|
144
166
|
|
145
167
|
##
|
@@ -245,7 +267,11 @@ module FunctionsFramework
|
|
245
267
|
::Rack::RACK_ERRORS => ::StringIO.new
|
246
268
|
}
|
247
269
|
headers.each do |header|
|
248
|
-
|
270
|
+
if header.is_a? String
|
271
|
+
name, value = header.split ":"
|
272
|
+
elsif header.is_a? Array
|
273
|
+
name, value = header
|
274
|
+
end
|
249
275
|
next unless name && value
|
250
276
|
name = name.strip.upcase.tr "-", "_"
|
251
277
|
name = "HTTP_#{name}" unless ["CONTENT_TYPE", "CONTENT_LENGTH"].include? name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: functions_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Azuma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puma
|