jets 4.0.12 → 5.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (616) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -1
  3. data/CHANGELOG.md +52 -8
  4. data/Gemfile +1 -5
  5. data/LICENSE.txt +1 -1
  6. data/Rakefile +3 -3
  7. data/engines/internal/app/controllers/jets/application_controller.rb +28 -0
  8. data/engines/internal/app/controllers/jets/bare_controller.rb +6 -0
  9. data/engines/internal/app/controllers/jets/health_controller.rb +55 -0
  10. data/engines/internal/app/controllers/jets/info_controller.rb +45 -0
  11. data/{lib/jets → engines}/internal/app/controllers/jets/mailers_controller.rb +12 -14
  12. data/{lib/jets → engines}/internal/app/controllers/jets/mount_controller.rb +6 -10
  13. data/{lib/jets → engines}/internal/app/controllers/jets/public_controller.rb +6 -2
  14. data/engines/internal/app/controllers/jets/welcome_controller.rb +9 -0
  15. data/{lib/jets → engines}/internal/app/functions/jets/base_path.rb +2 -1
  16. data/{lib/jets → engines}/internal/app/functions/jets/base_path_mapping.rb +26 -6
  17. data/engines/internal/app/jobs/jets/preheat_job.rb +67 -0
  18. data/engines/internal/app/views/jets/info/properties.html.erb +1 -0
  19. data/engines/internal/app/views/jets/info/routes.html.erb +10 -0
  20. data/{lib/jets → engines}/internal/app/views/jets/mailers/email.html.erb +37 -17
  21. data/engines/internal/app/views/jets/mailers/index.html.erb +8 -0
  22. data/engines/internal/app/views/jets/mailers/mailer.html.erb +6 -0
  23. data/{lib/jets/commands/templates/skeleton/public/index.html.tt → engines/internal/app/views/jets/welcome/index.html.erb} +8 -4
  24. data/engines/internal/app/views/layouts/application.html.erb +51 -0
  25. data/engines/internal/lib/internal/actiondispatch.rb +39 -0
  26. data/engines/internal/lib/internal/actionmailer.rb +51 -0
  27. data/engines/internal/lib/internal/actionview.rb +152 -0
  28. data/engines/internal/lib/internal/activerecord.rb +37 -0
  29. data/engines/internal/lib/internal/activesupport.rb +47 -0
  30. data/engines/internal/lib/internal/engine.rb +13 -0
  31. data/engines/internal/lib/internal/i18n_engine.rb +19 -0
  32. data/engines/internal/lib/internal/jets_controller.rb +46 -0
  33. data/engines/internal/lib/internal/overrides/debug_exceptions.rb +40 -0
  34. data/engines/internal/lib/internal/templates/rescues/_trace.html.erb +62 -0
  35. data/engines/internal/lib/internal/templates/rescues/_trace.text.erb +9 -0
  36. data/engines/internal/lib/internal/turbines/asset_tag_helper.rb +70 -0
  37. data/engines/internal/lib/internal/turbines/helpers.rb +18 -0
  38. data/engines/internal/lib/internal/turbines/routes_helpers.rb +42 -0
  39. data/exe/jets +1 -10
  40. data/jets.gemspec +14 -11
  41. data/lib/jets/app_loader.rb +77 -0
  42. data/lib/jets/application/bootstrap.rb +100 -0
  43. data/lib/jets/application/configuration/defaults.rb +256 -0
  44. data/lib/jets/application/configuration.rb +494 -0
  45. data/lib/jets/application/default_middleware_stack.rb +140 -0
  46. data/lib/jets/application/dummy_erb_compiler.rb +18 -0
  47. data/lib/jets/application/finisher.rb +266 -0
  48. data/lib/jets/application/routes_reloader.rb +80 -0
  49. data/lib/jets/application.rb +515 -198
  50. data/lib/jets/authorizer/base.rb +1 -0
  51. data/lib/jets/authorizer/dsl.rb +15 -11
  52. data/lib/jets/authorizer/helpers/iam_helper.rb +13 -11
  53. data/lib/jets/autoloaders/gem.rb +70 -0
  54. data/lib/jets/autoloaders/inflector.rb +21 -0
  55. data/lib/jets/autoloaders.rb +38 -101
  56. data/lib/jets/aws_services/stack_status.rb +1 -1
  57. data/lib/jets/backtrace_cleaner.rb +27 -0
  58. data/lib/jets/booter.rb +29 -176
  59. data/lib/jets/builders/code_builder.rb +45 -117
  60. data/lib/jets/builders/code_size.rb +1 -0
  61. data/lib/jets/builders/gem_replacer.rb +5 -6
  62. data/lib/jets/builders/handler_generator.rb +34 -14
  63. data/lib/jets/builders/lambda_layer.rb +2 -7
  64. data/lib/jets/builders/purger.rb +1 -1
  65. data/lib/jets/builders/rack_packager.rb +1 -1
  66. data/lib/jets/builders/ruby_packager.rb +17 -6
  67. data/lib/jets/builders/shim_vars/app.rb +10 -6
  68. data/lib/jets/builders/templates/handlers/one_lambda_for_all_controllers.rb +33 -0
  69. data/lib/jets/builders/templates/handlers/one_lambda_per_controller.rb +20 -0
  70. data/lib/jets/builders/templates/{handler.rb → handlers/one_lambda_per_method.rb} +6 -0
  71. data/lib/jets/bundle.rb +2 -9
  72. data/lib/jets/cfn/base.rb +82 -0
  73. data/lib/jets/cfn/builder/api/base.rb +12 -0
  74. data/lib/jets/cfn/{builders/api_deployment_builder.rb → builder/api/deployment.rb} +10 -20
  75. data/lib/jets/cfn/{builders/api_gateway_builder.rb → builder/api/gateway.rb} +14 -37
  76. data/lib/jets/cfn/builder/api/mapping.rb +54 -0
  77. data/lib/jets/cfn/builder/api/methods.rb +72 -0
  78. data/lib/jets/cfn/builder/api/paged.rb +30 -0
  79. data/lib/jets/cfn/builder/api/pages/base.rb +105 -0
  80. data/lib/jets/cfn/builder/api/pages/methods.rb +17 -0
  81. data/lib/jets/cfn/builder/api/pages/page.rb +19 -0
  82. data/lib/jets/cfn/builder/api/pages/resources.rb +21 -0
  83. data/lib/jets/cfn/builder/api/resources.rb +40 -0
  84. data/lib/jets/cfn/{builders/authorizer_builder.rb → builder/authorizer.rb} +16 -19
  85. data/lib/jets/cfn/builder/controller.rb +28 -0
  86. data/lib/jets/cfn/builder/function.rb +9 -0
  87. data/lib/jets/cfn/{builders → builder}/interface.rb +45 -51
  88. data/lib/jets/cfn/builder/job.rb +10 -0
  89. data/lib/jets/cfn/builder/nested.rb +130 -0
  90. data/lib/jets/cfn/builder/one_controller.rb +53 -0
  91. data/lib/jets/cfn/{builders/parent_builder → builder/parent}/stagger.rb +1 -1
  92. data/lib/jets/cfn/{builders/parent_builder.rb → builder/parent.rb} +54 -54
  93. data/lib/jets/cfn/builder/post_process.rb +25 -0
  94. data/lib/jets/cfn/{builders/rule_builder.rb → builder/rule.rb} +4 -8
  95. data/lib/jets/cfn/{builders/shared_builder.rb → builder/shared.rb} +4 -3
  96. data/lib/jets/cfn/{builders → builder}/util/source.rb +1 -1
  97. data/lib/jets/{commands/build.rb → cfn/builder.rb} +50 -78
  98. data/lib/jets/cfn/deployment.rb +45 -0
  99. data/lib/jets/cfn/download.rb +39 -0
  100. data/lib/jets/cfn/params/api/base.rb +39 -0
  101. data/lib/jets/cfn/params/api/cors.rb +10 -0
  102. data/lib/jets/cfn/params/api/methods.rb +69 -0
  103. data/lib/jets/cfn/params/api/resources.rb +28 -0
  104. data/lib/jets/{resource/child_stack/common_parameters.rb → cfn/params/common.rb} +3 -3
  105. data/lib/jets/{resource → cfn/resource}/api_gateway/authorizer.rb +21 -21
  106. data/lib/jets/cfn/resource/api_gateway/base_path/function.rb +57 -0
  107. data/lib/jets/{resource → cfn/resource}/api_gateway/base_path/mapping.rb +13 -12
  108. data/lib/jets/cfn/resource/api_gateway/base_path/role.rb +70 -0
  109. data/lib/jets/{resource → cfn/resource}/api_gateway/deployment.rb +13 -20
  110. data/lib/jets/{resource → cfn/resource}/api_gateway/domain_name.rb +11 -11
  111. data/lib/jets/{resource → cfn/resource}/api_gateway/method/authorization.rb +1 -1
  112. data/lib/jets/cfn/resource/api_gateway/method.rb +92 -0
  113. data/lib/jets/{resource → cfn/resource}/api_gateway/resource.rb +14 -10
  114. data/lib/jets/cfn/resource/api_gateway/resource_id.rb +25 -0
  115. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/change_detection.rb +1 -1
  116. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/logical_id/message.rb +1 -1
  117. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/logical_id.rb +1 -1
  118. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/change/base.rb +4 -3
  119. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/change/media_types.rb +2 -2
  120. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/change/page.rb +5 -5
  121. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/change/to.rb +8 -3
  122. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/change/variable.rb +2 -2
  123. data/lib/jets/cfn/resource/api_gateway/rest_api/routes/change.rb +21 -0
  124. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/collision/variable_exception.rb +1 -1
  125. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes/collision.rb +1 -1
  126. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api/routes.rb +1 -1
  127. data/lib/jets/{resource → cfn/resource}/api_gateway/rest_api.rb +12 -12
  128. data/lib/jets/{resource → cfn/resource}/associated.rb +1 -1
  129. data/lib/jets/{resource → cfn/resource}/config/config_rule.rb +18 -18
  130. data/lib/jets/{resource → cfn/resource}/config/managed_rule.rb +5 -5
  131. data/lib/jets/{resource → cfn/resource}/events/rule.rb +10 -10
  132. data/lib/jets/{resource → cfn/resource}/iam/application_role.rb +4 -4
  133. data/lib/jets/{resource → cfn/resource}/iam/base_role_definition.rb +15 -15
  134. data/lib/jets/{resource → cfn/resource}/iam/class_role.rb +5 -5
  135. data/lib/jets/{resource → cfn/resource}/iam/function_role.rb +6 -6
  136. data/lib/jets/{resource → cfn/resource}/iam/managed_policy.rb +1 -1
  137. data/lib/jets/{resource → cfn/resource}/iam/policy.rb +8 -8
  138. data/lib/jets/{resource → cfn/resource}/iam/policy_document.rb +10 -9
  139. data/lib/jets/{resource → cfn/resource}/iot/topic_rule.rb +10 -10
  140. data/lib/jets/{resource → cfn/resource}/lambda/event_source_mapping.rb +9 -9
  141. data/lib/jets/cfn/resource/lambda/function/controller.rb +21 -0
  142. data/lib/jets/{resource → cfn/resource}/lambda/function/environment.rb +4 -5
  143. data/lib/jets/cfn/resource/lambda/function.rb +266 -0
  144. data/lib/jets/{resource → cfn/resource}/lambda/gem_layer.rb +2 -2
  145. data/lib/jets/{resource → cfn/resource}/lambda/layer_version.rb +10 -10
  146. data/lib/jets/cfn/resource/lambda/permission.rb +51 -0
  147. data/lib/jets/cfn/resource/logs/subscription_filter.rb +31 -0
  148. data/lib/jets/cfn/resource/nested/api/base.rb +4 -0
  149. data/lib/jets/cfn/resource/nested/api/deployment.rb +53 -0
  150. data/lib/jets/cfn/resource/nested/api/gateway.rb +15 -0
  151. data/lib/jets/cfn/resource/nested/api/mapping.rb +33 -0
  152. data/lib/jets/cfn/resource/nested/api/methods.rb +30 -0
  153. data/lib/jets/cfn/resource/nested/api/page.rb +8 -0
  154. data/lib/jets/cfn/resource/nested/api/resources.rb +22 -0
  155. data/lib/jets/{resource/child_stack → cfn/resource/nested}/app_class.rb +15 -48
  156. data/lib/jets/{resource/child_stack → cfn/resource/nested}/authorizer.rb +8 -14
  157. data/lib/jets/cfn/resource/nested/base.rb +38 -0
  158. data/lib/jets/cfn/resource/nested/one_controller.rb +48 -0
  159. data/lib/jets/{resource/child_stack → cfn/resource/nested}/shared.rb +10 -16
  160. data/lib/jets/cfn/resource/one/function.rb +66 -0
  161. data/lib/jets/cfn/resource/one/permission.rb +17 -0
  162. data/lib/jets/{resource → cfn/resource}/replacer.rb +26 -27
  163. data/lib/jets/{resource → cfn/resource}/route53/record_set.rb +18 -18
  164. data/lib/jets/{resource → cfn/resource}/s3/bucket.rb +4 -4
  165. data/lib/jets/cfn/resource/s3/jets_bucket.rb +68 -0
  166. data/lib/jets/{resource → cfn/resource}/sns/subscription.rb +8 -8
  167. data/lib/jets/{resource → cfn/resource}/sns/topic.rb +10 -10
  168. data/lib/jets/{resource → cfn/resource}/sns/topic_policy.rb +13 -13
  169. data/lib/jets/{resource → cfn/resource}/sqs/queue.rb +5 -5
  170. data/lib/jets/{resource → cfn/resource}/standardizer.rb +8 -9
  171. data/lib/jets/cfn/resource.rb +8 -0
  172. data/lib/jets/cfn/ship.rb +20 -19
  173. data/lib/jets/cfn/template.rb +89 -0
  174. data/lib/jets/cfn/upload.rb +26 -23
  175. data/lib/jets/cli.rb +28 -210
  176. data/lib/jets/command/actions.rb +49 -0
  177. data/lib/jets/command/api_helpers.rb +41 -0
  178. data/lib/jets/command/aws_helpers.rb +26 -0
  179. data/lib/jets/command/base.rb +204 -0
  180. data/lib/jets/command/behavior.rb +83 -0
  181. data/lib/jets/command/environment_argument.rb +42 -0
  182. data/lib/jets/command/help/call.md +48 -0
  183. data/lib/jets/{commands → command}/help/deploy.md +1 -1
  184. data/lib/jets/command/help/logs.md +21 -0
  185. data/lib/jets/{commands → command}/help/new.md +3 -4
  186. data/lib/jets/command/help/projects.md +6 -0
  187. data/lib/jets/command/help/releases.md +37 -0
  188. data/lib/jets/command/help/rollback.md +5 -0
  189. data/lib/jets/command/help/routes.md +15 -0
  190. data/lib/jets/command/help/stacks.md +6 -0
  191. data/lib/jets/command/help.rb +17 -0
  192. data/lib/jets/command/helpers/editor.rb +35 -0
  193. data/lib/jets/command.rb +133 -0
  194. data/lib/jets/commands/application/application_command.rb +40 -0
  195. data/lib/jets/commands/build/build_command.rb +33 -0
  196. data/lib/jets/commands/call/anonymous_guesser.rb +1 -1
  197. data/lib/jets/commands/call/autoload_guesser.rb +2 -2
  198. data/lib/jets/commands/call/base_guesser.rb +4 -4
  199. data/lib/jets/commands/call/call_command.rb +27 -0
  200. data/lib/jets/commands/call/caller.rb +184 -0
  201. data/lib/jets/commands/call/guesser.rb +1 -1
  202. data/lib/jets/commands/clean/base.rb +1 -1
  203. data/lib/jets/commands/clean/build.rb +1 -1
  204. data/lib/jets/commands/clean/clean_command.rb +15 -0
  205. data/lib/jets/commands/clean/log.rb +1 -1
  206. data/lib/jets/commands/configure/configure_command.rb +9 -0
  207. data/lib/jets/commands/console/console_command.rb +38 -0
  208. data/lib/jets/commands/credentials/USAGE +103 -0
  209. data/lib/jets/commands/credentials/credentials_command/diffing.rb +51 -0
  210. data/lib/jets/commands/credentials/credentials_command.rb +139 -0
  211. data/lib/jets/commands/db/system/change/change_command.rb +24 -0
  212. data/lib/jets/commands/dbconsole/dbconsole_command.rb +184 -0
  213. data/lib/jets/commands/degenerate/degenerate_command.rb +21 -0
  214. data/lib/jets/commands/delete/delete_command.rb +155 -0
  215. data/lib/jets/commands/{deploy.rb → deploy/deploy_command.rb} +28 -47
  216. data/lib/jets/commands/dev/dev_command.rb +19 -0
  217. data/lib/jets/commands/{dotenv.rb → dotenv/dotenv_command.rb} +2 -2
  218. data/lib/jets/commands/encrypted/USAGE +46 -0
  219. data/lib/jets/commands/encrypted/encrypted_command.rb +87 -0
  220. data/lib/jets/commands/gems/gems_command.rb +14 -0
  221. data/lib/jets/commands/generate/generate_command.rb +95 -0
  222. data/lib/jets/commands/help/USAGE +20 -0
  223. data/lib/jets/commands/help/help_command.rb +15 -0
  224. data/lib/jets/commands/initializers/initializers_command.rb +19 -0
  225. data/lib/jets/commands/logs/logs_command.rb +45 -0
  226. data/lib/jets/commands/new/new_command.rb +19 -0
  227. data/lib/jets/commands/notes/notes_command.rb +30 -0
  228. data/lib/jets/commands/plugin/plugin_command.rb +45 -0
  229. data/lib/jets/commands/projects/projects_command.rb +30 -0
  230. data/lib/jets/commands/rake/rake_command.rb +59 -0
  231. data/lib/jets/commands/releases/releases_command.rb +72 -0
  232. data/lib/jets/commands/rollback/rollback_command.rb +41 -0
  233. data/lib/jets/commands/routes/routes_command.rb +19 -0
  234. data/lib/jets/commands/runner/runner_command.rb +60 -0
  235. data/lib/jets/commands/server/server_command.rb +291 -0
  236. data/lib/jets/commands/stacks/stacks_command.rb +39 -0
  237. data/lib/jets/commands/status/status_command.rb +9 -0
  238. data/lib/jets/commands/{url.rb → url/url_command.rb} +37 -14
  239. data/lib/jets/commands/version/version_command.rb +11 -0
  240. data/lib/jets/commands.rb +17 -0
  241. data/lib/jets/configuration.rb +166 -0
  242. data/lib/jets/controller/base.rb +105 -183
  243. data/lib/jets/controller/compat/abstract_controller/base.rb +126 -0
  244. data/lib/jets/controller/compat/action_controller/metal.rb +99 -0
  245. data/lib/jets/controller/compat/caching.rb +13 -0
  246. data/lib/jets/controller/compat/future.rb +13 -0
  247. data/lib/jets/controller/compat/route_set.rb +47 -0
  248. data/lib/jets/controller/decorate/apigw_stage.rb +39 -0
  249. data/lib/jets/controller/{authorization.rb → decorate/authorization.rb} +1 -1
  250. data/lib/jets/controller/decorate/logging.rb +90 -0
  251. data/lib/jets/controller/decorate/redirecting.rb +16 -0
  252. data/lib/jets/controller/decorate/url_for.rb +10 -0
  253. data/lib/jets/controller/{rack/adapter.rb → handler/apigw.rb} +36 -37
  254. data/lib/jets/controller/handler.rb +41 -0
  255. data/lib/jets/controller/middleware/main.rb +16 -8
  256. data/lib/jets/controller/middleware/{local/api_gateway.rb → mimic/apigw.rb} +40 -15
  257. data/lib/jets/controller/middleware/mimic/lambda_context.rb +44 -0
  258. data/lib/jets/controller/middleware/{local.rb → mimic.rb} +36 -51
  259. data/lib/jets/controller/rack_adapter/action.rb +35 -0
  260. data/lib/jets/controller/{rack → rack_adapter}/env.rb +39 -24
  261. data/lib/jets/controller/request/compat/params.rb +144 -0
  262. data/lib/jets/controller/request/compat/request.rb +125 -0
  263. data/lib/jets/controller/request.rb +35 -18
  264. data/lib/jets/controller/response/compat/response.rb +67 -0
  265. data/lib/jets/controller/response.rb +91 -8
  266. data/lib/jets/core.rb +136 -51
  267. data/lib/jets/core_ext/kernel.rb +2 -2
  268. data/lib/jets/core_ext/symbol.rb +5 -0
  269. data/lib/jets/core_ext.rb +4 -0
  270. data/lib/jets/dev_caching.rb +44 -0
  271. data/lib/jets/dotenv/ssm.rb +2 -2
  272. data/lib/jets/dotenv.rb +2 -1
  273. data/lib/jets/engine/configuration.rb +96 -0
  274. data/lib/jets/engine/turbines.rb +23 -0
  275. data/lib/jets/engine.rb +380 -0
  276. data/lib/jets/exception_reporting.rb +43 -0
  277. data/lib/jets/generators/job/job_generator.rb +41 -0
  278. data/lib/jets/generators/job/templates/event_types/dynamodb.rb.tt +8 -0
  279. data/lib/jets/generators/job/templates/event_types/iot.rb.tt +8 -0
  280. data/lib/jets/generators/job/templates/event_types/kinesis.rb.tt +9 -0
  281. data/lib/jets/generators/job/templates/event_types/log.rb.tt +9 -0
  282. data/lib/jets/generators/job/templates/event_types/rule.rb.tt +23 -0
  283. data/lib/jets/generators/job/templates/event_types/s3.rb.tt +11 -0
  284. data/lib/jets/{generator/templates/active_job/job/templates/job.rb.tt → generators/job/templates/event_types/scheduled.rb.tt} +3 -3
  285. data/lib/jets/generators/job/templates/event_types/sns.rb.tt +9 -0
  286. data/lib/jets/generators/job/templates/event_types/sqs.rb.tt +9 -0
  287. data/lib/jets/generators/overrides/app/USAGE +38 -0
  288. data/lib/jets/generators/overrides/app/app_generator.rb +148 -0
  289. data/lib/jets/generators/overrides/app/helpers.rb +143 -0
  290. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/.gitignore +2 -1
  291. data/lib/jets/generators/overrides/app/templates/Gemfile.tt +25 -0
  292. data/lib/jets/generators/overrides/app/templates/Rakefile +2 -0
  293. data/lib/jets/generators/overrides/app/templates/app/assets/config/manifest.js +3 -0
  294. data/lib/jets/generators/overrides/app/templates/app/assets/stylesheets/application.css +15 -0
  295. data/lib/jets/generators/overrides/app/templates/app/javascript/application.js +5 -0
  296. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/app/models/application_record.rb +1 -1
  297. data/lib/jets/generators/overrides/app/templates/app/views/layouts/application.html.erb.tt +30 -0
  298. data/lib/jets/generators/overrides/app/templates/bin/jets +3 -0
  299. data/lib/jets/generators/overrides/app/templates/config/application.rb.tt +15 -0
  300. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/config/database.yml.tt +1 -1
  301. data/lib/jets/generators/overrides/app/templates/config/environments/development.rb.tt +29 -0
  302. data/lib/jets/generators/overrides/app/templates/config/environments/production.rb.tt +19 -0
  303. data/lib/jets/generators/overrides/app/templates/config/environments/test.rb.tt +23 -0
  304. data/lib/jets/generators/overrides/app/templates/config/initializers/content_security_policy.rb +31 -0
  305. data/lib/jets/generators/overrides/app/templates/config/initializers/filter_parameter_logging.rb +8 -0
  306. data/lib/jets/generators/overrides/app/templates/config/initializers/permissions_policy.rb +11 -0
  307. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/config/routes.rb +5 -1
  308. data/lib/jets/generators/overrides/app/templates/db/.gitkeep +0 -0
  309. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/public/404.html +6 -6
  310. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/public/422.html +6 -6
  311. data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/public/500.html +6 -6
  312. data/lib/jets/generators/overrides/templates/erb/scaffold/index.html.erb +22 -0
  313. data/lib/jets/generators/overrides/templates/erb/scaffold/partial.html.erb +8 -0
  314. data/lib/jets/{generator/templates/rails/scaffold_controller/api_controller.rb → generators/overrides/templates/rails/scaffold_controller/api_controller.rb.tt} +5 -9
  315. data/lib/jets/generators/overrides/templates/rails/scaffold_controller/controller.rb.tt +67 -0
  316. data/lib/jets/generators.rb +112 -0
  317. data/lib/jets/info.rb +116 -0
  318. data/lib/jets/initializable.rb +95 -0
  319. data/lib/jets/job/base.rb +3 -2
  320. data/lib/jets/job/dsl/dynamodb_event.rb +19 -9
  321. data/lib/jets/job/dsl/event_source_mapping.rb +1 -1
  322. data/lib/jets/job/dsl/iot_event.rb +6 -6
  323. data/lib/jets/job/dsl/kinesis_event.rb +5 -5
  324. data/lib/jets/job/dsl/log_event.rb +2 -2
  325. data/lib/jets/job/dsl/rule_event.rb +7 -4
  326. data/lib/jets/job/dsl/s3_event.rb +1 -1
  327. data/lib/jets/job/dsl/sns_event.rb +6 -6
  328. data/lib/jets/job/dsl/sqs_event.rb +11 -11
  329. data/lib/jets/klass.rb +5 -6
  330. data/lib/jets/lambda/definition.rb +118 -0
  331. data/lib/jets/lambda/dsl/warnings.rb +57 -0
  332. data/lib/jets/lambda/dsl.rb +64 -53
  333. data/lib/jets/lambda/function.rb +3 -3
  334. data/lib/jets/lambda/function_constructor.rb +6 -6
  335. data/lib/jets/lambda/functions.rb +36 -1
  336. data/lib/jets/mega/request/source.rb +1 -2
  337. data/lib/jets/mega/request.rb +4 -4
  338. data/lib/jets/names.rb +31 -15
  339. data/lib/jets/overrides/dummy/rails.rb +11 -0
  340. data/lib/jets/overrides/lambda/marshaller.rb +10 -0
  341. data/lib/jets/overrides/puma.rb +10 -0
  342. data/lib/jets/paths.rb +243 -0
  343. data/lib/jets/{poly_fun → poly}/base_executor.rb +13 -13
  344. data/lib/jets/{poly_fun → poly}/lambda_executor.rb +2 -2
  345. data/lib/jets/{poly_fun → poly}/node_error.rb +1 -1
  346. data/lib/jets/{poly_fun → poly}/node_executor.rb +4 -4
  347. data/lib/jets/{poly_fun → poly}/python_error.rb +1 -1
  348. data/lib/jets/{poly_fun → poly}/python_executor.rb +2 -2
  349. data/lib/jets/{poly_fun.rb → poly.rb} +12 -12
  350. data/lib/jets/preheat.rb +12 -25
  351. data/lib/jets/processors/deducer.rb +2 -2
  352. data/lib/jets/processors/main_processor.rb +6 -13
  353. data/lib/jets/rack/logger.rb +77 -0
  354. data/lib/jets/router/compat/route_set.rb +177 -0
  355. data/lib/jets/router/dsl/mount.rb +40 -6
  356. data/lib/jets/router/dsl.rb +125 -105
  357. data/lib/jets/router/engine_mount.rb +36 -0
  358. data/lib/jets/router/help.rb +130 -0
  359. data/lib/jets/router/helpers/named_routes/add_full_url.rb +13 -0
  360. data/lib/jets/router/helpers/named_routes/generated.rb +197 -0
  361. data/lib/jets/router/helpers/named_routes/proxy.rb +66 -0
  362. data/lib/jets/router/matcher.rb +135 -16
  363. data/lib/jets/router/resources/options.rb +6 -4
  364. data/lib/jets/router/route/after_initialize.rb +64 -0
  365. data/lib/jets/router/route/as.rb +93 -0
  366. data/lib/jets/router/route/authorizer.rb +1 -0
  367. data/lib/jets/router/route/compat.rb +45 -0
  368. data/lib/jets/router/route/info.rb +74 -0
  369. data/lib/jets/router/route/node.rb +137 -0
  370. data/lib/jets/router/route/path.rb +93 -0
  371. data/lib/jets/router/route.rb +109 -106
  372. data/lib/jets/router/route_set.rb +214 -0
  373. data/lib/jets/router/scope.rb +204 -69
  374. data/lib/jets/router/state.rb +36 -16
  375. data/lib/jets/router/util.rb +1 -31
  376. data/lib/jets/router.rb +64 -162
  377. data/lib/jets/ruby_version_check.rb +15 -0
  378. data/lib/jets/rule/base.rb +1 -0
  379. data/lib/jets/rule/dsl.rb +7 -7
  380. data/lib/jets/secrets.rb +110 -0
  381. data/lib/jets/spec_helpers/controllers/request.rb +22 -16
  382. data/lib/jets/spec_helpers/controllers.rb +32 -24
  383. data/lib/jets/spec_helpers.rb +0 -6
  384. data/lib/jets/stack/builder.rb +3 -2
  385. data/lib/jets/stack/definition.rb +1 -4
  386. data/lib/jets/stack/function.rb +2 -2
  387. data/lib/jets/stack/main/dsl/cloudwatch.rb +4 -4
  388. data/lib/jets/stack/main/dsl/kinesis.rb +2 -2
  389. data/lib/jets/stack/main/dsl/lambda.rb +26 -20
  390. data/lib/jets/stack/main/dsl/sqs.rb +2 -2
  391. data/lib/jets/stack/output/lookup.rb +1 -1
  392. data/lib/jets/stack/output.rb +2 -2
  393. data/lib/jets/stack/parameter.rb +2 -2
  394. data/lib/jets/stack/resource.rb +3 -3
  395. data/lib/jets/stack/s3_event.rb +51 -37
  396. data/lib/jets/stack.rb +1 -1
  397. data/lib/jets/tasks/engine.rake +85 -0
  398. data/lib/jets/tasks/framework.rake +66 -0
  399. data/lib/jets/tasks/log.rake +41 -0
  400. data/lib/jets/tasks/middleware.rake +9 -0
  401. data/lib/jets/tasks/misc.rake +81 -0
  402. data/lib/jets/tasks/statistics.rake +37 -0
  403. data/lib/jets/tasks/tmp.rake +51 -0
  404. data/lib/jets/tasks/yarn.rake +29 -0
  405. data/lib/jets/tasks/zeitwerk.rake +61 -0
  406. data/lib/jets/tasks.rb +18 -0
  407. data/lib/jets/turbine/configurable.rb +36 -0
  408. data/lib/jets/turbine/configuration.rb +101 -0
  409. data/lib/jets/turbine.rb +164 -20
  410. data/lib/jets/util/camelize.rb +24 -0
  411. data/lib/jets/version.rb +1 -1
  412. data/lib/jets.rb +7 -15
  413. metadata +429 -339
  414. data/bin/release +0 -9
  415. data/lib/jets/application/defaults.rb +0 -230
  416. data/lib/jets/builders/reconfigure_rails/config/initializers/jets.rb +0 -16
  417. data/lib/jets/builders/reconfigure_rails.rb +0 -114
  418. data/lib/jets/cfn/builders/api_resources_builder.rb +0 -44
  419. data/lib/jets/cfn/builders/base_child_builder.rb +0 -88
  420. data/lib/jets/cfn/builders/controller_builder.rb +0 -50
  421. data/lib/jets/cfn/builders/function_builder.rb +0 -14
  422. data/lib/jets/cfn/builders/job_builder.rb +0 -14
  423. data/lib/jets/cfn/builders/page_builder.rb +0 -80
  424. data/lib/jets/cfn/built_template.rb +0 -15
  425. data/lib/jets/cfn/template_source.rb +0 -61
  426. data/lib/jets/commands/base.rb +0 -145
  427. data/lib/jets/commands/call.rb +0 -185
  428. data/lib/jets/commands/clean.rb +0 -19
  429. data/lib/jets/commands/configure.rb +0 -51
  430. data/lib/jets/commands/console.rb +0 -18
  431. data/lib/jets/commands/db/environment-task.rake +0 -3
  432. data/lib/jets/commands/db/tasks/dummy/app.rb +0 -25
  433. data/lib/jets/commands/db/tasks/dummy/config.rb +0 -14
  434. data/lib/jets/commands/db/tasks.rb +0 -34
  435. data/lib/jets/commands/db.rb +0 -13
  436. data/lib/jets/commands/dbconsole.rb +0 -134
  437. data/lib/jets/commands/delete.rb +0 -136
  438. data/lib/jets/commands/dynamodb/migrate.rb +0 -9
  439. data/lib/jets/commands/dynamodb/migrator.rb +0 -36
  440. data/lib/jets/commands/dynamodb.rb +0 -19
  441. data/lib/jets/commands/gems.rb +0 -13
  442. data/lib/jets/commands/help/call.md +0 -69
  443. data/lib/jets/commands/help/dynamodb/generate.md +0 -52
  444. data/lib/jets/commands/help/dynamodb/migrate.md +0 -4
  445. data/lib/jets/commands/help/routes.md +0 -16
  446. data/lib/jets/commands/help.rb +0 -9
  447. data/lib/jets/commands/import/base.rb +0 -49
  448. data/lib/jets/commands/import/cheatsheet.rb +0 -35
  449. data/lib/jets/commands/import/rack.rb +0 -16
  450. data/lib/jets/commands/import/rails.rb +0 -74
  451. data/lib/jets/commands/import/sequence.rb +0 -90
  452. data/lib/jets/commands/import/templates/config/database.yml +0 -30
  453. data/lib/jets/commands/import/templates/submodules-cheatsheet.md +0 -89
  454. data/lib/jets/commands/import.rb +0 -12
  455. data/lib/jets/commands/main.rb +0 -169
  456. data/lib/jets/commands/markdown/creator.rb +0 -58
  457. data/lib/jets/commands/markdown/index.rb +0 -27
  458. data/lib/jets/commands/markdown/page.rb +0 -125
  459. data/lib/jets/commands/markdown/shell.rb +0 -11
  460. data/lib/jets/commands/new.rb +0 -173
  461. data/lib/jets/commands/rake_command.rb +0 -61
  462. data/lib/jets/commands/rake_tasks.rb +0 -50
  463. data/lib/jets/commands/runner.rb +0 -16
  464. data/lib/jets/commands/sequence.rb +0 -104
  465. data/lib/jets/commands/stack_info.rb +0 -30
  466. data/lib/jets/commands/templates/skeleton/.env.development.tt +0 -3
  467. data/lib/jets/commands/templates/skeleton/.env.test +0 -3
  468. data/lib/jets/commands/templates/skeleton/.env.tt +0 -3
  469. data/lib/jets/commands/templates/skeleton/.jetskeep +0 -1
  470. data/lib/jets/commands/templates/skeleton/Gemfile.tt +0 -40
  471. data/lib/jets/commands/templates/skeleton/Procfile +0 -7
  472. data/lib/jets/commands/templates/skeleton/Rakefile +0 -2
  473. data/lib/jets/commands/templates/skeleton/app/models/application_item.rb +0 -2
  474. data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +0 -26
  475. data/lib/jets/commands/templates/skeleton/config/application.rb.tt +0 -72
  476. data/lib/jets/commands/templates/skeleton/config/dynamodb.yml +0 -22
  477. data/lib/jets/commands/templates/skeleton/config/environments/development.rb +0 -7
  478. data/lib/jets/commands/templates/skeleton/config/environments/production.rb +0 -9
  479. data/lib/jets/commands/templates/skeleton/config/environments/test.rb +0 -7
  480. data/lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt +0 -23
  481. data/lib/jets/commands/templates/webpacker/app/javascript/packs/theme.scss.tt +0 -24
  482. data/lib/jets/commands/upgrade/templates/bin/webpack +0 -19
  483. data/lib/jets/commands/upgrade/templates/bin/webpack-dev-server +0 -19
  484. data/lib/jets/commands/upgrade/version1.rb +0 -136
  485. data/lib/jets/commands/upgrade.rb +0 -105
  486. data/lib/jets/commands/webpacker_template.rb +0 -18
  487. data/lib/jets/controller/callbacks.rb +0 -73
  488. data/lib/jets/controller/cookies/jar.rb +0 -269
  489. data/lib/jets/controller/cookies.rb +0 -38
  490. data/lib/jets/controller/error/invalid_authenticity_token.rb +0 -6
  491. data/lib/jets/controller/error.rb +0 -4
  492. data/lib/jets/controller/forgery_protection.rb +0 -43
  493. data/lib/jets/controller/layout.rb +0 -17
  494. data/lib/jets/controller/middleware/cors.rb +0 -60
  495. data/lib/jets/controller/middleware/local/mimic_aws_call.rb +0 -38
  496. data/lib/jets/controller/middleware/local/route_matcher.rb +0 -22
  497. data/lib/jets/controller/middleware/reloader.rb +0 -15
  498. data/lib/jets/controller/parameters_filter.rb +0 -29
  499. data/lib/jets/controller/params.rb +0 -117
  500. data/lib/jets/controller/redirection.rb +0 -61
  501. data/lib/jets/controller/rendering/rack_renderer.rb +0 -267
  502. data/lib/jets/controller/rendering.rb +0 -96
  503. data/lib/jets/controller/stage.rb +0 -34
  504. data/lib/jets/controller.rb +0 -3
  505. data/lib/jets/db.rb +0 -15
  506. data/lib/jets/generator/templates/erb/controller/view.html.erb +0 -2
  507. data/lib/jets/generator/templates/erb/scaffold/index.html.erb +0 -29
  508. data/lib/jets/generator/templates/rails/controller/controller.rb +0 -13
  509. data/lib/jets/generator/templates/rails/helper/helper.rb +0 -4
  510. data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +0 -67
  511. data/lib/jets/generator.rb +0 -112
  512. data/lib/jets/internal/app/controllers/jets/bare_controller.rb +0 -16
  513. data/lib/jets/internal/app/controllers/jets/rack_controller.rb +0 -12
  514. data/lib/jets/internal/app/helpers/jets/mailers_helper.rb +0 -9
  515. data/lib/jets/internal/app/jobs/jets/preheat_job.rb +0 -52
  516. data/lib/jets/internal/app/views/jets/mailers/index.html.erb +0 -8
  517. data/lib/jets/internal/app/views/jets/mailers/mailer.html.erb +0 -6
  518. data/lib/jets/internal/turbines/jets/mailer.rb +0 -52
  519. data/lib/jets/lambda/task.rb +0 -111
  520. data/lib/jets/logger.rb +0 -21
  521. data/lib/jets/middleware/configurator.rb +0 -84
  522. data/lib/jets/middleware/default_stack.rb +0 -53
  523. data/lib/jets/middleware/layer.rb +0 -34
  524. data/lib/jets/middleware/stack.rb +0 -77
  525. data/lib/jets/middleware.rb +0 -33
  526. data/lib/jets/overrides/rails/action_controller.rb +0 -13
  527. data/lib/jets/overrides/rails/asset_tag_helper.rb +0 -114
  528. data/lib/jets/overrides/rails/common_methods.rb +0 -13
  529. data/lib/jets/overrides/rails/migration_checker.rb +0 -34
  530. data/lib/jets/overrides/rails/rendering_helper.rb +0 -27
  531. data/lib/jets/overrides/rails/url_helper.rb +0 -88
  532. data/lib/jets/overrides/rails.rb +0 -6
  533. data/lib/jets/rack_server.rb +0 -86
  534. data/lib/jets/resource/api_gateway/base_path/function.rb +0 -49
  535. data/lib/jets/resource/api_gateway/base_path/role.rb +0 -76
  536. data/lib/jets/resource/api_gateway/cors.rb +0 -61
  537. data/lib/jets/resource/api_gateway/method.rb +0 -102
  538. data/lib/jets/resource/api_gateway/rest_api/routes/change.rb +0 -16
  539. data/lib/jets/resource/base.rb +0 -28
  540. data/lib/jets/resource/child_stack/api_deployment.rb +0 -58
  541. data/lib/jets/resource/child_stack/api_gateway.rb +0 -23
  542. data/lib/jets/resource/child_stack/api_resource/page.rb +0 -20
  543. data/lib/jets/resource/child_stack/api_resource.rb +0 -54
  544. data/lib/jets/resource/child_stack/base.rb +0 -24
  545. data/lib/jets/resource/lambda/function.rb +0 -221
  546. data/lib/jets/resource/logs/subscription_filter.rb +0 -31
  547. data/lib/jets/resource/permission.rb +0 -45
  548. data/lib/jets/resource.rb +0 -71
  549. data/lib/jets/router/error.rb +0 -4
  550. data/lib/jets/router/finder.rb +0 -47
  551. data/lib/jets/router/helpers/core_helper.rb +0 -27
  552. data/lib/jets/router/helpers/named_routes_helper.rb +0 -8
  553. data/lib/jets/router/helpers.rb +0 -4
  554. data/lib/jets/router/method_creator/code.rb +0 -99
  555. data/lib/jets/router/method_creator/edit.rb +0 -12
  556. data/lib/jets/router/method_creator/generic.rb +0 -11
  557. data/lib/jets/router/method_creator/index.rb +0 -48
  558. data/lib/jets/router/method_creator/new.rb +0 -12
  559. data/lib/jets/router/method_creator/root.rb +0 -15
  560. data/lib/jets/router/method_creator/show.rb +0 -12
  561. data/lib/jets/router/method_creator.rb +0 -50
  562. data/lib/jets/turbo/database_yaml.rb +0 -41
  563. data/lib/jets/turbo/project/.gitignore +0 -12
  564. data/lib/jets/turbo/project/.jetskeep +0 -1
  565. data/lib/jets/turbo/project/Gemfile +0 -16
  566. data/lib/jets/turbo/project/Rakefile +0 -2
  567. data/lib/jets/turbo/project/app/controllers/application_controller.rb +0 -2
  568. data/lib/jets/turbo/project/app/helpers/application_helper.rb +0 -2
  569. data/lib/jets/turbo/project/app/jobs/application_job.rb +0 -4
  570. data/lib/jets/turbo/project/config/application.rb +0 -5
  571. data/lib/jets/turbo/project/config/routes.rb +0 -4
  572. data/lib/jets/turbo/project/config.ru +0 -5
  573. data/lib/jets/turbo/rails.rb +0 -127
  574. data/lib/jets/turbo/templates/config/database.yml +0 -30
  575. data/lib/jets/turbo.rb +0 -56
  576. data/readme/prerelease.md +0 -6
  577. data/readme/testing.md +0 -60
  578. /data/{lib/jets → engines}/internal/app/shared/functions/jets/s3_bucket_config.rb +0 -0
  579. /data/lib/jets/{commands → command}/help/build.md +0 -0
  580. /data/lib/jets/{commands → command}/help/clean/build.md +0 -0
  581. /data/lib/jets/{commands → command}/help/clean/log.md +0 -0
  582. /data/lib/jets/{commands → command}/help/console.md +0 -0
  583. /data/lib/jets/{commands → command}/help/db/generate.md +0 -0
  584. /data/lib/jets/{commands → command}/help/dbconsole.md +0 -0
  585. /data/lib/jets/{commands → command}/help/degenerate.md +0 -0
  586. /data/lib/jets/{commands → command}/help/delete.md +0 -0
  587. /data/lib/jets/{commands → command}/help/gems/check.md +0 -0
  588. /data/lib/jets/{commands → command}/help/generate.md +0 -0
  589. /data/lib/jets/{commands → command}/help/import/rack.md +0 -0
  590. /data/lib/jets/{commands → command}/help/import/rails.md +0 -0
  591. /data/lib/jets/{commands → command}/help/runner.md +0 -0
  592. /data/lib/jets/{commands → command}/help/server.md +0 -0
  593. /data/lib/jets/{commands → command}/help/status.md +0 -0
  594. /data/lib/jets/{commands → command}/help/upgrade.md +0 -0
  595. /data/lib/jets/{commands → command}/help/url.md +0 -0
  596. /data/lib/jets/{generator/templates/active_job → generators}/job/templates/application_job.rb.tt +0 -0
  597. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/.rspec +0 -0
  598. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/README.md +0 -0
  599. /data/{.gitmodules → lib/jets/generators/overrides/app/templates/app/assets/images/.keep} +0 -0
  600. /data/lib/jets/{commands/templates/skeleton/db/.gitkeep → generators/overrides/app/templates/app/assets/javascripts/.keep} +0 -0
  601. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/app/controllers/application_controller.rb +0 -0
  602. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/app/helpers/application_helper.rb +0 -0
  603. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/app/jobs/application_job.rb +0 -0
  604. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/config.ru +0 -0
  605. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/public/favicon.ico +0 -0
  606. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/spec/controllers/posts_controller_spec.rb +0 -0
  607. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/spec/fixtures/payloads/posts-index.json +0 -0
  608. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/spec/fixtures/payloads/posts-show.json +0 -0
  609. /data/lib/jets/{commands/templates/skeleton → generators/overrides/app/templates}/spec/spec_helper.rb.tt +0 -0
  610. /data/lib/jets/{generator → generators/overrides}/templates/erb/scaffold/_form.html.erb +0 -0
  611. /data/lib/jets/{generator → generators/overrides}/templates/erb/scaffold/edit.html.erb +0 -0
  612. /data/lib/jets/{generator → generators/overrides}/templates/erb/scaffold/new.html.erb +0 -0
  613. /data/lib/jets/{generator → generators/overrides}/templates/erb/scaffold/show.html.erb +0 -0
  614. /data/lib/jets/{generator → generators/overrides}/templates/rails/assets/javascript.js +0 -0
  615. /data/lib/jets/{generator → generators/overrides}/templates/rails/assets/stylesheet.css +0 -0
  616. /data/lib/jets/{generator → generators/overrides}/templates/rails/scaffold/scaffold.css +0 -0
