jets 2.1.1 → 2.1.2

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 (54) hide show
  1. checksums.yaml +4 -4
  2. data/.codebuild/README.md +10 -60
  3. data/.codebuild/docs/bin/build.sh +6 -0
  4. data/.codebuild/docs/bin/cli_docs.sh +5 -0
  5. data/.codebuild/docs/bin/git_commit.sh +27 -0
  6. data/.codebuild/docs/bin/git_setup.sh +19 -0
  7. data/.codebuild/docs/bin/subnav.sh +14 -0
  8. data/.codebuild/docs/buildspec.yml +8 -0
  9. data/.codebuild/docs/project.rb +10 -0
  10. data/.gitignore +5 -5
  11. data/CHANGELOG.md +8 -0
  12. data/jets.gemspec +5 -5
  13. data/lib/jets/aws_services/stack_status.rb +5 -1
  14. data/lib/jets/cfn/builders/api_gateway_builder.rb +10 -19
  15. data/lib/jets/cfn/builders/api_resources_builder.rb +46 -0
  16. data/lib/jets/cfn/builders/parent_builder.rb +15 -0
  17. data/lib/jets/cfn/built_template.rb +15 -0
  18. data/lib/jets/commands/clean/log.rb +18 -1
  19. data/lib/jets/commands/delete.rb +14 -1
  20. data/lib/jets/commands/deploy.rb +43 -12
  21. data/lib/jets/commands/help/build.md +1 -1
  22. data/lib/jets/commands/help/{destroy.md → degenerate.md} +1 -1
  23. data/lib/jets/commands/help/upgrade.md +2 -0
  24. data/lib/jets/commands/main.rb +2 -1
  25. data/lib/jets/commands/templates/skeleton/Gemfile.tt +1 -0
  26. data/lib/jets/naming.rb +4 -0
  27. data/lib/jets/resource/api_gateway/resource.rb +7 -3
  28. data/lib/jets/resource/api_gateway/rest_api/change_detection.rb +0 -32
  29. data/lib/jets/resource/api_gateway/rest_api/routes/change.rb +9 -1
  30. data/lib/jets/resource/api_gateway/rest_api/routes/change/base.rb +26 -5
  31. data/lib/jets/resource/api_gateway/rest_api/routes/change/media_types.rb +36 -0
  32. data/lib/jets/resource/api_gateway/rest_api/routes/change/page.rb +93 -0
  33. data/lib/jets/resource/api_gateway/rest_api/routes/change/to.rb +0 -4
  34. data/lib/jets/resource/api_gateway/rest_api/routes/change/variable.rb +0 -4
  35. data/lib/jets/resource/child_stack/api_resource.rb +60 -0
  36. data/lib/jets/resource/child_stack/api_resource/page.rb +20 -0
  37. data/lib/jets/resource/child_stack/app_class.rb +14 -3
  38. data/lib/jets/router.rb +57 -40
  39. data/lib/jets/router/method_creator/code.rb +3 -1
  40. data/lib/jets/router/method_creator/edit.rb +6 -1
  41. data/lib/jets/router/method_creator/index.rb +9 -3
  42. data/lib/jets/router/method_creator/new.rb +6 -1
  43. data/lib/jets/router/method_creator/show.rb +6 -1
  44. data/lib/jets/router/route.rb +1 -0
  45. data/lib/jets/version.rb +1 -1
  46. metadata +22 -17
  47. data/.codebuild/bin/jets +0 -3
  48. data/.codebuild/buildspec-base.yml +0 -14
  49. data/.codebuild/integration.sh +0 -72
  50. data/.codebuild/jets.postman_collection.json +0 -323
  51. data/.codebuild/scripts/install-docker.sh +0 -12
  52. data/.codebuild/scripts/install-dynamodb-local.sh +0 -22
  53. data/.codebuild/scripts/install-java.sh +0 -22
  54. data/.codebuild/scripts/install-node.sh +0 -4
@@ -1,10 +1,6 @@
1
1
  # Detects route to changes
2
2
  class Jets::Resource::ApiGateway::RestApi::Routes::Change
3
3
  class To < Base
4
- def self.changed?
5
- new.changed?
6
- end
7
-
8
4
  def changed?
9
5
  deployed_routes.each do |deployed_route|
10
6
  new_route = find_comparable_route(deployed_route)
@@ -1,10 +1,6 @@
1
1
  # Detects route variable changes
2
2
  class Jets::Resource::ApiGateway::RestApi::Routes::Change
3
3
  class Variable < Base
4
- def self.changed?
5
- new.changed?
6
- end
7
-
8
4
  def changed?
9
5
  changed = false
10
6
  deployed_routes.each do |deployed_route|
@@ -0,0 +1,60 @@
1
+ # Implements:
2
+ #
3
+ # definition
4
+ # template_filename
5
+ #
6
+ module Jets::Resource::ChildStack
7
+ class ApiResource < Base
8
+ def initialize(*)
9
+ super
10
+ @page = @options[:page]
11
+ end
12
+
13
+ def definition
14
+ {
15
+ "api_resources_#{@page}" => {
16
+ type: "AWS::CloudFormation::Stack",
17
+ # depends_on: "ApiGateway", # CloudFormation seems to be smart enough
18
+ properties: {
19
+ template_url: template_url,
20
+ parameters: parameters,
21
+ }
22
+ }
23
+ }
24
+ end
25
+
26
+ def parameters
27
+ params = {}
28
+ # Since dont have all the info required.
29
+ # Read the template back to find the parameters required.
30
+ # Actually might be easier to rationalize this approach.
31
+ template_path = Jets::Naming.api_resources_template_path(@page)
32
+ template = Jets::Cfn::BuiltTemplate.get(template_path)
33
+ template['Parameters'].keys.each do |p|
34
+ case p
35
+ when "RestApi"
36
+ params[p] = "!GetAtt ApiGateway.Outputs.RestApi"
37
+ when "RootResourceId"
38
+ params[p] = "!GetAtt ApiGateway.Outputs.RootResourceId"
39
+ else
40
+ params[p] = "!GetAtt #{api_resource_page(p)}.Outputs.#{p}"
41
+ end
42
+ end
43
+ params
44
+ end
45
+
46
+ def api_resource_page(parameter)
47
+ Page.logical_id(parameter)
48
+ end
49
+
50
+ def outputs
51
+ {
52
+ logical_id => "!Ref #{logical_id}",
53
+ }
54
+ end
55
+
56
+ def template_filename
57
+ "#{Jets.config.project_namespace}-api-resources-#{@page}.yml"
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,20 @@
1
+ class Jets::Resource::ChildStack::ApiResource
2
+ # Find the ApiResource Page that contains the AWS::ApiGateway::Resource
3
+ # Returns: logical id of ApiResource Page
4
+ class Page
5
+ def self.logical_id(parameter)
6
+ expression = "#{Jets::Naming.template_path_prefix}-api-resources-*"
7
+ # IE: path: #{Jets.build_root}/templates/demo-dev-2-api-resources-1.yml"
8
+ template_paths = Dir.glob(expression).sort.to_a
9
+ found_template = template_paths.detect do |path|
10
+ next unless File.file?(path)
11
+
12
+ template = Jets::Cfn::BuiltTemplate.get(path)
13
+ template['Outputs'].keys.include?(parameter)
14
+ end
15
+ md = found_template.match(/-(api-resources-\d+)/)
16
+
17
+ md[1].underscore.camelize # IE: ApiResources1
18
+ end
19
+ end
20
+ end
@@ -62,13 +62,24 @@ module Jets::Resource::ChildStack
62
62
  params = {
63
63
  RestApi: "!GetAtt ApiGateway.Outputs.RestApi",
64
64
  }
65
- scoped_routes.each do |route|
66
- resource = Jets::Resource::ApiGateway::Resource.new(route.path)
67
- params[resource.logical_id] = "!GetAtt ApiGateway.Outputs.#{resource.logical_id}"
65
+
66
+ template_path = @path
67
+ template = Jets::Cfn::BuiltTemplate.get(template_path)
68
+ template['Parameters'].keys.each do |p|
69
+ case p
70
+ when /Resource$/ # AWS::ApiGateway::Resource in api-resources templates. IE: demo-dev-api-resources-2.yml
71
+ params[p] = "!GetAtt #{api_resource_page(p)}.Outputs.#{p}"
72
+ when 'RootResourceId'
73
+ params[p] = "!GetAtt ApiGateway.Outputs.RootResourceId"
74
+ end
68
75
  end
69
76
  params
70
77
  end
71
78
 
79
+ def api_resource_page(parameter)
80
+ ApiResource::Page.logical_id(parameter)
81
+ end
82
+
72
83
  def controller?
73
84
  @path.include?('_controller.yml')
74
85
  end
data/lib/jets/router.rb CHANGED
@@ -107,57 +107,74 @@ module Jets
107
107
  simple_routes + capture_routes + wildcard_routes
