jets 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +3 -3
  4. data/lib/jets/application.rb +6 -6
  5. data/lib/jets/booter.rb +4 -4
  6. data/lib/jets/builders/code_builder.rb +5 -5
  7. data/lib/jets/builders/shim_vars/app.rb +2 -2
  8. data/lib/jets/cfn/upload.rb +2 -2
  9. data/lib/jets/commands/build.rb +4 -4
  10. data/lib/jets/commands/call.rb +1 -1
  11. data/lib/jets/commands/call/anonymous_guesser.rb +1 -1
  12. data/lib/jets/commands/db/tasks.rb +1 -1
  13. data/lib/jets/commands/deploy.rb +1 -1
  14. data/lib/jets/commands/dynamodb/migrator.rb +1 -1
  15. data/lib/jets/commands/import/cheatsheet.rb +1 -1
  16. data/lib/jets/commands/import/sequence.rb +1 -1
  17. data/lib/jets/commands/runner.rb +1 -1
  18. data/lib/jets/commands/upgrade.rb +7 -7
  19. data/lib/jets/controller/base.rb +9 -0
  20. data/lib/jets/controller/rendering.rb +1 -1
  21. data/lib/jets/controller/rendering/rack_renderer.rb +3 -3
  22. data/lib/jets/core.rb +4 -8
  23. data/lib/jets/db.rb +2 -2
  24. data/lib/jets/inflections.rb +1 -1
  25. data/lib/jets/lambda/function_constructor.rb +2 -7
  26. data/lib/jets/middleware/default_stack.rb +1 -1
  27. data/lib/jets/overrides/rails/asset_tag_helper.rb +1 -1
  28. data/lib/jets/poly_fun/base_executor.rb +1 -1
  29. data/lib/jets/poly_fun/node_executor.rb +1 -1
  30. data/lib/jets/processors/deducer.rb +1 -1
  31. data/lib/jets/rack_server.rb +1 -1
  32. data/lib/jets/resource/api_gateway/cors.rb +8 -8
  33. data/lib/jets/resource/api_gateway/method.rb +11 -2
  34. data/lib/jets/router.rb +4 -2
  35. data/lib/jets/stack.rb +3 -3
  36. data/lib/jets/stack/function.rb +1 -1
  37. data/lib/jets/stack/main/dsl.rb +1 -1
  38. data/lib/jets/tmp_loader.rb +1 -1
  39. data/lib/jets/turbo/database_yaml.rb +2 -2
  40. data/lib/jets/version.rb +1 -1
  41. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 35b8d7335c644339643a2c97c53d4e320967f43761949eeda46909b33f140776
4
- data.tar.gz: 49d1cd847f9423e21d899107534a81c5d51c368999d60cefe70a89b39b434b9c
3
+ metadata.gz: 75898252d0d7ef29286086cca3e59433da914f67bd9b42e66927beb9bd4b72e0
4
+ data.tar.gz: 6d535ce82983daee425f36a670fcca6d7d2650fce3714fa196dbdd4be685a8c5
5
5
  SHA512:
6
- metadata.gz: fa356ebc6da237b6046e44bf6307af25bfce9fec40746346b52d7a4bc774cdd25ef6a449573c14b3fed5b514ffddc8327c0c7d4fbdc65040abdd7a5749642271
7
- data.tar.gz: 99b185e759621461ce327b014c51345fe11843732395b79d3604216c60ef668a56ba0004e14ef68faf7151dee2379ae81939084e03e4f6b6bb58cc28e716fcad
6
+ metadata.gz: e2b412fdc2e7271eb998359bc501d76539d683d332ef8545c6ed5d1572bcd833ec2c963d115ba0bbbaa2662e922c4b88760884cae1a3424446097b6a812d932c
7
+ data.tar.gz: f57fa1a144e8b4328abfebc181d3bf7fd8df4dbed084ae7882eeee734ab1fa4557cd9d1d0733f115b675e7a9ad723b8b3199b1fe290d65177eabd115569b4261
data/CHANGELOG.md CHANGED
@@ -3,6 +3,11 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.6.2]
7
+ - #165 remove always trailing slash from Jets.root
8
+ - #166 fix cors headers
9
+ - #167 controller authorization_type declaration
10
+
6
11
  ## [1.6.1]
7
12
  - #162 from patchkit-net/feature/spec_helpers
8
13
  - #163 from tongueroo/spec-helpers
data/Gemfile.lock CHANGED
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.6.1)
14
+ jets (1.6.2)
15
15
  activerecord (~> 5.2.1)
16
16
  activesupport (~> 5.2.1)
17
17
  aws-sdk-apigateway