@@ -1,35 +1,88 @@
1
- class Jets::Router
1
+ module Jets::Router
2
2
  module Dsl
3
3
  include Mount
4
4
 
5
5
  # Methods supported by API Gateway
6
6
  %w[any delete get head options patch post put].each do |method_name|
7
- define_method method_name do |path, options={}|
8
- create_route(options.merge(path: escape_path(path), method: __method__))
7
+ define_method method_name do |*args|
8
+ options = args.extract_options!
9
+ normalize_path_to_controller_map_option!(args, options)
10
+ options = options.clone
11
+ path_arg = args.first
12
+ if path_arg.is_a?(Symbol)
13
+ options[:action] = path_arg # Info#action uses
14
+ end
15
+ options[:path] ||= path_arg
16
+ options[:http_method] = __method__
17
+ create_route(options)
18
+ end
19
+ end
20
+
21
+ # Normally first args is a String that is the path
22
+ # get "/posts", to: "posts#index"
23
+ # But it can also be a Hash that maps the path to the controller/action
24
+ # get "/jets/info" => "jets/info#index"
25
+ # This logic normalize options to support both cases.
26
+ def normalize_path_to_controller_map_option!(args, options)
27
+ if !options[:to] && !args.first.is_a?(String) && !args.first.is_a?(Symbol)
28
+ map = options.find { |k,v| k.is_a?(String) }
29
+ path, to = map[0], map[1]
30
+ options[:to] = to
31
+ options[:path] = path
32
+ options.delete(path)
33
+ end
34
+ end
35
+
36
+ def match(path, options={})
37
+ via = options.delete(:via) || :any
38
+ Array(via).each do |http_method|
39
+ http_method = :any if via == :all
40
+ send http_method, path, options
9
41
  end