108
108
  end
109
109
 
110
- def self.has_controller?(name)
111
- routes.detect { |r| r.controller_name == name }
112
- end
110
+ class << self
111
+ def has_controller?(name)
112
+ routes.detect { |r| r.controller_name == name }
113
+ end
113
114
 
114
- # Class methods
115
- def self.draw
116
- drawn_router
117
- end
115
+ # Class methods
116
+ def draw
117
+ drawn_router
118
+ end
118
119
 
119
- @@drawn_router = nil
120
- def self.drawn_router
121
- return @@drawn_router if @@drawn_router
120
+ @@drawn_router = nil
121
+ def drawn_router
122
+ return @@drawn_router if @@drawn_router
122
123
 
123
- router = Jets.application.routes
124
- @@drawn_router = router
125
- end
124
+ router = Jets.application.routes
125
+ @@drawn_router = router
126
+ end
126
127
 
127
- def self.clear!
128
- @@drawn_router = nil
129
- Jets::Router::Helpers::NamedRoutesHelper.clear!
130
- end
128
+ def clear!
129
+ @@drawn_router = nil
130
+ Jets::Router::Helpers::NamedRoutesHelper.clear!
131
+ end
131
132
 
132
- def self.routes
133
- drawn_router.routes
134
- end
133
+ def routes
134
+ drawn_router.routes
135
+ end
135
136
 
136
- # Returns all paths including subpaths.
137
- # Example:
138
- # Input: ["posts/:id/edit"]
139
- # Output: ["posts", "posts/:id", "posts/:id/edit"]
140
- def self.all_paths
141
- drawn_router.all_paths
142
- end
137
+ # Returns all paths including subpaths.
138
+ # Example:
139
+ # Input: ["posts/:id/edit"]
140
+ # Output: ["posts", "posts/:id", "posts/:id/edit"]
141
+ def all_paths
142
+ drawn_router.all_paths
143
+ end
143
144
 
144
- def self.help(routes)
145
- return "Your routes table is empty." if routes.empty?
145
+ def help(routes)
146
+ return "Your routes table is empty." if routes.empty?
146
147
 