@@ -66,7 +66,7 @@ GEM
66
66
  tzinfo (~> 1.1)
67
67
  arel (9.0.0)
68
68
  aws-eventstream (1.0.1)
69
- aws-partitions (1.135.0)
69
+ aws-partitions (1.136.0)
70
70
  aws-sdk-apigateway (1.23.0)
71
71
  aws-sdk-core (~> 3, >= 3.39.0)
72
72
  aws-sigv4 (~> 1.0)
@@ -107,7 +107,7 @@ GEM
107
107
  crass (1.0.4)
108
108
  diff-lcs (1.3)
109
109
  dotenv (2.6.0)
110
- dynomite (1.2.1)
110
+ dynomite (1.2.2)
111
111
  activesupport
112
112
  aws-sdk-dynamodb
113
113
  erubi (1.8.0)
@@ -110,7 +110,7 @@ class Jets::Application
110
110
  def parse_project_name
111
111
  return ENV['JETS_PROJECT_NAME'] if ENV['JETS_PROJECT_NAME'] # override
112
112
 
113
- lines = IO.readlines("#{Jets.root}config/application.rb")
113
+ lines = IO.readlines("#{Jets.root}/config/application.rb")
114
114
  project_name_line = lines.find { |l| l =~ /config\.project_name.*=/ }