10
42
  end
11
43
 
44
+ def create_route(options)
45
+ one_apigw_method_for_all_routes_warning(options)
46
+ route = Route.new(options, @scope)
47
+ @routes << route
48
+ end
49
+
50
+ def constraints(constraints, &block)
51
+ scope(from: :constraints, constraints: constraints, &block)
52
+ end
53
+
54
+ def member(&block)
55
+ scope(from: :member, &block)
56
+ end
57
+
58
+ def collection(&block)
59
+ scope(from: :collection, &block)
60
+ end
61
+
62
+ def defaults(data={}, &block)
63
+ scope(from: :defaults, defaults: data, &block)
64
+ end
65
+
66
+ def path(path, &block)
67
+ scope(from: :path, path: path, &block)
68
+ end
69
+
12
70
  def namespace(ns, &block)
13
- scope(module: ns, prefix: ns, as: ns, from: :namespace, &block)
71
+ scope(from: :namespace, path: ns, module: ns, as: ns, &block)
14
72
  end
15
73
 
16
- def prefix(prefix, &block)
17
- scope(prefix: prefix, &block)
74
+ def shallow(&block)
75
+ scope(from: :shallow, &block)
18
76
  end
19
77
 
20
- # scope supports three options: module, prefix and as.
21
- # Jets vs Rails:
22
- # module - module
23
- # prefix - path
24
- # as - as
25
- def scope(args)
26
- # normalizes `scope(:admin)` as `scope(prefix: :admin)`
27
- options = case args
28
- when Hash
29
- args
30
- when String, Symbol
31
- { prefix: args }
32
- end
78
+ # Examples
79
+ # scope :admin
80
+ # scope path: :admin
81
+ # scope 'admin', as: 'admin'
82
+ def scope(*args)
83
+ options = args.extract_options!
84
+ path = args.first
85
+ options[:path] = path.to_s if path
33
86
 
