jets 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/bin/commit_docs.sh +26 -0
- data/.circleci/config.yml +126 -0
- data/.codebuild/README.md +57 -0
- data/.codebuild/bin/jets +3 -0
- data/.codebuild/buildspec-base.yml +14 -0
- data/.codebuild/integration.sh +54 -0
- data/.codebuild/jets.postman_collection.json +323 -0
- data/.codebuild/scripts/install-docker.sh +12 -0
- data/.codebuild/scripts/install-dynamodb-local.sh +22 -0
- data/.codebuild/scripts/install-java.sh +20 -0
- data/.codebuild/scripts/install-node.sh +4 -0
- data/.gitignore +3 -0
- data/.gitmodules +9 -0
- data/.python-version +1 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +3 -0
- data/Dockerfile +16 -0
- data/Dockerfile.base +53 -0
- data/Gemfile +8 -1
- data/Gemfile.lock +132 -28
- data/LICENSE.txt +1 -1
- data/Procfile +2 -0
- data/README.md +116 -17
- data/Rakefile +6 -0
- data/buildspec.yml +18 -0
- data/exe/jets +14 -0
- data/jets.gemspec +31 -3
- data/lib/jets.rb +56 -8
- data/lib/jets/application.rb +121 -0
- data/lib/jets/application/middleware.rb +23 -0
- data/lib/jets/aws_services.rb +71 -0
- data/lib/jets/booter.rb +95 -0
- data/lib/jets/builders.rb +6 -0
- data/lib/jets/builders/code_builder.rb +431 -0
- data/lib/jets/builders/deducer.rb +73 -0
- data/lib/jets/builders/gem_replacer.rb +154 -0
- data/lib/jets/builders/handler_generator.rb +76 -0
- data/lib/jets/builders/node-hello.js +73 -0
- data/lib/jets/builders/node-shim.js +151 -0
- data/lib/jets/cfn.rb +5 -4
- data/lib/jets/cfn/ship.rb +178 -0
- data/lib/jets/cfn/status.rb +208 -0
- data/lib/jets/cfn/template_builders.rb +21 -0
- data/lib/jets/cfn/template_builders/api_gateway_builder.rb +73 -0
- data/lib/jets/cfn/template_builders/api_gateway_deployment_builder.rb +38 -0
- data/lib/jets/cfn/template_builders/base_child_builder.rb +38 -0
- data/lib/jets/cfn/template_builders/controller_builder.rb +107 -0
- data/lib/jets/cfn/template_builders/function_builder.rb +20 -0
- data/lib/jets/cfn/template_builders/function_properties.rb +6 -0
- data/lib/jets/cfn/template_builders/function_properties/base_builder.rb +106 -0
- data/lib/jets/cfn/template_builders/function_properties/node_builder.rb +12 -0
- data/lib/jets/cfn/template_builders/function_properties/python_builder.rb +12 -0
- data/lib/jets/cfn/template_builders/function_properties/ruby_builder.rb +13 -0
- data/lib/jets/cfn/template_builders/interface.rb +91 -0
- data/lib/jets/cfn/template_builders/job_builder.rb +63 -0
- data/lib/jets/cfn/template_builders/parent_builder.rb +97 -0
- data/lib/jets/cfn/template_builders/rule_builder.rb +55 -0
- data/lib/jets/cfn/template_builders/templates/minimal-stack.yml +45 -0
- data/lib/jets/cfn/template_mappers.rb +23 -0
- data/lib/jets/cfn/template_mappers/api_gateway_deployment_mapper.rb +48 -0
- data/lib/jets/cfn/template_mappers/api_gateway_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/child_mapper.rb +41 -0
- data/lib/jets/cfn/template_mappers/config_rule_mapper.rb +34 -0
- data/lib/jets/cfn/template_mappers/controller_mapper.rb +36 -0
- data/lib/jets/cfn/template_mappers/events_rule_mapper.rb +40 -0
- data/lib/jets/cfn/template_mappers/function_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/gateway_method_mapper.rb +56 -0
- data/lib/jets/cfn/template_mappers/gateway_resource_mapper.rb +62 -0
- data/lib/jets/cfn/template_mappers/job_mapper.rb +4 -0
- data/lib/jets/cfn/template_mappers/lambda_function_mapper.rb +50 -0
- data/lib/jets/cfn/template_mappers/rule_mapper.rb +5 -0
- data/lib/jets/cli.rb +180 -15
- data/lib/jets/commands.rb +22 -0
- data/lib/jets/commands/base.rb +151 -0
- data/lib/jets/commands/build.rb +186 -0
- data/lib/jets/commands/call.rb +175 -0
- data/lib/jets/commands/call/anonymous_guesser.rb +96 -0
- data/lib/jets/commands/call/autoload_guesser.rb +112 -0
- data/lib/jets/commands/call/base_guesser.rb +33 -0
- data/lib/jets/commands/call/guesser.rb +51 -0
- data/lib/jets/commands/console.rb +12 -0
- data/lib/jets/commands/db.rb +15 -0
- data/lib/jets/commands/db/environment-task.rake +3 -0
- data/lib/jets/commands/db/tasks.rb +30 -0
- data/lib/jets/commands/dbconsole.rb +131 -0
- data/lib/jets/commands/delete.rb +119 -0
- data/lib/jets/commands/deploy.rb +53 -0
- data/lib/jets/commands/dynamodb.rb +22 -0
- data/lib/jets/commands/dynamodb/migrate.rb +9 -0
- data/lib/jets/commands/dynamodb/migrator.rb +36 -0
- data/lib/jets/commands/help.rb +9 -0
- data/lib/jets/commands/help/build.md +1 -0
- data/lib/jets/commands/help/call.md +55 -0
- data/lib/jets/commands/help/console.md +4 -0
- data/lib/jets/commands/help/db/generate.md +8 -0
- data/lib/jets/commands/help/dbconsole.md +5 -0
- data/lib/jets/commands/help/delete.md +9 -0
- data/lib/jets/commands/help/deploy.md +5 -0
- data/lib/jets/commands/help/dynamodb/generate.md +50 -0
- data/lib/jets/commands/help/dynamodb/migrate.md +4 -0
- data/lib/jets/commands/help/generate.md +5 -0
- data/lib/jets/commands/help/new.md +9 -0
- data/lib/jets/commands/help/process/controller.md +6 -0
- data/lib/jets/commands/help/process/function.md +5 -0
- data/lib/jets/commands/help/process/job.md +5 -0
- data/lib/jets/commands/help/process/rule.md +5 -0
- data/lib/jets/commands/help/routes.md +3 -0
- data/lib/jets/commands/help/server.md +6 -0
- data/lib/jets/commands/help/status.md +1 -0
- data/lib/jets/commands/help/url.md +5 -0
- data/lib/jets/commands/main.rb +111 -0
- data/lib/jets/commands/markdown.rb +8 -0
- data/lib/jets/commands/markdown/creator.rb +58 -0
- data/lib/jets/commands/markdown/index.rb +27 -0
- data/lib/jets/commands/markdown/page.rb +125 -0
- data/lib/jets/commands/markdown/shell.rb +11 -0
- data/lib/jets/commands/new.rb +110 -0
- data/lib/jets/commands/rake_command.rb +61 -0
- data/lib/jets/commands/rake_tasks.rb +45 -0
- data/lib/jets/commands/sequence.rb +44 -0
- data/lib/jets/commands/stack_info.rb +30 -0
- data/lib/jets/commands/templates/skeleton/.env +2 -0
- data/lib/jets/commands/templates/skeleton/.env.development.tt +3 -0
- data/lib/jets/commands/templates/skeleton/.env.test +3 -0
- data/lib/jets/commands/templates/skeleton/.gitignore +14 -0
- data/lib/jets/commands/templates/skeleton/.jetskeep +1 -0
- data/lib/jets/commands/templates/skeleton/Gemfile.tt +27 -0
- data/lib/jets/commands/templates/skeleton/Procfile +7 -0
- data/lib/jets/commands/templates/skeleton/README.md +4 -0
- data/lib/jets/commands/templates/skeleton/Rakefile +2 -0
- data/lib/jets/commands/templates/skeleton/app/controllers/application_controller.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/helpers/application_helper.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/jobs/application_job.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/models/application_item.rb +2 -0
- data/lib/jets/commands/templates/skeleton/app/models/application_record.rb +3 -0
- data/lib/jets/commands/templates/skeleton/app/views/layouts/application.html.erb.tt +24 -0
- data/lib/jets/commands/templates/skeleton/bin/ruby_server +18 -0
- data/lib/jets/commands/templates/skeleton/bin/ruby_server.rb +2 -0
- data/lib/jets/commands/templates/skeleton/config.ru +4 -0
- data/lib/jets/commands/templates/skeleton/config/application.rb.tt +26 -0
- data/lib/jets/commands/templates/skeleton/config/database.yml.tt +27 -0
- data/lib/jets/commands/templates/skeleton/config/dynamodb.yml +25 -0
- data/lib/jets/commands/templates/skeleton/config/routes.rb +8 -0
- data/lib/jets/commands/templates/skeleton/db/.gitkeep +0 -0
- data/lib/jets/commands/templates/skeleton/public/404.html +67 -0
- data/lib/jets/commands/templates/skeleton/public/422.html +67 -0
- data/lib/jets/commands/templates/skeleton/public/500.html +66 -0
- data/lib/jets/commands/templates/skeleton/public/favicon.ico +0 -0
- data/lib/jets/commands/templates/skeleton/public/index.html.tt +79 -0
- data/lib/jets/commands/templates/skeleton/spec/controllers/posts_controller_spec.rb +18 -0
- data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-index.json +51 -0
- data/lib/jets/commands/templates/skeleton/spec/fixtures/payloads/posts-show.json +53 -0
- data/lib/jets/commands/templates/skeleton/spec/spec_helper.rb.tt +27 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/packs/application.js.tt +14 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/packs/theme.scss.tt +24 -0
- data/lib/jets/commands/templates/webpacker/app/javascript/src/jets/crud.js +87 -0
- data/lib/jets/commands/url.rb +45 -0
- data/lib/jets/commands/webpacker_template.rb +19 -0
- data/lib/jets/controller.rb +9 -0
- data/lib/jets/controller/base.rb +50 -0
- data/lib/jets/controller/callbacks.rb +43 -0
- data/lib/jets/controller/layout.rb +17 -0
- data/lib/jets/controller/params.rb +53 -0
- data/lib/jets/controller/redirection.rb +55 -0
- data/lib/jets/controller/renderers.rb +5 -0
- data/lib/jets/controller/renderers/aws_proxy_renderer.rb +69 -0
- data/lib/jets/controller/renderers/base_renderer.rb +16 -0
- data/lib/jets/controller/renderers/template_renderer.rb +107 -0
- data/lib/jets/controller/rendering.rb +80 -0
- data/lib/jets/controller/request.rb +55 -0
- data/lib/jets/core.rb +81 -0
- data/lib/jets/default/application.rb +20 -0
- data/lib/jets/dotenv.rb +37 -0
- data/lib/jets/erb.rb +51 -0
- data/lib/jets/generator.rb +40 -0
- data/lib/jets/generator/templates/erb/controller/view.html.erb +2 -0
- data/lib/jets/generator/templates/erb/scaffold/_form.html.erb +39 -0
- data/lib/jets/generator/templates/erb/scaffold/edit.html.erb +6 -0
- data/lib/jets/generator/templates/erb/scaffold/index.html.erb +29 -0
- data/lib/jets/generator/templates/erb/scaffold/new.html.erb +5 -0
- data/lib/jets/generator/templates/erb/scaffold/show.html.erb +9 -0
- data/lib/jets/generator/templates/rails/assets/javascript.js +2 -0
- data/lib/jets/generator/templates/rails/assets/stylesheet.css +4 -0
- data/lib/jets/generator/templates/rails/controller/controller.rb +13 -0
- data/lib/jets/generator/templates/rails/helper/helper.rb +4 -0
- data/lib/jets/generator/templates/rails/scaffold/scaffold.css +80 -0
- data/lib/jets/generator/templates/rails/scaffold_controller/api_controller.rb +62 -0
- data/lib/jets/generator/templates/rails/scaffold_controller/controller.rb +71 -0
- data/lib/jets/internal/app/controllers/jets/public_controller.rb +30 -0
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.py +47 -0
- data/lib/jets/internal/app/controllers/jets/public_controller/python/show.pyc +0 -0
- data/lib/jets/internal/app/controllers/jets/welcome_controller.rb +22 -0
- data/lib/jets/internal/app/controllers/jets/welcome_controller/python/index.py +24 -0
- data/lib/jets/internal/app/jobs/jets/preheat_job.rb +52 -0
- data/lib/jets/job.rb +5 -0
- data/lib/jets/job/base.rb +29 -0
- data/lib/jets/job/dsl.rb +58 -0
- data/lib/jets/job/task.rb +17 -0
- data/lib/jets/klass.rb +71 -0
- data/lib/jets/lambda.rb +18 -0
- data/lib/jets/lambda/dsl.rb +153 -0
- data/lib/jets/lambda/function.rb +29 -0
- data/lib/jets/lambda/function_constructor.rb +60 -0
- data/lib/jets/lambda/functions.rb +22 -0
- data/lib/jets/lambda/task.rb +77 -0
- data/lib/jets/naming.rb +61 -0
- data/lib/jets/pascalize.rb +30 -0
- data/lib/jets/poly_fun.rb +61 -0
- data/lib/jets/poly_fun/base_executor.rb +129 -0
- data/lib/jets/poly_fun/lambda_executor.rb +16 -0
- data/lib/jets/poly_fun/node_error.rb +8 -0
- data/lib/jets/poly_fun/node_executor.rb +54 -0
- data/lib/jets/poly_fun/python_error.rb +8 -0
- data/lib/jets/poly_fun/python_executor.rb +23 -0
- data/lib/jets/preheat.rb +72 -0
- data/lib/jets/processors.rb +4 -0
- data/lib/jets/processors/deducer.rb +54 -0
- data/lib/jets/processors/main_processor.rb +57 -0
- data/lib/jets/rails_overrides.rb +4 -0
- data/lib/jets/rails_overrides/asset_tag_helper.rb +41 -0
- data/lib/jets/rails_overrides/common_methods.rb +13 -0
- data/lib/jets/rails_overrides/rendering_helper.rb +26 -0
- data/lib/jets/rails_overrides/url_helper.rb +26 -0
- data/lib/jets/route.rb +145 -0
- data/lib/jets/router.rb +115 -0
- data/lib/jets/ruby_server.rb +91 -0
- data/lib/jets/rule.rb +5 -0
- data/lib/jets/rule/base.rb +19 -0
- data/lib/jets/rule/dsl.rb +64 -0
- data/lib/jets/rule/task.rb +44 -0
- data/lib/jets/server.rb +16 -0
- data/lib/jets/server/api_gateway.rb +39 -0
- data/lib/jets/server/lambda_aws_proxy.rb +122 -0
- data/lib/jets/server/route_matcher.rb +96 -0
- data/lib/jets/server/timing_middleware.rb +16 -0
- data/lib/jets/server/webpacker_setup.rb +7 -0
- data/lib/jets/timing.rb +65 -0
- data/lib/jets/timing/report.rb +82 -0
- data/lib/jets/util.rb +7 -12
- data/lib/jets/version.rb +1 -1
- data/support/clean +3 -0
- data/support/console +3 -0
- metadata +473 -76
- data/bin/jets +0 -14
- data/lib/jets/base_controller.rb +0 -54
- data/lib/jets/build.rb +0 -46
- data/lib/jets/build/handler_generator.rb +0 -46
- data/lib/jets/build/lambda_deducer.rb +0 -23
- data/lib/jets/build/templates/handler.js +0 -149
- data/lib/jets/build/traveling_ruby.rb +0 -133
- data/lib/jets/cfn/base.rb +0 -17
- data/lib/jets/cfn/builder.rb +0 -53
- data/lib/jets/cfn/namer.rb +0 -30
- data/lib/jets/cli/help.rb +0 -19
- data/lib/jets/command.rb +0 -25
- data/lib/jets/process.rb +0 -18
- data/lib/jets/process/base_processor.rb +0 -23
- data/lib/jets/process/controller_processor.rb +0 -36
- data/lib/jets/process/help.rb +0 -11
- data/lib/jets/process/processor_deducer.rb +0 -51
- data/lib/jets/project.rb +0 -23
- data/notes/design.md +0 -107
- data/notes/faq.md +0 -3
- data/notes/lambda_ruby_info.md +0 -34
- data/notes/traveling-ruby-packaging-jets.md +0 -26
- data/notes/traveling-ruby-packaging.md +0 -103
- data/notes/traveling-ruby-structure.md +0 -6
- data/notes/traveling-ruby.md +0 -82
- data/spec/fixtures/classes.rb +0 -5
- data/spec/fixtures/project/.gitignore +0 -3
- data/spec/fixtures/project/.ruby-version +0 -1
- data/spec/fixtures/project/Gemfile +0 -4
- data/spec/fixtures/project/Gemfile.lock +0 -23
- data/spec/fixtures/project/app/controllers/application_controller.rb +0 -2
- data/spec/fixtures/project/app/controllers/posts_controller.rb +0 -12
- data/spec/fixtures/project/bin/jets +0 -22
- data/spec/fixtures/project/config/routes.rb +0 -6
- data/spec/fixtures/project/handlers/controllers/posts.js +0 -212
- data/spec/lib/cli_spec.rb +0 -20
- data/spec/lib/jets/base_controller_spec.rb +0 -18
- data/spec/lib/jets/build/handler_generator_spec.rb +0 -20
- data/spec/lib/jets/build/lambda_deducer_spec.rb +0 -15
- data/spec/lib/jets/build_spec.rb +0 -34
- data/spec/lib/jets/cfn/builder_spec.rb +0 -18
- data/spec/lib/jets/cfn/namer_spec.rb +0 -16
- data/spec/lib/jets/process/controller_processor_spec.rb +0 -22
- data/spec/lib/jets/process/infer_spec.rb +0 -24
- data/spec/lib/jets/process_spec.rb +0 -18
- data/spec/lib/jets/project_spec.rb +0 -14
- data/spec/spec_helper.rb +0 -28
@@ -0,0 +1,96 @@
|
|
1
|
+
class Jets::Commands::Call
|
2
|
+
class AnonymousGuesser < BaseGuesser
|
3
|
+
def detect_class_name
|
4
|
+
found_path = function_paths.find do |path|
|
5
|
+
File.exist?("#{Jets.root}#{path}")
|
6
|
+
end
|
7
|
+
|
8
|
+
klass = Jets::Klass.from_path(found_path) if found_path
|
9
|
+
klass.to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_name
|
13
|
+
return @method_name if defined?(@method_name)
|
14
|
+
|
15
|
+
full_function_name = @provided_function_name.underscore
|
16
|
+
underscored_class_name = class_name.underscore
|
17
|
+
meth = full_function_name.sub("#{underscored_class_name}_","")
|
18
|
+
|
19
|
+
if meth == class_name.constantize.handler.to_s
|
20
|
+
@method_name = meth
|
21
|
+
else
|
22
|
+
@method_name_error = "#{class_name} class found but #{meth} method not found"
|
23
|
+
@method_name = nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Useful to printing out what was attempted to look up
|
28
|
+
def error_message
|
29
|
+
guess_paths = function_paths
|
30
|
+
puts "Unable to find the function to call."
|
31
|
+
if class_name and !method_name
|
32
|
+
puts @method_name_error
|
33
|
+
else
|
34
|
+
puts "Tried: #{guess_paths.join(', ')}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def function_filenames(meth=nil, primary_namespace=nil)
|
39
|
+
guesses = []
|
40
|
+
parts = meth.split('_')
|
41
|
+
|
42
|
+
if primary_namespace.nil?
|
43
|
+
guesses << meth
|
44
|
+
|
45
|
+
if parts.size == 1 # already on final_primary_namespace
|
46
|
+
return guesses # end of recursion
|
47
|
+
else
|
48
|
+
next_primary_namespace = parts.first
|
49
|
+
guesses += function_filenames(meth, next_primary_namespace) # start of recursion
|
50
|
+
return guesses # return early
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
next_meth = meth.sub("#{primary_namespace}_", '')
|
55
|
+
next_parts = next_meth.split('_')
|
56
|
+
|
57
|
+
# Takes the next_parts and creates guesses with the parts joined by '/'
|
58
|
+
# with the primary_namespace prepended. So if next_parts is
|
59
|
+
# ["long", "name", "function"] and primary_namespace is "complex"
|
60
|
+
#
|
61
|
+
# guesses that get added:
|
62
|
+
#
|
63
|
+
# [
|
64
|
+
# "complex/long_name_function",
|
65
|
+
# "complex/long/name_function",
|
66
|
+
# "complex/long/name/function",
|
67
|
+
# ]
|
68
|
+
n = next_parts.size + 1
|
69
|
+
next_parts.size.times do |i|
|
70
|
+
namespace = i == 0 ? nil : next_parts[0..i-1].join('/')
|
71
|
+
class_path = next_parts[i..-1].join('_')
|
72
|
+
guesses << [primary_namespace, namespace, class_path].compact.join('/')
|
73
|
+
end
|
74
|
+
|
75
|
+
final_primary_namespace = parts[0..-2].join('_')
|
76
|
+
if primary_namespace == final_primary_namespace
|
77
|
+
return guesses # end of recursion
|
78
|
+
else
|
79
|
+
namespace_size = parts.size - next_parts.size
|
80
|
+
next_primary_namespace = parts[0..namespace_size].join('_')
|
81
|
+
guesses += function_filenames(meth, next_primary_namespace)
|
82
|
+
return guesses
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def function_paths
|
87
|
+
# drop the last word for starting filename
|
88
|
+
starting_filename = @provided_function_name.underscore.split('_')[0..-2].join('_')
|
89
|
+
filenames = function_filenames(starting_filename)
|
90
|
+
filenames.map do |name|
|
91
|
+
"app/functions/#{name}.rb"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
class Jets::Commands::Call
|
2
|
+
class AutoloadGuesser < BaseGuesser
|
3
|
+
def detect_class_name
|
4
|
+
guess_classes.each do |class_name_guess|
|
5
|
+
begin
|
6
|
+
class_name_guess.constantize
|
7
|
+
return class_name_guess # if there's no error then the class is found
|
8
|
+
rescue NameError
|
9
|
+
if out_of_guesses(class_name_guess)
|
10
|
+
# puts "Unable to find the class to call. Tried guessing: #{guess_classes[0..-2].join(', ')}."
|
11
|
+
# raise # re-raise NameError for now but maybe better to provide
|
12
|
+
# a custom error class, so we can rescue it and provide a
|
13
|
+
# friendly message to the user
|
14
|
+
else
|
15
|
+
next
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def method_name
|
24
|
+
return @method_name if defined?(@method_name)
|
25
|
+
return nil unless class_name
|
26
|
+
|
27
|
+
underscored_class_name = class_name.underscore.gsub('/','_')
|
28
|
+
underscored_function_name = @provided_function_name.underscore.gsub('/','_')
|
29
|
+
meth = underscored_function_name.sub(underscored_class_name, '')
|
30
|
+
meth = meth.sub(/^[-_]/,'') # remove leading _ or -
|
31
|
+
|
32
|
+
if class_name.constantize.tasks.map(&:meth).include?(meth.to_sym)
|
33
|
+
@method_name = meth
|
34
|
+
else
|
35
|
+
@method_name_error ="#{class_name} class found but #{meth} method not found"
|
36
|
+
@method_name = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# Useful to printing out what was attempted to look up
|
41
|
+
def error_message
|
42
|
+
guesses = guess_classes
|
43
|
+
puts "Unable to find the function to call."
|
44
|
+
if class_name and !method_name
|
45
|
+
puts @method_name_error
|
46
|
+
else
|
47
|
+
puts "Tried: #{guesses.join(', ')}"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def process_type
|
52
|
+
if @provided_function_name =~ /[-_]controller/
|
53
|
+
"controller"
|
54
|
+
elsif @provided_function_name =~ /[-_]job/
|
55
|
+
"job"
|
56
|
+
elsif @provided_function_name =~ /[-_]rule/
|
57
|
+
"rule"
|
58
|
+
else
|
59
|
+
"function"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def process_type_pattern
|
64
|
+
Regexp.new("[-_]#{process_type}[-_](.*)")
|
65
|
+
end
|
66
|
+
|
67
|
+
# Strips the action because we dont want it to guess the class name
|
68
|
+
# So:
|
69
|
+
# admin-related-pages => admin_related_pages_controller
|
70
|
+
def underscored_name
|
71
|
+
# strip action and concidentally the _controller_ string
|
72
|
+
name = @provided_function_name.sub(process_type_pattern,'')
|
73
|
+
# Ensure _controller or _job at the end except for simple functions
|
74
|
+
unless process_type == "function"
|
75
|
+
name = name.gsub('-','_') + "_#{process_type}"
|
76
|
+
end
|
77
|
+
name
|
78
|
+
end
|
79
|
+
|
80
|
+
# Guesses autoload paths.
|
81
|
+
#
|
82
|
+
# underscored_name: admin_related_pages_controller
|
83
|
+
# Returns:
|
84
|
+
# [
|
85
|
+
# "admin_related_pages_controller",
|
86
|
+
# "admin/related_pages_controller",
|
87
|
+
# "admin_related/pages_controller",
|
88
|
+
# "admin_related_pages/controller",
|
89
|
+
# ]
|
90
|
+
def autoload_paths
|
91
|
+
guesses = []
|
92
|
+
|
93
|
+
parts = underscored_name.split('_')
|
94
|
+
parts.size.times do |i|
|
95
|
+
namespace = i == 0 ? nil : parts[0..i-1].join('/')
|
96
|
+
class_path = parts[i..-1].join('_')
|
97
|
+
guesses << [namespace, class_path].compact.join('/')
|
98
|
+
end
|
99
|
+
|
100
|
+
guesses
|
101
|
+
end
|
102
|
+
|
103
|
+
def guess_classes
|
104
|
+
autoload_paths.map(&:classify)
|
105
|
+
end
|
106
|
+
|
107
|
+
def out_of_guesses(guess)
|
108
|
+
guess.include?("::Controller")
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Subclasses of BaseGuessor must implement interface:
|
2
|
+
# detect_class_name
|
3
|
+
# method_name
|
4
|
+
# error_message
|
5
|
+
#
|
6
|
+
class Jets::Commands::Call
|
7
|
+
class BaseGuesser
|
8
|
+
# provided_function_name:
|
9
|
+
# admin/related_pages_controller-list_all
|
10
|
+
# admin-related-pages-controller-list-all
|
11
|
+
def initialize(provided_function_name)
|
12
|
+
@provided_function_name = provided_function_name
|
13
|
+
end
|
14
|
+
|
15
|
+
def class_name
|
16
|
+
return @class_name if @detection_ran
|
17
|
+
|
18
|
+
@class_name = detect_class_name
|
19
|
+
@detection_ran = true
|
20
|
+
@class_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def function_name
|
24
|
+
# Strip the project namespace if the user has accidentally added it
|
25
|
+
# Since we're going to automatically add it no matter what at the end
|
26
|
+
# and dont want the namespace to be included twice
|
27
|
+
@provided_function_name = @provided_function_name.sub("#{Jets.config.project_namespace}-", "")
|
28
|
+
|
29
|
+
code_path = class_name.underscore.gsub('/','-')
|
30
|
+
function_name = [Jets.config.project_namespace, code_path, method_name].join('-')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "active_support/core_ext/hash"
|
2
|
+
require "active_support/core_ext/object"
|
3
|
+
|
4
|
+
# Guesser transforms the user provided function name to the actual lambda
|
5
|
+
# function name.
|
6
|
+
#
|
7
|
+
# Allow for variety of different inputs to work:
|
8
|
+
# Simple:
|
9
|
+
# admin/pages_controller-index => admin-pages_controller-index
|
10
|
+
# admin-pages_controller-index => admin-pages_controller-index
|
11
|
+
#
|
12
|
+
# Complex, requires detecting the right class name:
|
13
|
+
# admin/related_pages_controller-list_all
|
14
|
+
# admin-related-pages-controller-list-all
|
15
|
+
#
|
16
|
+
# All still result in: admin-related_pages_controller-index
|
17
|
+
#
|
18
|
+
# The detection process follows. Given worse case:
|
19
|
+
# admin-related-pages-controller-list-all
|
20
|
+
#
|
21
|
+
# Know that the action comes after controller, try:
|
22
|
+
# AdminRelatedPagesController
|
23
|
+
# Admin::RelatedPagesController <= found stop guessing
|
24
|
+
#
|
25
|
+
# admin/related_pages_controller <= underscored
|
26
|
+
# admin/related_pages_controller-list_all <= add action back on
|
27
|
+
# admin-related_pages_controller-list_all <= gsub / - DONE
|
28
|
+
#
|
29
|
+
# Now we're at a point where we can start guessing
|
30
|
+
# function_name = detect_function_name(function_name)
|
31
|
+
class Jets::Commands::Call
|
32
|
+
class Guesser
|
33
|
+
delegate :class_name, :method_name, :error_message, :function_name,
|
34
|
+
to: :delegate_guesser
|
35
|
+
|
36
|
+
# Example of provided_function_name:
|
37
|
+
# admin/related_pages_controller-list_all
|
38
|
+
# admin-related-pages-controller-list-all
|
39
|
+
def initialize(provided_function_name)
|
40
|
+
@provided_function_name = provided_function_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def delegate_guesser
|
44
|
+
@delegate_guesser ||= if @provided_function_name =~ /[-_](controller|job|rule)/
|
45
|
+
AutoloadGuesser.new(@provided_function_name)
|
46
|
+
else
|
47
|
+
AnonymousGuesser.new(@provided_function_name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class Jets::Commands::Console
|
2
|
+
def self.run
|
3
|
+
puts Jets::Booter.message
|
4
|
+
|
5
|
+
# Thanks: https://mutelight.org/bin-console
|
6
|
+
require "irb"
|
7
|
+
require "irb/completion"
|
8
|
+
|
9
|
+
ARGV.clear # https://stackoverflow.com/questions/33070092/irb-start-not-starting/33136762
|
10
|
+
IRB.start
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
require "rails/generators/active_record/migration/migration_generator"
|
3
|
+
|
4
|
+
module Jets::Commands
|
5
|
+
class Db < Jets::Commands::Base
|
6
|
+
autoload :Tasks, 'jets/commands/db/tasks'
|
7
|
+
|
8
|
+
desc "generate", "Creates a migration to change a db table"
|
9
|
+
long_desc Help.text('db:generate')
|
10
|
+
def generate(*args)
|
11
|
+
generator = ActiveRecord::Generators::MigrationGenerator.new(args)
|
12
|
+
generator.create_migration_file
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "rails"
|
2
|
+
require "active_record"
|
3
|
+
require "recursive-open-struct"
|
4
|
+
|
5
|
+
class Jets::Commands::Db::Tasks
|
6
|
+
# Ugly but it loads ActiveRecord database tasks
|
7
|
+
def self.load!
|
8
|
+
# Jets.boot # Jets.boot here screws up jets -h, the db_config doesnt seem to match exactly
|
9
|
+
# but seems to be working anyway.
|
10
|
+
db_configs = Jets.application.config.database
|
11
|
+
ActiveRecord::Tasks::DatabaseTasks.database_configuration = db_configs
|
12
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths = ["db/migrate"]
|
13
|
+
|
14
|
+
# Need to mock out the usage of Rails.application in:
|
15
|
+
# activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb
|
16
|
+
Rails.application = RecursiveOpenStruct.new(
|
17
|
+
config: {
|
18
|
+
paths: {
|
19
|
+
db: ["db"],
|
20
|
+
}
|
21
|
+
},
|
22
|
+
paths: {
|
23
|
+
"db/migrate": ["db/migrate"]
|
24
|
+
}
|
25
|
+
)
|
26
|
+
load "active_record/railties/databases.rake"
|
27
|
+
|
28
|
+
load File.expand_path("../environment-task.rake", __FILE__)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# Thanks: Rails dbconsole_command.rb
|
2
|
+
module Jets::Commands
|
3
|
+
class Dbconsole
|
4
|
+
def self.start(*args)
|
5
|
+
new(*args).start
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize(options = {})
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def start
|
13
|
+
ENV["RAILS_ENV"] ||= @options[:environment] || environment
|
14
|
+
|
15
|
+
case config["adapter"]
|
16
|
+
when /^(jdbc)?mysql/
|
17
|
+
args = {
|
18
|
+
"host" => "--host",
|
19
|
+
"port" => "--port",
|
20
|
+
"socket" => "--socket",
|
21
|
+
"username" => "--user",
|
22
|
+
"encoding" => "--default-character-set",
|
23
|
+
"sslca" => "--ssl-ca",
|
24
|
+
"sslcert" => "--ssl-cert",
|
25
|
+
"sslcapath" => "--ssl-capath",
|
26
|
+
"sslcipher" => "--ssl-cipher",
|
27
|
+
"sslkey" => "--ssl-key"
|
28
|
+
}.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
|
29
|
+
|
30
|
+
if config["password"] && @options["include_password"]
|
31
|
+
args << "--password=#{config['password']}"
|
32
|
+
elsif config["password"] && !config["password"].to_s.empty?
|
33
|
+
args << "-p"
|
34
|
+
end
|
35
|
+
|
36
|
+
args << config["database"]
|
37
|
+
|
38
|
+
find_cmd_and_exec(["mysql", "mysql5"], *args)
|
39
|
+
|
40
|
+
when /^postgres|^postgis/
|
41
|
+
ENV["PGUSER"] = config["username"] if config["username"]
|
42
|
+
ENV["PGHOST"] = config["host"] if config["host"]
|
43
|
+
ENV["PGPORT"] = config["port"].to_s if config["port"]
|
44
|
+
ENV["PGPASSWORD"] = config["password"].to_s if config["password"] && @options["include_password"]
|
45
|
+
find_cmd_and_exec("psql", config["database"])
|
46
|
+
|
47
|
+
when "sqlite3"
|
48
|
+
args = []
|
49
|
+
|
50
|
+
args << "-#{@options['mode']}" if @options["mode"]
|
51
|
+
args << "-header" if @options["header"]
|
52
|
+
args << File.expand_path(config["database"], Jets.root)
|
53
|
+
|
54
|
+
find_cmd_and_exec("sqlite3", *args)
|
55
|
+
|
56
|
+
when "oracle", "oracle_enhanced"
|
57
|
+
logon = ""
|
58
|
+
|
59
|
+
if config["username"]
|
60
|
+
logon = config["username"]
|
61
|
+
logon << "/#{config['password']}" if config["password"] && @options["include_password"]
|
62
|
+
logon << "@#{config['database']}" if config["database"]
|
63
|
+
end
|
64
|
+
|
65
|
+
find_cmd_and_exec("sqlplus", logon)
|
66
|
+
|
67
|
+
when "sqlserver"
|
68
|
+
args = []
|
69
|
+
|
70
|
+
args += ["-D", "#{config['database']}"] if config["database"]
|
71
|
+
args += ["-U", "#{config['username']}"] if config["username"]
|
72
|
+
args += ["-P", "#{config['password']}"] if config["password"]
|
73
|
+
|
74
|
+
if config["host"]
|
75
|
+
host_arg = "#{config['host']}"
|
76
|
+
host_arg << ":#{config['port']}" if config["port"]
|
77
|
+
args += ["-S", host_arg]
|
78
|
+
end
|
79
|
+
|
80
|
+
find_cmd_and_exec("sqsh", *args)
|
81
|
+
|
82
|
+
else
|
83
|
+
abort "Unknown command-line client for #{config['database']}."
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def config
|
88
|
+
@config ||= begin
|
89
|
+
if configurations[environment].blank?
|
90
|
+
raise ActiveRecord::AdapterNotSpecified, "'#{environment}' database is not configured. Available configuration: #{configurations.inspect}"
|
91
|
+
else
|
92
|
+
configurations[environment]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def environment
|
98
|
+
Jets.env.to_s
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
def configurations # :doc:
|
103
|
+
db_config = Jets.application.config.database
|
104
|
+
ActiveRecord::Base.configurations = db_config
|
105
|
+
ActiveRecord::Base.configurations
|
106
|
+
end
|
107
|
+
|
108
|
+
def find_cmd_and_exec(commands, *args) # :doc:
|
109
|
+
commands = Array(commands)
|
110
|
+
|
111
|
+
dirs_on_path = ENV["PATH"].to_s.split(File::PATH_SEPARATOR)
|
112
|
+
unless (ext = RbConfig::CONFIG["EXEEXT"]).empty?
|
113
|
+
commands = commands.map { |cmd| "#{cmd}#{ext}" }
|
114
|
+
end
|
115
|
+
|
116
|
+
full_path_command = nil
|
117
|
+
found = commands.detect do |cmd|
|
118
|
+
dirs_on_path.detect do |path|
|
119
|
+
full_path_command = File.join(path, cmd)
|
120
|
+
File.file?(full_path_command) && File.executable?(full_path_command)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
if found
|
125
|
+
exec full_path_command, *args
|
126
|
+
else
|
127
|
+
abort("Couldn't find database client: #{commands.join(', ')}. Check your $PATH and try again.")
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|