147
- table = Text::Table.new
148
- table.head = %w[As Verb Path Controller#action]
149
- routes.each do |route|
150
- table.rows << [route.as, route.method, route.path, route.to]
148
+ table = Text::Table.new
149
+ table.head = %w[As Verb Path Controller#action]
150
+ routes.each do |route|
151
+ table.rows << [route.as, route.method, route.path, route.to]
152
+ end
153
+ table
151
154
  end
152
- table
153
- end
154
155
 
155
- def self.all_routes_valid
156
- invalid_routes.empty?
157
- end
156
+ def all_routes_valid?
157
+ invalid_routes.empty?
158
+ end
159
+
160
+ def invalid_routes
161
+ routes.select { |r| !r.valid? }
162
+ end
163
+
164
+ def validate_routes!
165
+ check_route_connected_functions
166
+ end
158
167
 
159
- def self.invalid_routes
160
- routes.select { |r| !r.valid? }
168
+ # Checks that all routes are validate and have corresponding lambda functions
169
+ def check_route_connected_functions
170
+ return true if all_routes_valid?
171
+
172
+ puts "Please double check the routes below map to valid controllers:".color(:red)
173
+ invalid_routes.each do |route|
174
+ puts " /#{route.path} => #{route.controller_name}##{route.action_name}"
175
+ end
176
+ false
177
+ end
161
178
  end
162
179
  end
163
180
  end
@@ -33,7 +33,7 @@ class Jets::Router::MethodCreator
33
33
  end
34
34
 
35
35
  def action
36
- @action || self.class.name.split('::').last.downcase
36
+ @action || self.class.name.split('::').last.downcase # MethodCreator::Edit, MethodCreator::New, etc
37
37
  end
38
38
 
39
39
  def full_as
@@ -55,6 +55,7 @@ class Jets::Router::MethodCreator
55
55
  end
56
56
 
57
57
  def path_method
58
+ return if @as == :disabled
58
59
  <<~EOL
59
60
  def #{full_meth_name(:path)}#{meth_args}
60
61
  "#{meth_result}"
@@ -63,6 +64,7 @@ class Jets::Router::MethodCreator
63
64
  end
64
65
 
65
66
  def url_method
67
+ return if @as == :disabled
66
68
  path_method_call = "#{full_meth_name(:path)}#{meth_args}"
67
69
  # Note: It is important lazily get the value of ENV['JETS_HOST'] within the method.
68
70
  # Since it is not set until the requrest goes through the main middleware.
@@ -1,7 +1,12 @@
1
1
  class Jets::Router::MethodCreator
2
2
  class Edit < Code
3
3
  def meth_name
4
- join(action, singularize(full_as), singularize(method_name_leaf))
4
+ path_items = @path.to_s.split('/')
5
+ if method_name_leaf && path_items.size != 3
6
+ nil # fallback: do not define url method
7
+ else # comes from resources
8
+ join(action, singularize(full_as), singularize(method_name_leaf))
9
+ end
5
10
  end
6
11
  end
7
12
  end
@@ -1,7 +1,7 @@
1
1
  class Jets::Router::MethodCreator
2
2
  class Index < Code
3
3
  def meth_name
4
- # Well this is pretty confusing and tough to follow. TODO: figure out how to improve this.
4
+ # TODO: figure out how to improve this and make easier to follow.
5
5
  #
6
6
  # Example 1:
7
7
  #
@@ -32,9 +32,15 @@ class Jets::Router::MethodCreator
32
32
  # all the info we need. In this tricky case, the method_name_leaf is set.
33
33
  # We then have to reconstruct the meth_name.
34
34
  #
35
+
35
36
  if method_name_leaf
36
- join(singularize(full_as), method_name_leaf) # reconstruct
37
- else
37
+ path_items = @path.to_s.split('/')
38
+ if path_items.size == 1
39
+ join(singularize(full_as), method_name_leaf) # reconstruct
40
+ else
41
+ nil # fallback: do not define url method
42
+ end
43
+ else # comes from resources
38
44
  join(full_as) # construct entirely from scope info
39
45
  end
40
46
  end
@@ -1,7 +1,12 @@
1
1
  class Jets::Router::MethodCreator
2
2
  class New < Code
3
3
  def meth_name
4
- join(action, singularize(full_as), singularize(method_name_leaf))
4
+ path_items = @path.to_s.split('/')
5
+ if method_name_leaf && path_items.size != 2
6
+ nil # fallback: do not define url method
7
+ else # comes from resources
8
+ join(action, singularize(full_as), singularize(method_name_leaf))
9
+ end
5
10
  end
6
11
  end
7
12
  end
@@ -1,7 +1,12 @@
1
1
  class Jets::Router::MethodCreator
2
2
  class Show < Code
3
3
  def meth_name
4
- join(singularize(full_as), singularize(method_name_leaf))
4
+ path_items = @path.to_s.split('/')
5
+ if method_name_leaf && path_items.size != 2
6
+ nil # fallback: do not define url method
7
+ else # comes from resources
8
+ join(singularize(full_as), singularize(method_name_leaf))
9
+ end
5
10
  end
6
11
  end
7
12
  end
@@ -59,6 +59,7 @@ class Jets::Router
59
59
  end
60
60
 
61
61
  def compute_as
62
+ return nil if @options[:as] == :disabled
62
63
  return unless @options[:method] == :get || @options[:root]
63
64
 
64
65
  controller, action = get_controller_action(@options)
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "2.1.1"
2
+ VERSION = "2.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -529,10 +529,10 @@ dependencies:
529
529
  - !ruby/object:Gem::Version
530
530
  version: '0'
531
531
  description: 'Jets is a framework that allows you to create serverless applications
532
- with a beautiful language: Ruby. It includes everything required to build an application
533
- and deploy it to AWS Lambda. Jets makes serverless accessible to everyone.'
534
- email:
535
- - tongueroo@gmail.com
532
+ with a beautiful language: Ruby. It includes everything required to build and deploy
533
+ an application. Jets leverages the power of Ruby to make serverless joyful for
534
+ everyone.'
535
+ email: tongueroo@gmail.com
536
536
  executables:
537
537
  - jets
538
538
  extensions: []
@@ -540,14 +540,13 @@ extra_rdoc_files: []
540
540
  files:
541
541
  - ".circleci/config.yml"
542
542
  - ".codebuild/README.md"
543
- - ".codebuild/bin/jets"
544
- - ".codebuild/buildspec-base.yml"
545
- - ".codebuild/integration.sh"
546
- - ".codebuild/jets.postman_collection.json"
547
- - ".codebuild/scripts/install-docker.sh"
548
- - ".codebuild/scripts/install-dynamodb-local.sh"
549
- - ".codebuild/scripts/install-java.sh"
550
- - ".codebuild/scripts/install-node.sh"
543
+ - ".codebuild/docs/bin/build.sh"
544
+ - ".codebuild/docs/bin/cli_docs.sh"
545
+ - ".codebuild/docs/bin/git_commit.sh"
546
+ - ".codebuild/docs/bin/git_setup.sh"
547
+ - ".codebuild/docs/bin/subnav.sh"
548
+ - ".codebuild/docs/buildspec.yml"
549
+ - ".codebuild/docs/project.rb"
551
550
  - ".github/ISSUE_TEMPLATE.md"
552
551
  - ".github/ISSUE_TEMPLATE/bug_report.md"
553
552
  - ".github/ISSUE_TEMPLATE/documentation.md"
@@ -609,6 +608,7 @@ files:
609
608
  - lib/jets/camelizer.rb
610
609
  - lib/jets/cfn/builders/api_deployment_builder.rb
611
610
  - lib/jets/cfn/builders/api_gateway_builder.rb
611
+ - lib/jets/cfn/builders/api_resources_builder.rb
612
612
  - lib/jets/cfn/builders/base_child_builder.rb
613
613
  - lib/jets/cfn/builders/controller_builder.rb
614
614
  - lib/jets/cfn/builders/function_builder.rb
@@ -617,6 +617,7 @@ files:
617
617
  - lib/jets/cfn/builders/parent_builder.rb
618
618
  - lib/jets/cfn/builders/rule_builder.rb
619
619
  - lib/jets/cfn/builders/shared_builder.rb
620
+ - lib/jets/cfn/built_template.rb
620
621
  - lib/jets/cfn/ship.rb
621
622
  - lib/jets/cfn/status.rb
622
623
  - lib/jets/cfn/upload.rb
@@ -653,9 +654,9 @@ files:
653
654
  - lib/jets/commands/help/console.md
654
655
  - lib/jets/commands/help/db/generate.md
655
656
  - lib/jets/commands/help/dbconsole.md
657
+ - lib/jets/commands/help/degenerate.md
656
658
  - lib/jets/commands/help/delete.md
657
659
  - lib/jets/commands/help/deploy.md
658
- - lib/jets/commands/help/destroy.md
659
660
  - lib/jets/commands/help/dynamodb/generate.md
660
661
  - lib/jets/commands/help/dynamodb/migrate.md
661
662
  - lib/jets/commands/help/gems/check.md
@@ -856,6 +857,8 @@ files:
856
857
  - lib/jets/resource/api_gateway/rest_api/routes.rb
857
858
  - lib/jets/resource/api_gateway/rest_api/routes/change.rb
858
859
  - lib/jets/resource/api_gateway/rest_api/routes/change/base.rb
860
+ - lib/jets/resource/api_gateway/rest_api/routes/change/media_types.rb
861
+ - lib/jets/resource/api_gateway/rest_api/routes/change/page.rb
859
862
  - lib/jets/resource/api_gateway/rest_api/routes/change/to.rb
860
863
  - lib/jets/resource/api_gateway/rest_api/routes/change/variable.rb
861
864
  - lib/jets/resource/api_gateway/rest_api/routes/collision.rb
@@ -864,6 +867,8 @@ files:
864
867
  - lib/jets/resource/base.rb
865
868
  - lib/jets/resource/child_stack/api_deployment.rb
866
869
  - lib/jets/resource/child_stack/api_gateway.rb
870
+ - lib/jets/resource/child_stack/api_resource.rb
871
+ - lib/jets/resource/child_stack/api_resource/page.rb
867
872
  - lib/jets/resource/child_stack/app_class.rb
868
873
  - lib/jets/resource/child_stack/base.rb
869
874
  - lib/jets/resource/child_stack/shared.rb
@@ -967,7 +972,7 @@ files:
967
972
  - readme/testing.md
968
973
  - vendor/aws_data/Gemfile.lock
969
974
  - vendor/aws_data/pkg/aws_data-0.1.0.gem
970
- homepage: http://rubyonjets.com
975
+ homepage: https://rubyonjets.com
971
976
  licenses:
972
977
  - MIT
973
978
  metadata: {}
@@ -1029,5 +1034,5 @@ requirements: []
1029
1034
  rubygems_version: 3.0.3
1030
1035
  signing_key:
1031
1036
  specification_version: 4
1032
- summary: Ruby Serverless Framework on AWS Lambda
1037
+ summary: Ruby Serverless Framework
1033
1038
  test_files: []