faastruby 0.4.12 → 0.4.14

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.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +15 -4
  4. data/Gemfile.lock +2 -2
  5. data/README.md +2 -0
  6. data/exe/faastruby-server +4 -2
  7. data/lib/faastruby/cli/commands/function/build.rb +20 -1
  8. data/lib/faastruby/cli/commands/function/deploy_to.rb +20 -1
  9. data/lib/faastruby/cli/commands/function/new.rb +6 -4
  10. data/lib/faastruby/cli/commands/function/update_context.rb +2 -2
  11. data/lib/faastruby/server.rb +10 -233
  12. data/lib/faastruby/server/concurrency_controller.rb +51 -0
  13. data/lib/faastruby/server/errors.rb +3 -0
  14. data/lib/faastruby/server/event.rb +19 -0
  15. data/lib/faastruby/server/event_channel.rb +19 -0
  16. data/lib/faastruby/server/event_hub.rb +50 -0
  17. data/lib/faastruby/server/function_object.rb +9 -0
  18. data/lib/faastruby/server/response.rb +25 -0
  19. data/lib/faastruby/server/runner.rb +43 -0
  20. data/lib/faastruby/server/runner_methods.rb +106 -0
  21. data/lib/faastruby/server/subscriber.rb +16 -0
  22. data/lib/faastruby/spec_helper.rb +36 -0
  23. data/lib/faastruby/version.rb +1 -1
  24. data/templates/crystal/example-blank/spec/spec_helper.cr +1 -1
  25. data/templates/crystal/example/spec/spec_helper.cr +1 -1
  26. data/templates/ruby/example-blank/Gemfile +1 -0
  27. data/templates/ruby/example-blank/spec/handler_spec.rb +6 -1
  28. data/templates/ruby/example-blank/spec/spec_helper.rb +2 -2
  29. data/templates/ruby/example/Gemfile +1 -0
  30. data/templates/ruby/example/spec/handler_spec.rb +8 -3
  31. data/templates/ruby/example/spec/spec_helper.rb +2 -2
  32. metadata +13 -6
  33. data/templates/crystal/example-blank/spec/helpers/faastruby.cr +0 -77
  34. data/templates/crystal/example/spec/helpers/faastruby.cr +0 -77
  35. data/templates/ruby/example-blank/spec/helpers/faastruby.rb +0 -66
  36. data/templates/ruby/example/spec/helpers/faastruby.rb +0 -65
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  group :test do
4
4
  gem 'rspec'
5
5
  gem 'faastruby-rpc'
6
+ gem 'faastruby'
6
7
  end
@@ -2,14 +2,19 @@ require 'spec_helper'
2
2
  require 'handler'
3
3
 
4
4
  describe 'handler(event)' do
5
- let(:event) {SpecHelper::Event.new}
5
+ let(:event) {Event.new(
6
+ body: nil,
7
+ query_params: {},
8
+ headers: {},
9
+ context: nil
10
+ )}
6
11
 
7
12
  it 'should return a String' do
8
- body = handler(event).call.body
13
+ body = handler(event).body
9
14
  expect(body).to be_a(String)
10
15
  end
11
16
  it 'should reply Hello, World!' do
12
- body = handler(event).call.body
17
+ body = handler(event).body
13
18
  expect(body).to be == "Hello, World!\n"
14
19
  end
15
20
  end
@@ -1,3 +1,3 @@
1
1
  require 'faastruby-rpc/test_helper'
2
- require 'helpers/faastruby'
3
- include FaaStRuby
2
+ require 'faastruby/spec_helper'
3
+ include FaaStRuby::SpecHelper
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faastruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.12
4
+ version: 0.4.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-26 00:00:00.000000000 Z
11
+ date: 2019-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -257,25 +257,32 @@ files:
257
257
  - lib/faastruby/cli/package.rb
258
258
  - lib/faastruby/function.rb
259
259
  - lib/faastruby/server.rb
260
+ - lib/faastruby/server/concurrency_controller.rb
261
+ - lib/faastruby/server/errors.rb
262
+ - lib/faastruby/server/event.rb
263
+ - lib/faastruby/server/event_channel.rb
264
+ - lib/faastruby/server/event_hub.rb
265
+ - lib/faastruby/server/function_object.rb
266
+ - lib/faastruby/server/response.rb
267
+ - lib/faastruby/server/runner.rb
268
+ - lib/faastruby/server/runner_methods.rb
269
+ - lib/faastruby/server/subscriber.rb
270
+ - lib/faastruby/spec_helper.rb
260
271
  - lib/faastruby/version.rb
261
272
  - lib/faastruby/workspace.rb
262
273
  - templates/crystal/example-blank/spec/handler_spec.cr
263
- - templates/crystal/example-blank/spec/helpers/faastruby.cr
264
274
  - templates/crystal/example-blank/spec/spec_helper.cr
265
275
  - templates/crystal/example-blank/src/handler.cr
266
276
  - templates/crystal/example/spec/handler_spec.cr
267
- - templates/crystal/example/spec/helpers/faastruby.cr
268
277
  - templates/crystal/example/spec/spec_helper.cr
269
278
  - templates/crystal/example/src/handler.cr
270
279
  - templates/ruby/example-blank/Gemfile
271
280
  - templates/ruby/example-blank/handler.rb
272
281
  - templates/ruby/example-blank/spec/handler_spec.rb
273
- - templates/ruby/example-blank/spec/helpers/faastruby.rb
274
282
  - templates/ruby/example-blank/spec/spec_helper.rb
275
283
  - templates/ruby/example/Gemfile
276
284
  - templates/ruby/example/handler.rb
277
285
  - templates/ruby/example/spec/handler_spec.rb
278
- - templates/ruby/example/spec/helpers/faastruby.rb
279
286
  - templates/ruby/example/spec/spec_helper.rb
280
287
  homepage: https://faastruby.io
281
288
  licenses:
@@ -1,77 +0,0 @@
1
- require "yaml"
2
- require "json"
3
- require "base64"
4
-
5
- module FaaStRuby
6
- class Event
7
- JSON.mapping(
8
- body: String?,
9
- headers: Hash(String, String),
10
- context: String?,
11
- query_params: Hash(String, String)
12
- )
13
- end
14
- class Response
15
- @@rendered = false
16
- property "body"
17
- property "status"
18
- property "headers"
19
- property "io"
20
- def initialize(@body : String?, @status : Int32, @headers : Hash(String, String))
21
- @io = nil
22
- end
23
-
24
- def initialize(@io : Bytes, @status : Int32, @headers : Hash(String, String))
25
- end
26
-
27
- def payload
28
- if io
29
- hash = {
30
- "response" => Base64.encode(io.not_nil!),
31
- "status" => status,
32
- "headers" => headers
33
- }
34
- else
35
- hash = {
36
- "response" => body,
37
- "status" => status,
38
- "headers" => headers
39
- }
40
- end
41
- hash
42
- end
43
- end
44
-
45
- def respond_with(body : String? = nil, status : Int32 = 200, headers : Hash(String, String) = {} of String => String)
46
- Response.new(body: body, status: status, headers: headers)
47
- end
48
-
49
- def respond_with(io : Bytes, status : Int32 = 200, headers : Hash(String, String) = {} of String => String)
50
- Response.new(io: io, status: status, headers: headers)
51
- end
52
-
53
- def render(io : Bytes? = nil, js : String? = nil, inline : String? = nil, html : String? = nil, json : String? = nil, yaml : String? = nil, text : String? = nil, status : Int32 = 200, headers : Hash(String, String) = {} of String => String, content_type : String? = nil)
54
- headers["Content-Type"] = content_type if content_type
55
- case
56
- when json
57
- headers["Content-Type"] ||= "application/json"
58
- resp_body = json
59
- when html, inline
60
- headers["Content-Type"] ||= "text/html"
61
- resp_body = html
62
- when text
63
- headers["Content-Type"] ||= "text/plain"
64
- resp_body = text
65
- when yaml
66
- headers["Content-Type"] ||= "text/yaml"
67
- resp_body = yaml
68
- when js
69
- headers["Content-Type"] ||= "text/javascript"
70
- resp_body = js
71
- when io
72
- headers["Content-Type"] ||= "application/octet-stream"
73
- return respond_with(io: io, status: status, headers: headers)
74
- end
75
- respond_with(body: resp_body, status: status, headers: headers)
76
- end
77
- end
@@ -1,77 +0,0 @@
1
- require "yaml"
2
- require "json"
3
- require "base64"
4
-
5
- module FaaStRuby
6
- class Event
7
- JSON.mapping(
8
- body: String?,
9
- headers: Hash(String, String),
10
- context: String?,
11
- query_params: Hash(String, String)
12
- )
13
- end
14
- class Response
15
- @@rendered = false
16
- property "body"
17
- property "status"
18
- property "headers"
19
- property "io"
20
- def initialize(@body : String?, @status : Int32, @headers : Hash(String, String))
21
- @io = nil
22
- end
23
-
24
- def initialize(@io : Bytes, @status : Int32, @headers : Hash(String, String))
25
- end
26
-
27
- def payload
28
- if io
29
- hash = {
30
- "response" => Base64.encode(io.not_nil!),
31
- "status" => status,
32
- "headers" => headers
33
- }
34
- else
35
- hash = {
36
- "response" => body,
37
- "status" => status,
38
- "headers" => headers
39
- }
40
- end
41
- hash
42
- end
43
- end
44
-
45
- def respond_with(body : String? = nil, status : Int32 = 200, headers : Hash(String, String) = {} of String => String)
46
- Response.new(body: body, status: status, headers: headers)
47
- end
48
-
49
- def respond_with(io : Bytes, status : Int32 = 200, headers : Hash(String, String) = {} of String => String)
50
- Response.new(io: io, status: status, headers: headers)
51
- end
52
-
53
- def render(io : Bytes? = nil, js : String? = nil, inline : String? = nil, html : String? = nil, json : String? = nil, yaml : String? = nil, text : String? = nil, status : Int32 = 200, headers : Hash(String, String) = {} of String => String, content_type : String? = nil)
54
- headers["Content-Type"] = content_type if content_type
55
- case
56
- when json
57
- headers["Content-Type"] ||= "application/json"
58
- resp_body = json
59
- when html, inline
60
- headers["Content-Type"] ||= "text/html"
61
- resp_body = html
62
- when text
63
- headers["Content-Type"] ||= "text/plain"
64
- resp_body = text
65
- when yaml
66
- headers["Content-Type"] ||= "text/yaml"
67
- resp_body = yaml
68
- when js
69
- headers["Content-Type"] ||= "text/javascript"
70
- resp_body = js
71
- when io
72
- headers["Content-Type"] ||= "application/octet-stream"
73
- return respond_with(io: io, status: status, headers: headers)
74
- end
75
- respond_with(body: resp_body, status: status, headers: headers)
76
- end
77
- end
@@ -1,66 +0,0 @@
1
- require 'yaml'
2
- require 'oj'
3
-
4
- module FaaStRuby
5
- def self.included(base)
6
- base.extend(SpecHelper)
7
- $LOAD_PATH << Dir.pwd
8
- end
9
- class DoubleRenderError < StandardError; end
10
- module SpecHelper
11
- class Event
12
- @@event = Struct.new(:body, :query_params, :headers, :context)
13
- def self.new(body: 'example body', query_params: {'foo' => 'bar'}, headers: {'Foo' => 'Bar'}, context: '{"foo": "bar"}')
14
- @@event.new(body, query_params, headers, context)
15
- end
16
- end
17
- class Response
18
- # @@response = Struct.new(:body, :status, :headers)
19
- attr_accessor :body, :status, :headers
20
- @@rendered = false
21
- def initialize(body, status, headers)
22
- if @@rendered
23
- raise FaaStRuby::DoubleRenderError.new("You called 'render' or 'respond_with' multiple times in your handler method.")
24
- end
25
- @@rendered = true
26
- @body = body
27
- @status = status
28
- @headers = headers
29
- end
30
-
31
- def call
32
- @@rendered = false
33
- self
34
- end
35
- end
36
- end
37
-
38
- def respond_with(body, status: 200, headers: {})
39
- SpecHelper::Response.new(body, status, headers)
40
- end
41
-
42
- def render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, status: 200, headers: {}, content_type: nil)
43
- headers["Content-Type"] = content_type if content_type
44
- case
45
- when json
46
- headers["Content-Type"] ||= "application/json"
47
- resp_body = json.is_a?(String) ? json : Oj.dump(json)
48
- when html, inline
49
- headers["Content-Type"] ||= "text/html"
50
- resp_body = html
51
- when text
52
- headers["Content-Type"] ||= "text/plain"
53
- resp_body = text
54
- when yaml
55
- headers["Content-Type"] ||= "application/yaml"
56
- resp_body = yaml.is_a?(String) ? yaml : yaml.to_yaml
57
- when body
58
- headers["Content-Type"] ||= "application/octet-stream"
59
- resp_body = raw
60
- when js
61
- headers["Content-Type"] ||= "text/javascript"
62
- resp_body = js
63
- end
64
- respond_with(resp_body, status: status, headers: headers)
65
- end
66
- end
@@ -1,65 +0,0 @@
1
- require 'yaml'
2
- require 'oj'
3
-
4
- module FaaStRuby
5
- def self.included(base)
6
- base.extend(SpecHelper)
7
- $LOAD_PATH << Dir.pwd
8
- end
9
- class DoubleRenderError < StandardError; end
10
- module SpecHelper
11
- class Event
12
- @@event = Struct.new(:body, :query_params, :headers, :context)
13
- def self.new(body: 'example body', query_params: {'foo' => 'bar'}, headers: {'Foo' => 'Bar'}, context: '{"foo": "bar"}')
14
- @@event.new(body, query_params, headers, context)
15
- end
16
- end
17
- class Response
18
- attr_accessor :body, :status, :headers
19
- @@rendered = false
20
- def initialize(body, status, headers)
21
- if @@rendered
22
- raise FaaStRuby::DoubleRenderError.new("You called 'render' or 'respond_with' multiple times in your handler method.")
23
- end
24
- @@rendered = true
25
- @body = body
26
- @status = status
27
- @headers = headers
28
- end
29
-
30
- def call
31
- @@rendered = false
32
- self
33
- end
34
- end
35
- end
36
-
37
- def respond_with(body, status: 200, headers: {})
38
- SpecHelper::Response.new(body, status, headers)
39
- end
40
-
41
- def render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, status: 200, headers: {}, content_type: nil)
42
- headers["Content-Type"] = content_type if content_type
43
- case
44
- when json
45
- headers["Content-Type"] ||= "application/json"
46
- resp_body = json.is_a?(String) ? json : Oj.dump(json)
47
- when html, inline
48
- headers["Content-Type"] ||= "text/html"
49
- resp_body = html
50
- when text
51
- headers["Content-Type"] ||= "text/plain"
52
- resp_body = text
53
- when yaml
54
- headers["Content-Type"] ||= "application/yaml"
55
- resp_body = yaml.is_a?(String) ? yaml : yaml.to_yaml
56
- when body
57
- headers["Content-Type"] ||= "application/octet-stream"
58
- resp_body = raw
59
- when js
60
- headers["Content-Type"] ||= "text/javascript"
61
- resp_body = js
62
- end
63
- respond_with(resp_body, status: status, headers: headers)
64
- end
65
- end