34
87
  root_level = @scope.nil?
35
88
  @scope = root_level ? Scope.new(options) : @scope.new(options)
@@ -39,106 +92,73 @@ class Jets::Router
39
92
  end
40
93
 
41
94
  # resources macro expands to all the routes
42
- def resources(*items, **options)
43
- items.each do |item|
44
- scope_options = scope_options!(item, options)
45
- scope_options[:from] = :resources # flag for MethodCreator logic: to handle method_name_leaf and more
46
- scope(scope_options) do
47
- each_resources(item, options, block_given?)
95
+ def resources(*args)
96
+ options = args.extract_options!
97
+ resource_names = args
98
+ resource_names.each do |resource_name|
99
+ scope(options.merge(from: :resources, resource_name: resource_name)) do
100
+ each_resource(resource_name, options)
48
101
  yield if block_given?
49
102
  end
50
103
  end
51
104
  end
52
105
 
53
- def scope_options!(item, options)
54
- prefix = if options[:prefix]
55
- # prefix given from the resources macro get automatically prepended to the item name
56
- p = options.delete(:prefix)
57
- "#{p}/#{item}"
58
- else
59
- item
60
- end
61
-
62
- {
63
- as: options.delete(:as) || item, # delete as or it messes with create_route
64
- prefix: prefix,
65
- param: options[:param],
66
- # module: options.delete(:module) || item, # NOTE: resources does not automatically set module, but namespace does
67
- }
68
- end
69
-
70
- def each_resources(name, options={}, has_block=nil)
71
- o = Resources::Options.new(name, options)
72
- f = Resources::Filter.new(name, options)
73
- param = default_param(has_block, name, options)
74
-
75
- get name, o.build(:index) if f.yes?(:index)
76
- get "#{name}/new", o.build(:new) if f.yes?(:new) && !api_mode?
77
- get "#{name}/:#{param}", o.build(:show) if f.yes?(:show)
78
- post name, o.build(:create) if f.yes?(:create)
79
- get "#{name}/:#{param}/edit", o.build(:edit) if f.yes?(:edit) && !api_mode?
80
- put "#{name}/:#{param}", o.build(:update) if f.yes?(:update)
81
- post "#{name}/:#{param}", o.build(:update) if f.yes?(:update) # for binary uploads
82
- patch "#{name}/:#{param}", o.build(:update) if f.yes?(:update)
83
- delete "#{name}/:#{param}", o.build(:delete) if f.yes?(:delete)
84
- end
85
-
86
- def resource(*items, **options)
87
- items.each do |item|
88
- scope_options = scope_options!(item, options)
89
- scope_options[:from] = :resource # flag for MethodCreator logic: to handle method_name_leaf and more
90
- scope(scope_options) do
91
- each_resource(item, options, block_given?)
106
+ def resource(*args)
107
+ options = args.extract_options!
108
+ resource_names = args
109
+ resource_names.each do |resource_name|
110
+ scope(options.merge(from: :resource, resource_name: resource_name)) do
111
+ each_resource(resource_name, options.merge(singular_resource: true))
92
112
  yield if block_given?