115
115
  project_name_line.gsub(/.*=/,'').strip.gsub(/["']/,'') # project_name
116
116
  end
@@ -126,7 +126,7 @@ class Jets::Application
126
126
  end
127
127
 
128
128
  def eval_app_config
129
- app_config = "#{Jets.root}config/application.rb"
129
+ app_config = "#{Jets.root}/config/application.rb"
130
130
  load app_config # use load instead of require so reload_configs! works
131
131
  end
132
132
 
@@ -138,7 +138,7 @@ class Jets::Application
138
138
  end
139
139
 
140
140
  def load_environments_config
141
- env_file = "#{Jets.root}config/environments/#{Jets.env}.rb"
141
+ env_file = "#{Jets.root}/config/environments/#{Jets.env}.rb"
142
142
  if File.exist?(env_file)
143
143
  code = IO.read(env_file)
144
144
  instance_eval(code)
@@ -179,7 +179,7 @@ class Jets::Application
179
179
  # app/shared/resources
180
180
  def default_autoload_paths
181
181
  paths = []
182
- Dir.glob("#{Jets.root}app/*").each do |p|
182
+ Dir.glob("#{Jets.root}/app/*").each do |p|
183
183
  p.sub!('./','')
184
184
  paths << p unless exclude_autoload_path?(p)
185
185
  end
@@ -277,7 +277,7 @@ class Jets::Application
277
277
  config.database = {}
278
278
 
279
279
  Jets::Dotenv.load!
280
- database_yml = "#{Jets.root}config/database.yml"
280
+ database_yml = "#{Jets.root}/config/database.yml"
281
281
  if File.exist?(database_yml)
282
282
  text = Jets::Erb.result(database_yml)
283
283
  db_config = YAML.load(text)
@@ -295,7 +295,7 @@ class Jets::Application
295
295
  end
296
296
 
297
297
  def load_routes
298
- routes_file = "#{Jets.root}config/routes.rb"
298
+ routes_file = "#{Jets.root}/config/routes.rb"
299
299
  require routes_file if File.exist?(routes_file)
300
300
  end
301
301
 
data/lib/jets/booter.rb CHANGED
@@ -45,7 +45,7 @@ class Jets::Booter
45
45
  end
46
46
 
47
47
  def app_initializers
48
- Dir.glob("#{Jets.root}config/initializers/**/*").each do |path|
48
+ Dir.glob("#{Jets.root}/config/initializers/**/*").each do |path|
49
49
  load path
50
50
  end
51
51
  end
@@ -83,7 +83,7 @@ class Jets::Booter
83
83
  # config/database.yml exists.
84
84
  # Dynomite handles connecting to the clients lazily.
85
85
  def setup_db
86
- return unless File.exist?("#{Jets.root}config/database.yml")
86
+ return unless File.exist?("#{Jets.root}/config/database.yml")
87
87
 
88
88
  db_configs = Jets.application.config.database
89
89
  # DatabaseTasks.database_configuration for db:create db:migrate tasks
@@ -106,7 +106,7 @@ class Jets::Booter
106
106
 
107
107
  # Cannot call this for the jets new
108
108
  def confirm_jets_project!
109
- unless File.exist?("#{Jets.root}config/application.rb")
109
+ unless File.exist?("#{Jets.root}/config/application.rb")
110
110
  puts "It does not look like you are running this command within a jets project. Please confirm that you are in a jets project and try again.".color(:red)
111
111
  exit 1
112
112
  end
@@ -117,7 +117,7 @@ class Jets::Booter
117
117
  end
118
118
 
119
119
  def check_config_ru!
120
- config_ru = File.read("#{Jets.root}config.ru")
120
+ config_ru = File.read("#{Jets.root}/config.ru")
121
121
  unless config_ru.include?("Jets.boot")
122
122
  puts 'The config.ru file is missing Jets.boot. Please add Jets.boot after require "jets"'.color(:red)
123
123
  puts "This was changed as made in Jets v1.1.0."
@@ -181,7 +181,7 @@ class Jets::Builders
181
181
  return unless webpacker_included?
182
182
 
183
183
  sh("yarn install")
184
- webpack_command = File.exist?("#{Jets.root}bin/webpack") ?
184
+ webpack_command = File.exist?("#{Jets.root}/bin/webpack") ?
185
185
  "bin/webpack" :
186
186
  `which webpack`.strip
187
187
  sh "JETS_ENV=#{Jets.env} #{webpack_command}"
@@ -195,7 +195,7 @@ class Jets::Builders
195
195
 
196
196
  # Checking this way because when using jets standalone for Afterburner mode we don't want to run into
197
197
  # bundler gem collisions. TODO: figure out the a better way to handle the collisions.
198
- lines = IO.readlines("#{Jets.root}Gemfile")
198
+ lines = IO.readlines("#{Jets.root}/Gemfile")
199
199
  lines.detect { |l| l =~ /webpacker/ }
200
200
  end
201
201
 
@@ -227,13 +227,13 @@ class Jets::Builders
227
227
  # rake is available in both rails 4 and 5. rails command only in 5
228
228
  command = "bundle exec rake assets:#{cmd} --trace"
229
229
  command = "RAILS_ENV=#{Jets.env} #{command}" unless Jets.env.development?
230
- sh("cd #{jets_root}rack && #{command}")
230
+ sh("cd #{jets_root}/rack && #{command}")
231
231
  end
232
232
 
233
233
  # Rudimentary rails detection
234
234
  # Duplicated in builders/reconfigure_rails.rb
235
235
  def rails?
236
- config_ru = "#{Jets.root}rack/config.ru"
236
+ config_ru = "#{Jets.root}/rack/config.ru"
237
237
  return false unless File.exist?(config_ru)
238
238
  !IO.readlines(config_ru).grep(/Rails.application/).empty?
239
239
  end
@@ -243,7 +243,7 @@ class Jets::Builders
243
243
  # Another way of checking is loading a rails console and checking Rails.application.config.api_only
244
244
  # Using this way for simplicity.
245
245
  def rails_api?
246
- config_app = "#{Jets.root}rack/config/application.rb"
246
+ config_app = "#{Jets.root}/rack/config/application.rb"
247
247
  return false unless File.exist?(config_app)
248
248
  !IO.readlines(config_app).grep(/config.api_only.*=.*true/).empty?
249
249
  end
@@ -24,13 +24,13 @@ module Jets::Builders::ShimVars
24
24
  end
25
25
 
26
26
  def full(path)
27
- path = "#{Jets.root}#{path}" unless path.starts_with?("/")
27
+ path = "#{Jets.root}/#{path}" unless path.starts_with?("/")
28
28
  path
29
29
  end
30
30
 
31
31
  def relative(path)
32
32
  full_path = full(path)
33
- full_path.sub(Jets.root.to_s, "")
33
+ full_path.sub("#{Jets.root}/", "")
34
34
  .sub(/.*internal\/app/, "app")
35
35
 
36
36
  end
@@ -70,7 +70,7 @@ class Jets::Cfn
70
70
  end
71
71
 
72
72
  def upload_asset_folder(folder)
73
- expression = "#{Jets.root}#{folder}/**/*"
73
+ expression = "#{Jets.root}/#{folder}/**/*"
74
74
  group_size = 10
75
75
  Dir.glob(expression).each_slice(group_size) do |paths|
76
76
  threads = []
@@ -95,7 +95,7 @@ class Jets::Cfn
95
95
  end
96
96
 
97
97
  def s3_key(full_path)
98
- relative_path = full_path.sub(Jets.root.to_s, '')
98
+ relative_path = full_path.sub("#{Jets.root}/", '')
99
99
  "jets/#{relative_path}"
100
100
  end
101
101
 
@@ -109,12 +109,12 @@ module Jets::Commands
109
109
  # TODO: rework code so that Dir.pwd does not have to be in tmp_code for build to work.
110
110
  def self.app_files
111
111
  paths = []
112
- expression = "#{Jets.root}app/**/**/*.rb"
112
+ expression = "#{Jets.root}/app/**/**/*.rb"
113
113
  Dir.glob(expression).each do |path|
114
114
  return false unless File.file?(path)
115
115
  next unless app_file?(path)
116
116
 
117
- relative_path = path.sub(Jets.root.to_s, '')
117
+ relative_path = path.sub("#{Jets.root}/", '')
118
118
  # Rids of the Jets.root at beginning
119
119
  paths << relative_path
120
120
  end
@@ -128,12 +128,12 @@ module Jets::Commands
128
128
 
129
129
  def self.shared_files
130
130
  paths = []
131
- expression = "#{Jets.root}app/**/**/*.rb"
131
+ expression = "#{Jets.root}/app/**/**/*.rb"
132
132
  Dir.glob(expression).each do |path|
133
133
  return false unless File.file?(path)
134
134
  next unless path.include?("app/shared/resources")
135
135
 
136
- relative_path = path.sub(Jets.root.to_s, '')
136
+ relative_path = path.sub("#{Jets.root}/", '')
137
137
  # Rids of the Jets.root at beginning
138
138
  paths << relative_path
139
139
  end
@@ -115,7 +115,7 @@ class Jets::Commands::Call
115
115
 
116
116
  def load_event_from_file(text)
117
117
  path = text.gsub('file://','')
118
- path = "#{Jets.root}#{path}" unless path[0..0] == '/'
118
+ path = "#{Jets.root}/#{path}" unless path[0..0] == '/'
119
119
  unless File.exist?(path)
120
120
  puts "File #{path} does not exist. Are you sure the file exists?".color(:red)
121
121
  exit
@@ -2,7 +2,7 @@ class Jets::Commands::Call
2
2
  class AnonymousGuesser < BaseGuesser
3
3
  def detect_class_name
4
4
  found_path = function_paths.find do |path|
5
- File.exist?("#{Jets.root}#{path}")
5
+ File.exist?("#{Jets.root}/#{path}")
6
6
  end
7
7
 
8
8
  klass = Jets::Klass.from_path(found_path) if found_path
@@ -11,7 +11,7 @@ class Jets::Commands::Db::Tasks
11
11
  db_configs = Jets.application.config.database
12
12
  ActiveRecord::Tasks::DatabaseTasks.database_configuration = db_configs
13
13
  ActiveRecord::Tasks::DatabaseTasks.migrations_paths = ["db/migrate"]
14
- ActiveRecord::Tasks::DatabaseTasks.seed_loader = Seeder.new("#{Jets.root}db/seeds.rb")
14
+ ActiveRecord::Tasks::DatabaseTasks.seed_loader = Seeder.new("#{Jets.root}/db/seeds.rb")
15
15
 
16
16
  # Need to mock out the usage of Rails.application in:
17
17
  # activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb
@@ -39,7 +39,7 @@ module Jets::Commands
39
39
  end
40
40
 
41
41
  def check_dev_mode
42
- if File.exist?("#{Jets.root}dev.mode")
42
+ if File.exist?("#{Jets.root}/dev.mode")
43
43
  puts "The dev.mode file exists. Please removed it and run bundle update before you deploy.".color(:red)
44
44
  exit 1
45
45
  end
@@ -17,7 +17,7 @@ class Jets::Commands::Dynamodb::Migrator
17
17
  end
18
18
 
19
19
  def migrate
20
- path = "#{Jets.root}#{@path}"
20
+ path = "#{Jets.root}/#{@path}"
21
21
  unless File.exist?(path)
22
22
  puts "Unable to find the migration file: #{path}"
23
23
  exit 1 unless ENV['TEST']
@@ -11,7 +11,7 @@ class Jets::Commands::Import
11
11
  def create
12
12
  path = File.expand_path("./templates/", File.dirname(__FILE__)) + "/submodules-cheatsheet.md"
13
13
  basename = File.basename(path)
14
- dest = "#{Jets.root}#{basename}"
14
+ dest = "#{Jets.root}/#{basename}"
15
15
  cheatsheet = Jets::Erb.result(path, cheatsheet_vars)
16
16
  FileUtils.mkdir_p(File.dirname(dest))
17
17
  IO.write(dest, cheatsheet)
@@ -84,7 +84,7 @@ class Jets::Commands::Import
84
84
  end
85
85
 
86
86
  def rack_folder
87
- "#{Jets.root}rack"
87
+ "#{Jets.root}/rack"
88
88
  end
89
89
  end
90
90
  end
@@ -4,7 +4,7 @@ class Jets::Commands::Runner
4
4
 
5
5
  if code =~ %r{^file://}
6
6
  path = code.sub('file://', '')
7
- full_path = "#{Jets.root}#{path}"
7
+ full_path = "#{Jets.root}/#{path}"
8
8
  if File.exist?(full_path)
9
9
  code = IO.read(full_path)
10
10
  else
@@ -24,7 +24,7 @@ module Jets::Commands
24
24
  puts "path #{path}"
25
25
  Dir.glob("#{path}/*").each do |src|
26
26
  config_file = "config/environments/#{File.basename(src)}"
27
- dest = "#{Jets.root}#{config_file}"
27
+ dest = "#{Jets.root}/#{config_file}"
28
28
 
29
29
  puts "src #{src}"
30
30
  puts "dest #{dest}"
@@ -37,7 +37,7 @@ module Jets::Commands
37
37
  end
38
38
 
39
39
  def update_routes
40
- routes_file = "#{Jets.root}config/routes.rb"
40
+ routes_file = "#{Jets.root}/config/routes.rb"
41
41
  return unless File.exist?(routes_file)
42
42
 
43
43
  lines = IO.readlines(routes_file)
@@ -58,7 +58,7 @@ module Jets::Commands
58
58
  end
59
59
 
60
60
  def update_mode_setting
61
- application_file = "#{Jets.root}config/application.rb"
61
+ application_file = "#{Jets.root}/config/application.rb"
62
62
  lines = IO.readlines(application_file)
63
63
  deprecated_code = 'config.api_generator'
64
64
  return unless lines.detect { |l| l.include?(deprecated_code) }
@@ -78,19 +78,19 @@ module Jets::Commands
78
78
  end
79
79
 
80
80
  def update_config_ru
81
- config_ru = File.read("#{Jets.root}config.ru")
81
+ config_ru = File.read("#{Jets.root}/config.ru")
82
82
  return if config_ru.include?("Jets.boot")
83
83
 
84
84
  src = File.expand_path("templates/skeleton/config.ru", File.dirname(__FILE__))
85
- dest = "#{Jets.root}config.ru"
85
+ dest = "#{Jets.root}/config.ru"
86
86
  puts "Update: config.ru"
87
87
  FileUtils.cp(src, dest)
88
88
  end
89
89
 
90
90
  def remove_ruby_lazy_load
91
- app_config = "#{Jets.root}config/application.rb"
91
+ app_config = "#{Jets.root}/config/application.rb"
92
92
  remove_ruby_lazy_load_for(app_config)
93
- Dir.glob("#{Jets.root}config/environments/*.rb").each do |env_config|
93
+ Dir.glob("#{Jets.root}/config/environments/*.rb").each do |env_config|
94
94
  remove_ruby_lazy_load_for(env_config)
95
95
  end
96
96
  end
@@ -90,5 +90,14 @@ class Jets::Controller
90
90
  self.internal_controller
91
91
  end
92
92
  end
93
+
94
+ class_attribute :auth_type
95
+ def self.authorization_type(value=nil)
96
+ if !value.nil?
97
+ self.auth_type = value
98
+ else
99
+ self.auth_type
100
+ end
101
+ end
93
102
  end
94
103
  end
@@ -47,7 +47,7 @@ class Jets::Controller
47
47
  end
48
48
 
49
49
  def default_layout
50
- application_layout_exist = !Dir.glob("#{Jets.root}app/views/layouts/application*").empty?
50
+ application_layout_exist = !Dir.glob("#{Jets.root}/app/views/layouts/application*").empty?
51
51
  "application" if application_layout_exist
52
52
  end
53
53
 
@@ -215,7 +215,7 @@ module Jets::Controller::Rendering
215
215
  end
216
216
  end
217
217
 
218
- ActionController::Base.append_view_path("#{Jets.root}app/views")
218
+ ActionController::Base.append_view_path("#{Jets.root}/app/views")
219
219
 
220
220
  setup_webpacker if Jets.webpacker?
221
221
  end
@@ -223,10 +223,10 @@ module Jets::Controller::Rendering
223
223
  # Does not include ApplicationHelper, will include ApplicationHelper explicitly first.
224
224
  def find_app_helper_classes
225
225
  klasses = []
226
- expression = "#{Jets.root}app/helpers/**/*"
226
+ expression = "#{Jets.root}/app/helpers/**/*"
227
227
  Dir.glob(expression).each do |path|
228
228
  next unless File.file?(path)
229
- class_name = path.sub("#{Jets.root}app/helpers/","").sub(/\.rb/,'')
229
+ class_name = path.sub("#{Jets.root}/app/helpers/","").sub(/\.rb/,'')
230
230
  unless class_name == "application_helper"
231
231
  klasses << class_name.classify.constantize # autoload
232
232
  end
data/lib/jets/core.rb CHANGED
@@ -18,14 +18,10 @@ module Jets::Core
18
18
  Jets::Booter.boot!(options)
19
19
  end
20
20
 
21
- # Ensures trailing slash
22
- # Useful for appending a './' in front of a path or leaving it alone.
23
- # Returns: '/path/with/trailing/slash/' or './'
24
21
  def root
25
22
  # Do not memoize this method. Turbo mode can change it
26
23
  root = ENV['JETS_ROOT'].to_s
27
- root = '.' if root == ''
28
- root = "#{root}/" unless root.ends_with?('/')
24
+ root = Dir.pwd if root == ''
29
25
  Pathname.new(root)
30
26
  end
31
27
 
@@ -110,14 +106,14 @@ module Jets::Core
110
106
 
111
107
  # Eager load user's application
112
108
  def eager_load_app
113
- Dir.glob("#{Jets.root}app/**/*.rb").select do |path|
109
+ Dir.glob("#{Jets.root}/app/**/*.rb").select do |path|
114
110
  next if !File.file?(path) or path =~ %r{/javascript/} or path =~ %r{/views/}
115
111
  next if path.include?('app/functions') || path.include?('app/shared/functions') || path.include?('app/internal/functions')
116
112
 
117
113
  class_name = path
118
114
  .sub(/\.rb$/,'') # remove .rb
119
115
  .sub(%{^\./},'') # remove ./
120
- .sub(Jets.root.to_s,'')
116
+ .sub("#{Jets.root}/",'')
121
117
  .sub(%r{app/shared/\w+/},'') # remove shared/resources or shared/extensions
122
118
  .sub(%r{app/\w+/},'') # remove app/controllers or app/jobs etc
123
119
  class_name = class_name.classify
@@ -150,7 +146,7 @@ module Jets::Core
150
146
  end
151
147
 
152
148
  def rack?
153
- path = "#{Jets.root}rack"
149
+ path = "#{Jets.root}/rack"
154
150
  File.exist?(path) || File.symlink?(path)
155
151
  end
156
152
 
data/lib/jets/db.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  module Jets::Db ; end
2
2
 
3
3
  # Thanks: https://makandracards.com/makandra/42521-detecting-if-a-ruby-gem-is-loaded
4
- if File.exist?("#{Jets.root}config/database.yml")
4
+ if File.exist?("#{Jets.root}/config/database.yml")
5
5
  require "active_record"
6
6
  specs = Gem.loaded_specs
7
7
  require "mysql2" if specs.key?('mysql2')
8
8
  require "pg" if specs.key?('pg')
9
9
  end
10
10
 
11
- if File.exist?("#{Jets.root}config/dynamodb.yml")
11
+ if File.exist?("#{Jets.root}/config/dynamodb.yml")
12
12
  specs = Gem.loaded_specs
13
13
  specs.key?('dynomite')
14
14
  require "dynomite" if specs.key?('dynomite')
@@ -24,7 +24,7 @@ module Jets
24
24
 
25
25
  # User defined custom inflections
26
26
  def custom
27
- path = "#{Jets.root}config/inflections.yml"
27
+ path = "#{Jets.root}/config/inflections.yml"
28
28
  File.exist?(path) ? YAML.load_file(path) : {}
29
29
  end
30
30
  end
@@ -29,12 +29,7 @@
29
29
  module Jets::Lambda
30
30
  class FunctionConstructor
31
31
  def initialize(code_path)
32
- @code_path = full(code_path)
33
- end
34
-
35
- def full(path)
36
- path = "#{Jets.root}#{path}" unless path.include?(Jets.root.to_s)
37
- path
32
+ @code_path = "#{Jets.root}/#{code_path}"
38
33
  end
39
34
 
40
35
  def build
@@ -48,7 +43,7 @@ module Jets::Lambda
48
43
  # For anonymous classes method_added during task registration contains ""
49
44
  # for the class name. We adjust it here.
50
45
  def adjust_tasks(klass)
51
- class_name = @code_path.sub(/.*\/functions\//,'').sub(/\.rb$/, '')
46
+ class_name = @code_path.to_s.sub(/.*\/functions\//,'').sub(/\.rb$/, '')
52
47
  class_name = class_name.classify
53
48
  klass.tasks.each do |task|
54
49
  task.class_name = class_name
@@ -27,7 +27,7 @@ module Jets::Middleware
27
27
  # Different check for middleware because we need webpacker helpers for url helpers.
28
28
  # But we dont want to actually serve via webpacker middleware when running on AWS.
29
29
  # By this time the url helpers are serving assets out of s3.
30
- return if File.exist?("#{Jets.root}config/disable-webpacker-middleware.txt") # created as part of `jets deploy`
30
+ return if File.exist?("#{Jets.root}/config/disable-webpacker-middleware.txt") # created as part of `jets deploy`
31
31
  require "jets/controller/middleware/webpacker_setup"
32
32
  middleware.use Webpacker::DevServerProxy
33
33
  end
@@ -106,7 +106,7 @@ private
106
106
 
107
107
  def s3_public
108
108
  # s3_base_url.txt is created as part of the build process
109
- s3_base_url = IO.read("#{Jets.root}config/s3_base_url.txt").strip
109
+ s3_base_url = IO.read("#{Jets.root}/config/s3_base_url.txt").strip
110
110
  "#{s3_base_url}/public"
111
111
  end
112
112
  memoize :s3_public
@@ -41,7 +41,7 @@ class Jets::PolyFun
41
41
  internal = app_class.respond_to?(:internal) && app_class.internal
42
42
  src = internal ?
43
43
  "#{File.expand_path("../internal", File.dirname(__FILE__))}/#{@task.poly_src_path}" :
44
- "#{Jets.root}#{@task.poly_src_path}"
44
+ "#{Jets.root}/#{@task.poly_src_path}"
45
45
  dest = "#{@temp_dir}/#{@task.poly_src_path}"
46
46
 
47
47
  FileUtils.mkdir_p(File.dirname(dest))
@@ -18,7 +18,7 @@ class Jets::PolyFun
18
18
 
19
19
  # https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-handler.html
20
20
  def async_syntax?
21
- app_path = Jets.root + @task.handler_path.sub('handlers/', 'app/')
21
+ app_path = "#{Jets.root}/" + @task.handler_path.sub('handlers/', 'app/')
22
22
  source_code = IO.read(app_path)
23
23
  source_code.match(/=\s*async.*\(/)
24
24
  end
@@ -21,7 +21,7 @@ class Jets::Processors::Deducer
21
21
  # Input: @handler_path: handlers/jobs/hard_job.rb
22
22
  # Output: #{Jets.root/app/jobs/hard_job.rb
23
23
  def path
24
- Jets.root.to_s + @handler_path.sub("handlers", "app") + ".rb"
24
+ @handler_path.sub("handlers", "app") + ".rb"
25
25
  end
26
26
 
27
27
  # process_type is key. It can be either "controller" or "job". It is used to
@@ -74,7 +74,7 @@ module Jets
74
74
  end
75
75
 
76
76
  def rack_project
77
- "#{Jets.root}rack"
77
+ "#{Jets.root}/rack"
78
78
  end
79
79
  end
80
80
  end
@@ -15,10 +15,10 @@ module Jets::Resource::ApiGateway
15
15
  method_responses: [{
16
16
  status_code: '200',
17
17
  response_parameters: {
18
- "method.response.header.Access-Control-AllowOrigin": true,
19
- "method.response.header.Access-Control-AllowHeaders": true,
20
- "method.response.header.Access-Control-AllowMethods": true,
21
- "method.response.header.Access-Control-AllowCredentials": true,
18
+ "method.response.header.Access-Control-Allow-Origin": true,
19
+ "method.response.header.Access-Control-Allow-Headers": true,
20
+ "method.response.header.Access-Control-Allow-Methods": true,
21
+ "method.response.header.Access-Control-Allow-Credentials": true,
22
22
  },
23
23
  response_models: {},
24
24
  }],
@@ -31,10 +31,10 @@ module Jets::Resource::ApiGateway
31
31
  integration_responses: [{
32
32
  status_code: '200',
33
33
  response_parameters: {
34
- "method.response.header.Access-Control-AllowOrigin": "'#{allow_origin}'",
35
- "method.response.header.Access-Control-AllowHeaders": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'",
36
- "method.response.header.Access-Control-AllowMethods": "'OPTIONS,GET'",
37
- "method.response.header.Access-Control-AllowCredentials": "'false'",
34
+ "method.response.header.Access-Control-Allow-Origin": "'#{allow_origin}'",
35
+ "method.response.header.Access-Control-Allow-Headers": "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent'",
36
+ "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,GET'",
37
+ "method.response.header.Access-Control-Allow-Credentials": "'false'",
38
38
  },
39
39
  response_templates: {
40
40
  "application/json": '',
@@ -65,8 +65,17 @@ module Jets::Resource::ApiGateway
65
65
  private
66
66
 
67
67
  def authorization_type
68
- type = @route.authorization_type || Jets.config.api.authorization_type
69
- type.upcase
68
+ type = @route.authorization_type ||
69
+ controller_auth_type ||
70
+ Jets.config.api.authorization_type
71
+ type.to_s.upcase
72
+ end
73
+
74
+ def controller_auth_type
75
+ controller_name = @route.to.split('#').first
76
+ controller = "#{controller_name}_controller".classify.constantize
77
+ # Already handles inheritance via class_attribute
78
+ controller.authorization_type
70
79
  end
71
80
 
72
81
  def resource_id
data/lib/jets/router.rb CHANGED
@@ -84,8 +84,10 @@ module Jets
84
84
  end
85
85
 
86
86
  # root "posts#index"
87
- def root(to)
88
- @routes << Route.new(path: '', to: to, method: :get, root: true)
87
+ def root(to, options={})
88
+ default = {path: '', to: to, method: :get, root: true}
89
+ options = default.merge(options)
90
+ @routes << Route.new(options)
89
91
  end
90
92
 
91
93
  # Useful for creating API Gateway Resources
data/lib/jets/stack.rb CHANGED
@@ -72,13 +72,13 @@ module Jets
72
72
  end
73
73
 
74
74
  def eager_load_shared_resources!
75
- ActiveSupport::Dependencies.autoload_paths += ["#{Jets.root}app/shared/resources"]
76
- Dir.glob("#{Jets.root}app/shared/resources/**/*.rb").select do |path|
75
+ ActiveSupport::Dependencies.autoload_paths += ["#{Jets.root}/app/shared/resources"]
76
+ Dir.glob("#{Jets.root}/app/shared/resources/**/*.rb").select do |path|
77
77
  next if !File.file?(path) or path =~ %r{/javascript/} or path =~ %r{/views/}
78
78
 
79
79
  class_name = path
80
80
  .sub(/\.rb$/,'') # remove .rb
81
- .sub(Jets.root.to_s,'') # remove ./
81
+ .sub("#{Jets.root}/",'') # remove ./
82
82
  .sub(%r{app/shared/resources/},'') # remove app/shared/resources/
83
83
  .classify
84
84
  class_name.constantize # use constantize instead of require so dont have to worry about order.
@@ -40,7 +40,7 @@ class Jets::Stack
40
40
  attributes = @template.values.first
41
41
  handler = attributes['Properties']['Handler']
42
42
  search_expression = handler.split('.')[0..-2].join('.') + '.*'
43
- search_expression.sub('handlers/shared/', "#{Jets.root}app/shared/")
43
+ search_expression.sub('handlers/shared/', "#{Jets.root}/app/shared/")
44
44
  end
45
45
 
46
46
  # Relative path
@@ -17,7 +17,7 @@ class Jets::Stack
17
17
  end
18
18
 
19
19
  def self.included(base)
20
- base_path = "#{Jets.root}app/shared/extensions"
20
+ base_path = "#{Jets.root}/app/shared/extensions"
21
21
  ActiveSupport::Dependencies.autoload_paths += [base_path]
22
22
 
23
23
  Dir.glob("#{base_path}/**/*.rb").each do |path|
@@ -7,7 +7,7 @@ module Jets
7
7
  end
8
8
 
9
9
  def initialize(yaml_path=nil)
10
- yaml_path ||= "#{Jets.root}handlers/data.yml"
10
+ yaml_path ||= "#{Jets.root}/handlers/data.yml"
11
11
  @data = YAML.load_file(yaml_path)
12
12
  @s3_bucket = @data['s3_bucket']
13
13
  @rack_zip = @data['rack_zip']
@@ -1,7 +1,7 @@
1
1
  class Jets::Turbo
2
2
  class DatabaseYaml
3
3
  def reconfigure
4
- current_yaml = "#{Jets.root}rack/config/database.yml"
4
+ current_yaml = "#{Jets.root}/rack/config/database.yml"
5
5
  return unless File.exist?(current_yaml)
6
6
 
7
7
  vars = {}
@@ -27,7 +27,7 @@ class Jets::Turbo
27
27
  if !current_database[env]['database'].include?('<%') # already has ERB
28
28
  vars["database_#{env}"] = current_database[env]['database']
29
29
  else
30
- lines = IO.readlines("#{Jets.root}rack/config/application.rb")
30
+ lines = IO.readlines("#{Jets.root}/rack/config/application.rb")
31
31
  module_line = lines.find { |l| l =~ /^module / }
32
32
  app_module = module_line.gsub(/^module /,'').strip
33
33
  app_name = app_module.underscore
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.6.1"
2
+ VERSION = "1.6.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord