jets 1.9.32 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/jets/application/defaults.rb +6 -0
- data/lib/jets/cli.rb +9 -0
- data/lib/jets/commands/help/generate.md +25 -19
- data/lib/jets/commands/main.rb +3 -3
- data/lib/jets/commands/rake_tasks.rb +3 -0
- data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +1 -0
- data/lib/jets/commands/templates/skeleton/config/application.rb.tt +4 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js +3 -0
- data/lib/jets/commands/upgrade.rb +42 -109
- data/lib/jets/commands/upgrade/version1.rb +136 -0
- data/lib/jets/controller/base.rb +16 -0
- data/lib/jets/controller/error.rb +4 -0
- data/lib/jets/controller/error/invalid_authenticity_token.rb +6 -0
- data/lib/jets/controller/forgery_protection.rb +43 -0
- data/lib/jets/controller/middleware/local.rb +3 -3
- data/lib/jets/controller/middleware/local/route_matcher.rb +1 -1
- data/lib/jets/controller/middleware/main.rb +7 -1
- data/lib/jets/controller/rack/adapter.rb +1 -1
- data/lib/jets/controller/rack/env.rb +1 -1
- data/lib/jets/controller/rendering/rack_renderer.rb +44 -37
- data/lib/jets/controller/stage.rb +2 -1
- data/lib/jets/generator.rb +72 -8
- data/lib/jets/generator/templates/active_job/job/templates/application_job.rb.tt +6 -0
- data/lib/jets/generator/templates/active_job/job/templates/job.rb.tt +8 -0
- data/lib/jets/generator/templates/erb/scaffold/_form.html.erb +11 -16
- data/lib/jets/generator/templates/erb/scaffold/edit.html.erb +2 -2
- data/lib/jets/generator/templates/erb/scaffold/index.html.erb +5 -5
- data/lib/jets/generator/templates/erb/scaffold/new.html.erb +1 -1
- data/lib/jets/generator/templates/erb/scaffold/show.html.erb +3 -3
- data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +5 -5
- data/lib/jets/internal/app/controllers/jets/rack_controller.rb +1 -0
- data/lib/jets/overrides/rails.rb +2 -1
- data/lib/jets/overrides/rails/action_controller.rb +12 -0
- data/lib/jets/overrides/rails/url_helper.rb +66 -5
- data/lib/jets/resource/api_gateway/rest_api/routes/change/base.rb +1 -1
- data/lib/jets/resource/api_gateway/rest_api/routes/collision.rb +1 -1
- data/lib/jets/router.rb +32 -46
- data/lib/jets/router/dsl.rb +136 -0
- data/lib/jets/router/error.rb +4 -0
- data/lib/jets/router/helpers.rb +4 -0
- data/lib/jets/router/helpers/core_helper.rb +17 -0
- data/lib/jets/router/helpers/named_routes_helper.rb +8 -0
- data/lib/jets/router/method_creator.rb +54 -0
- data/lib/jets/router/method_creator/code.rb +98 -0
- data/lib/jets/router/method_creator/edit.rb +7 -0
- data/lib/jets/router/method_creator/generic.rb +11 -0
- data/lib/jets/router/method_creator/index.rb +42 -0
- data/lib/jets/router/method_creator/new.rb +7 -0
- data/lib/jets/router/method_creator/root.rb +15 -0
- data/lib/jets/router/method_creator/show.rb +7 -0
- data/lib/jets/router/resources/base.rb +7 -0
- data/lib/jets/router/resources/filter.rb +15 -0
- data/lib/jets/router/resources/options.rb +13 -0
- data/lib/jets/router/route.rb +226 -0
- data/lib/jets/router/scope.rb +65 -4
- data/lib/jets/router/util.rb +38 -0
- data/lib/jets/turbo/project/config/application.rb +1 -0
- data/lib/jets/version.rb +1 -1
- metadata +26 -2
- data/lib/jets/route.rb +0 -166
data/lib/jets/router/scope.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Jets
|
2
2
|
class Router
|
3
3
|
class Scope
|
4
|
+
include Util
|
5
|
+
|
4
6
|
attr_reader :options, :parent, :level
|
5
7
|
def initialize(options = {}, parent = nil, level = 1)
|
6
8
|
@options = options
|
@@ -16,14 +18,73 @@ module Jets
|
|
16
18
|
self.class.new(options, self, level + 1)
|
17
19
|
end
|
18
20
|
|
19
|
-
def
|
20
|
-
|
21
|
+
def full_module
|
22
|
+
items = walk_parents do |current, i, result|
|
23
|
+
mod = current.options[:module]
|
24
|
+
next unless mod
|
25
|
+
result.unshift(mod)
|
26
|
+
end
|
27
|
+
|
28
|
+
items.empty? ? nil : items.join('/')
|
29
|
+
end
|
30
|
+
|
31
|
+
def full_prefix
|
32
|
+
items = walk_parents do |current, i, result|
|
33
|
+
prefix = current.options[:prefix]
|
34
|
+
next unless prefix
|
35
|
+
|
36
|
+
case current.from
|
37
|
+
when :resources
|
38
|
+
variable = prefix.to_s.split('/').last
|
39
|
+
variable = ":#{variable.singularize}_id"
|
40
|
+
result.unshift(variable)
|
41
|
+
result.unshift(prefix)
|
42
|
+
else # resource, namespace or general scope
|
43
|
+
result.unshift(prefix)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
items.empty? ? nil : items.join('/')
|
48
|
+
end
|
49
|
+
|
50
|
+
def full_as
|
51
|
+
items = []
|
21
52
|
current = self
|
22
53
|
while current
|
23
|
-
|
54
|
+
items.unshift(current.options[:as]) # <= option_name
|
55
|
+
current = current.parent
|
56
|
+
end
|
57
|
+
|
58
|
+
items.compact!
|
59
|
+
return if items.empty?
|
60
|
+
|
61
|
+
items = singularize_leading(items)
|
62
|
+
items.join('_')
|
63
|
+
end
|
64
|
+
|
65
|
+
def walk_parents
|
66
|
+
current, i, result = self, 0, []
|
67
|
+
while current
|
68
|
+
yield(current, i, result)
|
24
69
|
current = current.parent
|
70
|
+
i += 1
|
25
71
|
end
|
26
|
-
|
72
|
+
result
|
73
|
+
end
|
74
|
+
|
75
|
+
# singularize all except last item
|
76
|
+
def singularize_leading(items)
|
77
|
+
result = []
|
78
|
+
items.each_with_index do |item, index|
|
79
|
+
item = item.to_s
|
80
|
+
r = index == items.size - 1 ? item : item.singularize
|
81
|
+
result << r
|
82
|
+
end
|
83
|
+
result
|
84
|
+
end
|
85
|
+
|
86
|
+
def from
|
87
|
+
@options[:from]
|
27
88
|
end
|
28
89
|
end
|
29
90
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Jets::Router
|
2
|
+
module Util
|
3
|
+
# used in MethodCreator logic
|
4
|
+
def join(*items)
|
5
|
+
list = items.compact.join('_')
|
6
|
+
underscore(list)
|
7
|
+
end
|
8
|
+
|
9
|
+
def underscore(str)
|
10
|
+
return unless str
|
11
|
+
str.to_s.gsub(/[^a-zA-Z0-9]/,'_')
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_controller_action(options)
|
15
|
+
if options.key?(:controller) && options.key?(:action)
|
16
|
+
[options[:controller], options[:action]]
|
17
|
+
elsif options.key?(:controller) && options.key?(:to)
|
18
|
+
action = options[:to].split('#').last
|
19
|
+
[options[:controller], action]
|
20
|
+
elsif options.key?(:on)
|
21
|
+
handle_on!(options)
|
22
|
+
else
|
23
|
+
options[:to].split('#') # controller, action
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def handle_on!(options)
|
28
|
+
controller = @scope.options[:prefix].to_s
|
29
|
+
to = "#{controller}##{options[:path]}"
|
30
|
+
options[:to] = to
|
31
|
+
|
32
|
+
as = @options[:on] == :member ? controller.singularize : controller
|
33
|
+
as = "#{@options[:path]}_#{as}"
|
34
|
+
options[:as] = as
|
35
|
+
to.split('#')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/jets/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
@@ -727,6 +727,7 @@ files:
|
|
727
727
|
- lib/jets/commands/upgrade.rb
|
728
728
|
- lib/jets/commands/upgrade/templates/bin/webpack
|
729
729
|
- lib/jets/commands/upgrade/templates/bin/webpack-dev-server
|
730
|
+
- lib/jets/commands/upgrade/version1.rb
|
730
731
|
- lib/jets/commands/url.rb
|
731
732
|
- lib/jets/commands/webpacker_template.rb
|
732
733
|
- lib/jets/controller.rb
|
@@ -734,6 +735,9 @@ files:
|
|
734
735
|
- lib/jets/controller/callbacks.rb
|
735
736
|
- lib/jets/controller/cookies.rb
|
736
737
|
- lib/jets/controller/cookies/jar.rb
|
738
|
+
- lib/jets/controller/error.rb
|
739
|
+
- lib/jets/controller/error/invalid_authenticity_token.rb
|
740
|
+
- lib/jets/controller/forgery_protection.rb
|
737
741
|
- lib/jets/controller/layout.rb
|
738
742
|
- lib/jets/controller/middleware/cors.rb
|
739
743
|
- lib/jets/controller/middleware/local.rb
|
@@ -759,6 +763,8 @@ files:
|
|
759
763
|
- lib/jets/dotenv/ssm.rb
|
760
764
|
- lib/jets/erb.rb
|
761
765
|
- lib/jets/generator.rb
|
766
|
+
- lib/jets/generator/templates/active_job/job/templates/application_job.rb.tt
|
767
|
+
- lib/jets/generator/templates/active_job/job/templates/job.rb.tt
|
762
768
|
- lib/jets/generator/templates/erb/controller/view.html.erb
|
763
769
|
- lib/jets/generator/templates/erb/scaffold/_form.html.erb
|
764
770
|
- lib/jets/generator/templates/erb/scaffold/edit.html.erb
|
@@ -817,6 +823,7 @@ files:
|
|
817
823
|
- lib/jets/overrides/lambda.rb
|
818
824
|
- lib/jets/overrides/lambda/marshaller.rb
|
819
825
|
- lib/jets/overrides/rails.rb
|
826
|
+
- lib/jets/overrides/rails/action_controller.rb
|
820
827
|
- lib/jets/overrides/rails/asset_tag_helper.rb
|
821
828
|
- lib/jets/overrides/rails/common_methods.rb
|
822
829
|
- lib/jets/overrides/rails/rendering_helper.rb
|
@@ -884,9 +891,26 @@ files:
|
|
884
891
|
- lib/jets/resource/sns/topic_policy.rb
|
885
892
|
- lib/jets/resource/sqs/queue.rb
|
886
893
|
- lib/jets/resource/standardizer.rb
|
887
|
-
- lib/jets/route.rb
|
888
894
|
- lib/jets/router.rb
|
895
|
+
- lib/jets/router/dsl.rb
|
896
|
+
- lib/jets/router/error.rb
|
897
|
+
- lib/jets/router/helpers.rb
|
898
|
+
- lib/jets/router/helpers/core_helper.rb
|
899
|
+
- lib/jets/router/helpers/named_routes_helper.rb
|
900
|
+
- lib/jets/router/method_creator.rb
|
901
|
+
- lib/jets/router/method_creator/code.rb
|
902
|
+
- lib/jets/router/method_creator/edit.rb
|
903
|
+
- lib/jets/router/method_creator/generic.rb
|
904
|
+
- lib/jets/router/method_creator/index.rb
|
905
|
+
- lib/jets/router/method_creator/new.rb
|
906
|
+
- lib/jets/router/method_creator/root.rb
|
907
|
+
- lib/jets/router/method_creator/show.rb
|
908
|
+
- lib/jets/router/resources/base.rb
|
909
|
+
- lib/jets/router/resources/filter.rb
|
910
|
+
- lib/jets/router/resources/options.rb
|
911
|
+
- lib/jets/router/route.rb
|
889
912
|
- lib/jets/router/scope.rb
|
913
|
+
- lib/jets/router/util.rb
|
890
914
|
- lib/jets/rule/base.rb
|
891
915
|
- lib/jets/rule/dsl.rb
|
892
916
|
- lib/jets/spec_helpers.rb
|
data/lib/jets/route.rb
DELETED
@@ -1,166 +0,0 @@
|
|
1
|
-
# route = Jets::Route.new(
|
2
|
-
# path: "posts",
|
3
|
-
# method: :get,
|
4
|
-
# to: "posts#index",
|
5
|
-
# )
|
6
|
-
class Jets::Route
|
7
|
-
CAPTURE_REGEX = "([^/]*)" # as string
|
8
|
-
|
9
|
-
def initialize(options)
|
10
|
-
@options = options
|
11
|
-
end
|
12
|
-
|
13
|
-
# IE: standard: posts/:id/edit
|
14
|
-
# api_gateway: posts/{id}/edit
|
15
|
-
def path(format=:jets)
|
16
|
-
case format
|
17
|
-
when :api_gateway
|
18
|
-
api_gateway_format(@options[:path])
|
19
|
-
when :raw
|
20
|
-
@options[:path]
|
21
|
-
else # jets format
|
22
|
-
ensure_jets_format(@options[:path])
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def method
|
27
|
-
@options[:method].to_s.upcase
|
28
|
-
end
|
29
|
-
|
30
|
-
# IE: posts#index
|
31
|
-
def to
|
32
|
-
@options[:to]
|
33
|
-
end
|
34
|
-
|
35
|
-
def internal?
|
36
|
-
!!@options[:internal]
|
37
|
-
end
|
38
|
-
|
39
|
-
def homepage?
|
40
|
-
path == ''
|
41
|
-
end
|
42
|
-
|
43
|
-
# IE: PostsController
|
44
|
-
def controller_name
|
45
|
-
to.sub(/#.*/,'').camelize + "Controller"
|
46
|
-
end
|
47
|
-
|
48
|
-
# IE: index
|
49
|
-
def action_name
|
50
|
-
to.sub(/.*#/,'')
|
51
|
-
end
|
52
|
-
|
53
|
-
# Checks to see if the corresponding controller exists. Useful to validate routes
|
54
|
-
# before deploying to CloudFormation and then rolling back.
|
55
|
-
def valid?
|
56
|
-
controller_class = begin
|
57
|
-
controller_name.constantize
|
58
|
-
rescue NameError
|
59
|
-
return false
|
60
|
-
end
|
61
|
-
controller_class.lambda_functions.include?(action_name.to_sym)
|
62
|
-
end
|
63
|
-
|
64
|
-
# Extracts the path parameters from the actual path
|
65
|
-
# Only supports extracting 1 parameter. So:
|
66
|
-
#
|
67
|
-
# actual_path: posts/tung/edit
|
68
|
-
# route.path: posts/:id/edit
|
69
|
-
#
|
70
|
-
# Returns:
|
71
|
-
# { id: "tung" }
|
72
|
-
def extract_parameters(actual_path)
|
73
|
-
if path.include?(':')
|
74
|
-
extract_parameters_capture(actual_path)
|
75
|
-
elsif path.include?('*')
|
76
|
-
extract_parameters_proxy(actual_path)
|
77
|
-
else
|
78
|
-
# Lambda AWS_PROXY sets null to the input request when there are no path parmeters
|
79
|
-
nil
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def extract_parameters_proxy(actual_path)
|
84
|
-
# changes path to a string used for a regexp
|
85
|
-
# others/*proxy => others\/(.*)
|
86
|
-
# nested/others/*proxy => nested/others\/(.*)
|
87
|
-
if path.include?('/')
|
88
|
-
leading_path = path.split('/')[0..-2].join('/') # drop last segment
|
89
|
-
# leading_path: nested/others
|
90
|
-
# capture everything after the leading_path as the value
|
91
|
-
regexp = Regexp.new("#{leading_path}/(.*)")
|
92
|
-
value = actual_path.match(regexp)[1]
|
93
|
-
else
|
94
|
-
value = actual_path
|
95
|
-
end
|
96
|
-
|
97
|
-
# the last segment without the '*' is the key
|
98
|
-
proxy_segment = path.split('/').last # last segment is the proxy segment
|
99
|
-
# proxy_segment: *proxy
|
100
|
-
key = proxy_segment.sub('*','')
|
101
|
-
|
102
|
-
{ key => value }
|
103
|
-
end
|
104
|
-
|
105
|
-
def extract_parameters_capture(actual_path)
|
106
|
-
# changes path to a string used for a regexp
|
107
|
-
# posts/:id/edit => posts\/(.*)\/edit
|
108
|
-
labels = []
|
109
|
-
regexp_string = path.split('/').map do |s|
|
110
|
-
if s.start_with?(':')
|
111
|
-
labels << s.delete_prefix(':')
|
112
|
-
CAPTURE_REGEX
|
113
|
-
else
|
114
|
-
s
|
115
|
-
end
|
116
|
-
end.join('\/')
|
117
|
-
# make sure beginning and end of the string matches
|
118
|
-
regexp_string = "^#{regexp_string}$"
|
119
|
-
regexp = Regexp.new(regexp_string)
|
120
|
-
|
121
|
-
values = regexp.match(actual_path).captures
|
122
|
-
labels.map do |next_label|
|
123
|
-
[next_label, values.delete_at(0)]
|
124
|
-
end.to_h
|
125
|
-
end
|
126
|
-
|
127
|
-
def authorization_type
|
128
|
-
@options[:authorization_type]
|
129
|
-
end
|
130
|
-
|
131
|
-
private
|
132
|
-
def ensure_jets_format(path)
|
133
|
-
path.split('/').map do |s|
|
134
|
-
if s =~ /^\{/ and s =~ /\+\}$/
|
135
|
-
s.sub(/^\{/, '*').sub(/\+\}$/,'') # {proxy+} => *proxy
|
136
|
-
elsif s =~ /^\{/ and s =~ /\}$/
|
137
|
-
s.sub('{',':').sub(/\}$/,'') # {id} => :id
|
138
|
-
else
|
139
|
-
s
|
140
|
-
end
|
141
|
-
end.join('/')
|
142
|
-
end
|
143
|
-
|
144
|
-
def api_gateway_format(path)
|
145
|
-
path.split('/')
|
146
|
-
.map {|s| transform_capture(s) }
|
147
|
-
.map {|s| transform_proxy(s) }
|
148
|
-
.join('/')
|
149
|
-
end
|
150
|
-
|
151
|
-
def transform_capture(text)
|
152
|
-
if text.starts_with?(':')
|
153
|
-
text = text.sub(':','')
|
154
|
-
text = "{#{text}}"
|
155
|
-
end
|
156
|
-
text
|
157
|
-
end
|
158
|
-
|
159
|
-
def transform_proxy(text)
|
160
|
-
if text.starts_with?('*')
|
161
|
-
text = text.sub('*','')
|
162
|
-
text = "{#{text}+}"
|
163
|
-
end
|
164
|
-
text
|
165
|
-
end
|
166
|
-
end
|