functions_framework 0.3.0 → 0.3.1

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
  SHA256:
3
- metadata.gz: f82e8f7fb76005b4b61225b3ca02e31e52caecb2742604b88b6b60ced2945d84
4
- data.tar.gz: 5f274cc6bdd13c7367d55212d1fb39f26432d8d00a6d607c09543e3818637c49
3
+ metadata.gz: d09fadc9facfc650793e4c6c30f8dab5f2e5909d0d068d18e0da0bd8a748115d
4
+ data.tar.gz: 7b99ab480e94f1ed4eae784121030a07106451cdc1ddd0de5e5b1d7edabbe41f
5
5
  SHA512:
6
- metadata.gz: 6470be9c192f2231a610830bf51563638ce27e4330f071dd28b41a8fc15811704ace7025cede45ea54a13b4862d86153401360523d6bb479735793e1ed1e00c4
7
- data.tar.gz: c7fd524f8c7c4819a6cb6a95d7e7ec0aa371e4211c8b521efe42d63ab3ca794dbfad490613633660c89aaa01479cbfe4d5e98683454e6bd4cdc382f1978da396
6
+ metadata.gz: b4cc30e0acb40f3de6e9a412b240c2f910a539d9b9e76085bcb701d605f657b5239b4bbeabf9a7f5e78c220ff4931ae34c7f21d028d4e472874308c91d26d997
7
+ data.tar.gz: d059a1fc586dfb12bbd06a757abf46227f0dcfc54c8653365198b596045a0c34d3fd4d00fcddc331a19d5bb028f5e52f5684aa022136b1258ce59a31ec195bd2
@@ -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
@@ -88,7 +88,7 @@ bundle exec functions-framework-ruby --target hello
88
88
  In a separate shell, you can send requests to this function using curl:
89
89
 
90
90
  ```sh
91
- curl https://localhost:8080
91
+ curl http://localhost:8080
92
92
  # Output: Hello, world!
93
93
  ```
94
94
 
@@ -92,7 +92,7 @@ bundle exec functions-framework-ruby --target hello
92
92
  In a separate shell, you can send requests to this function using curl:
93
93
 
94
94
  ```sh
95
- curl https://localhost:8080
95
+ curl http://localhost:8080
96
96
  # Output: Hello, world!
97
97
  ```
98
98
 
@@ -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 methods for obtaining request information such as the method,
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
- @block = block
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
- block.call argument.data, argument
65
+ execution_context.call argument.data, argument
68
66
  else
69
- block.call argument
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
- env = Testing.build_standard_env URI(url), headers
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 data [String] The body to post.
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, data, headers = []
139
- env = Testing.build_standard_env URI(url), headers
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
- name, value = header.split ":"
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
@@ -17,5 +17,5 @@ module FunctionsFramework
17
17
  # Version of the Ruby Functions Framework
18
18
  # @return [String]
19
19
  #
20
- VERSION = "0.3.0".freeze
20
+ VERSION = "0.3.1".freeze
21
21
  end
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.0
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-25 00:00:00.000000000 Z
11
+ date: 2020-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puma