93
113
  end
94
114
  end
95
115
  end
96
116
 
97
- def each_resource(name, options={}, has_block=nil)
98
- o = Resources::Options.new(name, options.merge(singular_resource: true))
99
- f = Resources::Filter.new(name, options)
100
-
101
- get "#{name}/new", o.build(:new) if f.yes?(:new) && !api_mode?
102
- get name, o.build(:show) if f.yes?(:show)
103
- post name, o.build(:create) if f.yes?(:create)
104
- get "#{name}/edit", o.build(:edit) if f.yes?(:edit) && !api_mode?
105
- put name, o.build(:update) if f.yes?(:update)
106
- post name, o.build(:update) if f.yes?(:update) # for binary uploads
107
- patch name, o.build(:update) if f.yes?(:update)
108
- delete name, o.build(:delete) if f.yes?(:delete)
109
- end
110
-
111
- def member
112
- @on_option = :member
113
- yield
114
- @on_option = nil
115
- end
116
-
117
- def collection
118
- @on_option = :collection
119
- yield
120
- @on_option = nil
121
- end
122
-
123
- # If a block has pass then we assume the resources will be nested and then prefix
124
- # the param name with the resource. IE: post_id instead of id
125
- # This avoids an API Gateway parent sibling variable collision.
126
- def default_param(has_block, name, options)
127
- default_param = has_block ? "#{name.to_s.singularize}_id".to_sym : :id
128
- options[:param] || default_param
117
+ # Important: Options as, module, etc are handled by scope and should not be passed to the route
118
+ HANDLED_BY_SCOPE = [:as, :module, :path, :shallow].freeze
119
+ def each_resource(resource_name, options={})
120
+ HANDLED_BY_SCOPE.each do |opt|
121
+ options.delete(opt)
122
+ end
123
+ o = Resources::Options.new(resource_name, options)
124
+ f = Resources::Filter.new(resource_name, options)
125
+
126
+ # Looks a little weird with '' but the path is handled by the scope
127
+ get '', o.build(:index) if f.yes?(:index) && !options[:singular_resource]
128
+ post '', o.build(:create) if f.yes?(:create)
129
+ get 'new', o.build(:new) if f.yes?(:new) && !api_mode?
130
+ get 'edit', o.build(:edit) if f.yes?(:edit) && !api_mode?
131
+ get '', o.build(:show) if f.yes?(:show)
132
+ put '', o.build(:update) if f.yes?(:update)
133
+ # post to update wont work with singular_resource because it's a route collision
134
+ # Also makes it so that route.to is always changed
135
+ # Leaving in case need it for some reason. Will remove later.
136
+ # post '', o.build(:update) if f.yes?(:update) # for binary uploads
137
+ patch '', o.build(:update) if f.yes?(:update)
138
+ delete '', o.build(:destroy) if f.yes?(:destroy)
129
139
  end
130
140
 
131
141
  # root "posts#index"
132
- def root(to, options={})
133
- default = {path: '', to: to, method: :get, root: true}
134
- options = default.merge(options)
135
- MethodCreator.new(options, @scope).create_root_helper
136
- @routes << Route.new(options, @scope)
137
- end
138
- private
142
+ # root to: "posts#index"
143
+ def root(*args)
144
+ if args.size == 1
145
+ options = args.first
146
+ if options.is_a?(String) # root "posts#index"
147
+ to = options
148
+ options = {}
149
+ elsif options.is_a?(Hash) # root to: "posts#index"
150
+ to = options.delete(:to)
151
+ end
152
+ else
153
+ to = args[0]
154
+ options = args[1] || {}
155
+ end
139
156
 
140
- def escape_path(path)
141
- path.to_s.split('/').map { |s| s =~ /\A[:\*]/ ? s : CGI.escape(s) }.join('/')
157
+ http_method = options.delete(:via)
158
+ http_method ||= Jets.config.api.cors ? :any : :get
159
+ default = {path: '/', to: to, http_method: http_method, root: true}
160
+ options = default.merge(options)
161
+ create_route(options)
142
162
  end
143
163
  end
144
164
  end
@@ -0,0 +1,36 @@
1
+ module Jets::Router
2
+ class EngineMount
3
+ def self.find_by(request_path: nil, engine: nil)
4
+ new.find_by(request_path: request_path, engine: engine)
5
+ end
6
+
7
+ def find_by(request_path: nil, engine: nil)
8
+ mount = if request_path
9
+ find_by_request_path(request_path)
10
+ elsif engine
11
+ find_by_engine(engine)
12
+ end
13
+
14
+ return unless mount
15
+
16
+ OpenStruct.new(at: mount[0], engine: mount[1])
17
+ end
18
+
19
+ def find_by_request_path(request_path)
20
+ mounted_engines.find do |at, engine|
21
+ request_path.starts_with?(at)
22
+ end
23
+ end
24
+
25
+ def find_by_engine(engine)
26
+ mounted = mounted_engines.find do |at, mounted_engine|
27
+ mounted_engine == engine
28
+ end
29
+ end
30
+
31
+ # Example mounted_engines: {"/blog"=>Blorgh::Engine}
32
+ def mounted_engines
33
+ Jets::Router::Dsl::Mount.mounted_engines
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,130 @@
1
+ require 'cli-format'
2
+
3
+ module Jets::Router
4
+ class Help
5
+ extend Memoist
6
+
7
+ def initialize(options={})
8
+ @options = options
9
+ @engines = {}
10
+ end
11
+
12
+ def all_routes
13
+ Jets::Router.routes
14
+ end
15
+
16
+ def routes
17
+ routes = filter(all_routes)
18
+ collect_engine_routes(routes)
19
+ if ENV['JETS_ROUTES_INTERNAL']
20
+ routes = routes.select { |route| route.internal }
21
+ else
22
+ routes = routes.reject { |route| route.internal }
23
+ end
24
+ routes
25
+ end
26
+
27
+ def collect_engine_routes(routes)
28
+ routes.each do |route|
29
+ collect_engine_routes_per(route) if route.engine?
30
+ end
31
+ end
32
+
33
+ def collect_engine_routes_per(route)
34
+ name = route.endpoint
35
+ return unless route.engine?
36
+ return if @engines[name]
37
+
38
+ route_set = route.rack_app.route_set
39
+ if route_set.is_a?(Jets::Router::RouteSet)
40
+ @engines[name] = route_set.routes
41
+ end
42
+ end
43
+
44
+ def filter(routes)
45
+ if @options[:controller]
46
+ routes.select do |route|
47
+ route.controller.include?(@options[:controller])
48
+ end
49
+ elsif @options[:grep]
50
+ grep_pattern = Regexp.new(@options[:grep], 'i')
51
+ proc = filter_proc(grep_pattern)
52
+ routes.select(&proc)
53
+ elsif @options[:reject]
54
+ reject_pattern = Regexp.new(@options[:reject], 'i')
55
+ proc = filter_proc(reject_pattern)
56
+ routes.reject(&proc)
57
+ else
58
+ routes
59
+ end
60
+ end
61
+
62
+ def filter_proc(pattern)
63
+ Proc.new do |route|
64
+ route.as =~ pattern ||
65
+ route.http_method =~ pattern ||
66
+ route.path =~ pattern ||
67
+ route.controller =~ pattern ||
68
+ route.mount_class_name =~ pattern
69
+ end
70
+ end
71
+
72
+ def header
73
+ header = ["As (Prefix)", "Verb", "Path (URI Pattern)", "Controller#action"]
74
+ # any_mount = routes.any?(&:mount_class_name)
75
+ # header << "Mount" if any_mount
76
+ header
77
+ end
78
+
79
+ def any_mount?
80
+ routes.any?(&:mount_class_name)
81
+ end
82
+
83
+ def print
84
+ puts text
85
+ end
86
+
87
+ def text
88
+ text = presenter_text("Routes for app:", routes)
89
+ @engines.each do |name, routes|
90
+ text += presenter_text("Routes for #{name}:", routes)
91
+ end
92
+ text
93
+ end
94
+
95
+ def presenter_text(summary_line, routes)
96
+ text = format_with_newlines(summary_line)
97
+ if routes.empty?
98
+ text += "The routes table is empty.\n"
99
+ return text
100
+ end
101
+
102
+ presenter = CliFormat::Presenter.new(@options)
103
+ presenter.header = header unless @options[:header] == false
104
+ routes.each do |route|
105
+ row = [route.as, route.http_method, route.path, route.to]
106
+ # row << route.mount_class_name if any_mount?
107
+ presenter.rows << row
108
+ end
109
+ text += presenter.text.to_s # <Text::Table> => String
110
+ text += "\n" unless text.ends_with?("\n")
111
+ text += "\n" if @options[:format] == "space" # add another newline for space format
112
+ text
113
+ end
114
+
115
+ def format_with_newlines(line)
116
+ return '' if @options[:header] == false
117
+
118
+ case @options[:format]
119
+ when "markdown"
120
+ # need leading newline for routes_table jets prints when route not found
121
+ # Unsure why it needs to be here and not at the routes_table method.
122
+ "\n#{line}\n\n"
123
+ when "space"
124
+ "#{line}\n\n"
125
+ else
126
+ "#{line}\n"
127
+ end
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,13 @@
1
+ module Jets::Router::Helpers::NamedRoutes
2
+ module AddFullUrl
3
+ # Named add_full_url to avoid mental conflicts with Jets full_url_for
4
+ # Leverage Rails URL.url_for to avoid duplicating the logic
5
+ # Rails sets url_strategy to:
6
+ # => ActionDispatch::Routing::RouteSet::UNKNOWN
7
+ # => ActionDispatch::Http::URL.url_for(options)
8
+ def add_full_url(options)
9
+ options = url_options.merge(options)
10
+ ActionDispatch::Http::URL.url_for(options)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,197 @@
1
+ require 'active_support/core_ext/module/remove_method'
2
+
3
+ module Jets::Router::Helpers::NamedRoutes
4
+ module Generated
5
+ def create_helper_module(route_set)
6
+ module_name = helper_module_name(route_set)
7
+ module_name.constantize rescue create_helper_module!(module_name, route_set)
8
+ end
9
+
10
+ def helper_module_name(route_set)
11
+ engine_class = route_set.engine.class
12
+ name = engine_class == Jets.app_class ? "main_app" : engine_class.engine_name
13
+ name = name.gsub('::','')
14
+ name = "#{name.camelize}Helpers" # MainAppHelpers or BlorghHelpers
15
+ "Jets::Router::Helpers::NamedRoutes::Generated::#{name}"
16
+ end
17
+
18
+ def create_helper_module!(module_name, route_set)
19
+ mod = Module.new do
20
+ extend ActiveSupport::Concern # Needed for _url_for_modules to work since or UrlHelper ClassMethods not included
21
+ mattr_accessor :path_helpers, default: Set.new
22
+ mattr_accessor :url_helpers, default: Set.new
23
+
24
+ include AddFullUrl
25
+
26
+ # For compatibility with Rails url_helpers
27
+ include ActionDispatch::Routing::UrlFor
28
+ define_singleton_method(:_routes) { route_set } # needed for controller class context
29
+ define_method(:_routes) { route_set } # needed for view context
30
+ # Jets convenience method
31
+ define_singleton_method(:route_set) { route_set }
32
+
33
+ define_singleton_method(:_url_for_modules) { ActionView::RoutingUrlFor }
34
+ define_method(:_url_for_modules) { ActionView::RoutingUrlFor }
35
+
36
+ # Mimic Rails behavior
37
+ # Precdence:
38
+ # 1. config.action_mailer.default_url_options
39
+ # 2. Jets.application.default_url_options
40
+ def default_url_options
41
+ self.class.default_url_options.empty? ? Jets.application.default_url_options : self.class.default_url_options
42
+ end
43
+
44
+ def add_methods!
45
+ route_set.routes.each do |route|
46
+ next unless route.as
47
+ next if route.engine?
48
+
49
+ name = route.as
50
+ path_name = "#{name}_path"
51
+ url_name = "#{name}_url"
52
+ engine_class = route_set.engine.class
53
+
54
+ # Normally, self is <PostsController> or View context instance
55
+ define_method(path_name) do |*args|
56
+ NamedRouteMethod.new(route, args, self, engine_class).path
57
+ end
58
+ self.path_helpers.add(path_name)
59
+
60
+ define_method(url_name) do |*args|
61
+ path = send(path_name, *args)
62
+ options = args.extract_options!
63
+ add_full_url(options.merge(path: path))
64
+ end
65
+ self.url_helpers.add(url_name)
66
+ end
67
+ end
68
+
69
+ def remove_methods!
70
+ remove = Proc.new { |method| remove_method(method) }
71
+ path_helpers.each(&:remove)
72
+ url_helpers.each(&:remove)
73
+ self.path_helpers.clear
74
+ self.url_helpers.clear
75
+ end
76
+
77
+ # Wonder if extend self is may idea since it can allow context to be module itself
78
+ # instead of the controller or view instance. However, it allows
79
+ # Jets.application.routes.url_helpers.posts_path style calls in jets console
80
+ extend self
81
+
82
+ add_methods!
83
+ end
84
+
85
+ # Name it instead of using anonymous module to help debugging
86
+ # IE: Jets::Router::Helpers::NamedRoutes::Generated::MainAppHelpers
87
+ basename = module_name.split('::').last.to_sym
88
+ Jets::Router::Helpers::NamedRoutes::Generated.const_set(basename, mod)
89
+
90
+ define_mounted_helper(mod, route_set)
91
+
92
+ mod
93
+ end
94
+
95
+ def define_mounted_helper(mod, route_set)
96
+ name = mod.name.split('::').last.sub('Helpers','').underscore.to_sym
97
+ return if MountedHelpers.method_defined?(name)
98
+
99
+ helpers_module = route_set.url_helpers
100
+
101
+ MountedHelpers.class_eval do
102
+ define_method "_#{name}" do
103
+ Jets::Router::Helpers::NamedRoutes::Proxy.new(self, helpers_module)
104
+ end
105
+ end
106
+
107
+ MountedHelpers.class_eval(<<-RUBY, __FILE__, __LINE__ + 1)
108
+ def #{name}
109
+ @_#{name} ||= _#{name}
110
+ end
111
+ RUBY
112
+ end
113
+
114
+ module MountedHelpers
115
+ extend ActiveSupport::Concern
116
+ end
117
+
118
+ # Contains all the mounted helpers across different
119
+ # engines and the `main_app` helper for the application.
120
+ # You can include this in your classes if you want to
121
+ # access routes for other engines.
122
+ def mounted_helpers
123
+ MountedHelpers
124
+ end
125
+
126
+ extend self
127
+ end
128
+
129
+ class NamedRouteMethod
130
+ include Jets::Controller::Decorate::ApigwStage
131
+
132
+ attr_reader :options
133
+ def initialize(route, args, context, engine_class)
134
+ @route, @args, @context, @engine_class = route, args, context, engine_class
135
+ @path = route.path # With placeholders still IE: /posts/:id
136
+ @options = normalize_options(@path, args)
137
+ end
138
+
139
+ # Normalized with format in options
140
+ # Helps to mimic Rails behavior.
141
+ # Processes extra arguments to support format and query string.
142
+ #
143
+ # post_path(post, "json", {foo: 'bar'}) => "/posts/1.json?foo=bar"
144
+ # post_path(post, {foo: 'bar'}) => "/posts/1?foo=bar"
145
+ #
146
+ def normalize_options(path, args)
147
+ args = args.dup
148
+ options = args.extract_options!
149
+ # If there is still an argument in rest, it's the format. Rails behavior.
150
+ rest = args[placeholders.size..-1]
151
+ format = rest.last
152
+ options[:format] = format if format
153
+ options
154
+ end
155
+
156
+ def path
157
+ query_string = @options.dup # make copy to modify
158
+ format = query_string.delete(:format)
159
+ query_string.delete(:action)
160
+ query_string.delete(:controller)
161
+ query_string.delete(:only_path)
162
+
163
+ path = path_with_replaced_placeholders
164
+ path = prepend_engine_mounted_at(path)
165
+ path = "#{path}.#{format}" if format
166
+ path = "#{path}?#{query_string.to_query}" unless query_string.empty?
167
+ path = add_apigw_stage(path)
168
+ path
169
+ end
170
+
171
+ # Needed for add_apigw_stage
172
+ delegate :event, :request, to: :@context
173
+
174
+ # IE: /posts/1
175
+ def path_with_replaced_placeholders
176
+ path = @path
177
+ placeholders.each_with_index do |placeholder, index|
178
+ path = path.gsub(placeholder, @args[index].to_param)
179
+ end
180
+ path
181
+ end
182
+
183
+ def placeholders
184
+ @path.scan(/:\w+/)
185
+ end
186
+
187
+ def prepend_engine_mounted_at(path)
188
+ mount = Jets::Router::EngineMount.find_by(engine: @engine_class)
189
+ if mount
190
+ path = path.delete_prefix('/')
191
+ [mount.at, path].compact.join('/')
192
+ else
193
+ path
194
+ end
195
+ end
196
+ end
197
+ end