jets 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2caf68ff06e809fb88b76bdfb381aca29ce7f8540989dd775da2b288351b7f28
4
- data.tar.gz: 566b69b388a24b2d110cd522c410b4be939a4a8e38f2771a69618228ffd8009c
3
+ metadata.gz: a0f899e409f74150cb787d1e943bc952061eac3750eff304d6e7d657fb982b77
4
+ data.tar.gz: 182a1f82f57e0f4a7afd89924f6a90b60dcc1be053b4c0e3ca1cb645030c54d3
5
5
  SHA512:
6
- metadata.gz: c76ed8e21738349e7052c01d27bce581afd66a8c32980532e1a2c63fcf597336bb6deabcdea64db75a880b4e055516d33271e543dcae9196b74a22e95685be9c
7
- data.tar.gz: c753ef10f2c180de87e82305b68195ff591a53f1b3b497144df7ddf43aeb7bce3d779183172984d068458a070512b072920b85986ad3354a5384ee5dead40c09
6
+ metadata.gz: c1f6ad92079f026224861aeda73d5552834119dc59504c00ef1fbba5480c817305e3e517372eedf48684d6145fad2ed8bda610dc3223798eb4aa2c65f3a10b23
7
+ data.tar.gz: 31f71bf99f2499d3ba8ac00e298abba20a09b9235f8cfd20f400ae005204e07e24271a925be6abc2e728a6e0162f5ea44cbaee1248e11dd2089b397ef82661e8
data/.gitignore CHANGED
@@ -17,5 +17,5 @@ tmp
17
17
 
18
18
  spec/fixtures/project/handlers
19
19
  .codebuild/definitions
20
- demo1*
20
+ demo*
21
21
  /html
@@ -3,6 +3,9 @@
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.0.6]
7
+ - method fixes: account for inheritance and private keyword #57
8
+
6
9
  ## [1.0.5]
7
10
  - change config.lambdagems to config.gems
8
11
  - friendly info message when yarn is not installed
data/Gemfile CHANGED
@@ -7,7 +7,7 @@ gemspec
7
7
  # TODO: Only require webpacker in Gemfile of project if possible.
8
8
  # Need both because of jets/application.rb and jets/webpacker/middleware_setup.rb
9
9
  group :development, :test do
10
- gem "pg", "=0.21"
10
+ gem "mysql2", "~> 0.5.2"
11
11
  gem "webpacker", git: "https://github.com/tongueroo/webpacker.git", branch: "jets"
12
12
  gem "rspec_junit_formatter"
13
13
  end
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.0.5)
14
+ jets (1.0.6)
15
15
  actionpack (>= 5.2.1)
16
16
  actionview (>= 5.2.1)
17
17
  activerecord (>= 5.2.1)
@@ -118,9 +118,9 @@ GEM
118
118
  mimemagic (0.3.2)
119
119
  mini_portile2 (2.3.0)
120
120
  minitest (5.11.3)
121
+ mysql2 (0.5.2)
121
122
  nokogiri (1.8.5)
122
123
  mini_portile2 (~> 2.3.0)
123
- pg (0.21.0)
124
124
  rack (2.0.5)
125
125
  rack-proxy (0.6.5)
126
126
  rack
@@ -167,7 +167,7 @@ DEPENDENCIES
167
167
  bundler
168
168
  byebug
169
169
  jets!
170
- pg (= 0.21)
170
+ mysql2 (~> 0.5.2)
171
171
  rake
172
172
  rspec
173
173
  rspec_junit_formatter
data/README.md CHANGED
@@ -19,7 +19,7 @@ It is key to understand AWS Lambda and API Gateway to understand Jets conceptual
19
19
  * **AWS Lambda** is Functions as a Service. It allows you to upload and run functions without worrying about the underlying infrastructure.
20
20
  * **API Gateway** is the routing layer for Lambda. It is used to route REST URL endpoints to Lambda functions.
21
21
 
22
- The official documentation is at: [Ruby on Jets](http://rubyonjets.com).
22
+ The official documentation is at [Ruby on Jets](http://rubyonjets.com).
23
23
 
24
24
  Refer to the official docs for more info, but here's a quick intro.
25
25
 
@@ -60,7 +60,7 @@ class PostsController < ApplicationController
60
60
  end
61
61
  ```
62
62
 
63
- Jets creates Lambda functions each the public method in your controller.
63
+ Jets creates Lambda functions for each public method in your controller.
64
64
 
65
65
  ### Jets Routing
66
66
 
@@ -86,15 +86,15 @@ end
86
86
 
87
87
  Test your API Gateway endpoints with curl or postman. Note, replace the URL endpoint with the one that is created:
88
88
 
89
- $ curl -s "https://quabepiu80.execute-api.us-east-1.amazonaws.com/dev/posts" | jq .
90
- {
91
- "hello": "world",
92
- "action": "index"
93
- }
89
+ $ curl -s "https://quabepiu80.execute-api.us-east-1.amazonaws.com/dev/posts" | jq .
90
+ {
91
+ "hello": "world",
92
+ "action": "index"
93
+ }
94
94
 
95
95
  ### Jets Jobs
96
96
 
97
- A Jets job handles asynchrous background jobs performed outside of the web request/response cycle. Here's an example:
97
+ A Jets job handles asynchronous background jobs performed outside of the web request/response cycle. Here's an example:
98
98
 
99
99
  app/jobs/hard_job.rb:
100
100
 
@@ -118,7 +118,7 @@ end
118
118
 
119
119
  You can test your application with a local server that mimics API Gateway: [Jets Local Server](http://rubyonjets.com/docs/local-server/). Once ready, deploying to AWS Lambda is a single command.
120
120
 
121
- jets deploy
121
+ jets deploy
122
122
 
123
123
  After deployment, you can test the Lambda functions with the AWS Lambda console or the CLI.
124
124
 
@@ -132,7 +132,7 @@ Here's a [Live Demo](https://demo.rubyonjets.com/posts) of the quintessential CR
132
132
 
133
133
  ### Rails Support
134
134
 
135
- Jets [Mega Mode](http://rubyonjets.com/docs/megamode/) provides Rails support with little effort. This allows you run a Rails application on AWS Lambda. Refer to the [Rails Support](http://rubyonjets.com/docs/rails-support/) docs for more info.
135
+ Jets [Mega Mode](http://rubyonjets.com/docs/megamode/) provides Rails support with little effort. This allows you to run a Rails application on AWS Lambda. Refer to the [Rails Support](http://rubyonjets.com/docs/rails-support/) docs for more info.
136
136
 
137
137
  ### More Info
138
138
 
@@ -141,7 +141,6 @@ For more documentation, check out the official docs: [Ruby on Jets](http://rubyo
141
141
  * [Quick Start](http://rubyonjets.com/quick-start/)
142
142
  * [Local Jets Server](http://rubyonjets.com/docs/local-server/)
143
143
  * [REPL Console](http://rubyonjets.com/docs/repl-console/)
144
- * [Jets Call](http://rubyonjets.com/docs/jets-call/)
145
144
  * [Project Structure](http://rubyonjets.com/project-structure/)
146
145
  * [App Configuration](http://rubyonjets.com/app-config/)
147
146
  * [Database Support](http://rubyonjets.com/docs/database-support/)
@@ -8,6 +8,8 @@ To run unit tests:
8
8
 
9
9
  ## Integration
10
10
 
11
+ These commands run all from the jets repo itself. The demo folder has been added to the `.gitignore`.
12
+
11
13
  ### Locally
12
14
 
13
15
  To run the integration tests locally, you need to create a new Jets CRUD project and start the server:
@@ -38,4 +40,9 @@ Then you can deploy the jets app and test it on real AWS Lambda.
38
40
 
39
41
  Run the remote integration script:
40
42
 
41
- spec/integration/remote.sh
43
+ BASE_URL=xxx spec/integration/remote.sh
44
+
45
+ Example:
46
+
47
+ BASE_URL=https://wb5dcjc09a.execute-api.us-west-2.amazonaws.com/dev spec/integration/remote.sh
48
+
@@ -50,10 +50,10 @@ class Jets::Cfn
50
50
  end
51
51
 
52
52
  def upload_assets
53
- puts "Uploading modified public assets to S3."
53
+ puts "Checking for modified public assets and uploading to S3."
54
54
  start_time = Time.now
55
55
  upload_public_assets
56
- puts "Time to upload public assets to s3: #{pretty_time(Time.now-start_time).colorize(:green)}"
56
+ puts "Time for public assets to s3: #{pretty_time(Time.now-start_time).colorize(:green)}"
57
57
  end
58
58
 
59
59
  def upload_public_assets
@@ -79,6 +79,7 @@ class Jets::Commands::Base < Thor
79
79
  def namespaced_commands
80
80
  eager_load!
81
81
  subclasses.map do |klass|
82
+ # This all_tasks is part of Thor not the lambda/dsl.rb
82
83
  klass.all_tasks.keys.map do |task_name|
83
84
  klass = klass.to_s.sub('Jets::Commands::','')
84
85
  namespace = klass =~ /^Main/ ? nil : klass.underscore.gsub('/',':')
@@ -13,6 +13,8 @@ module Jets::Lambda::Dsl
13
13
 
14
14
  included do
15
15
  class << self
16
+ extend Memoist
17
+
16
18
  def class_properties(options=nil)
17
19
  if options
18
20
  @class_properties ||= {}
@@ -259,12 +261,70 @@ module Jets::Lambda::Dsl
259
261
  # Returns the all tasks for this class with their method names as keys.
260
262
  #
261
263
  # ==== Returns
262
- # OrderedHash:: An ordered hash with tasks names as keys and JobTask
264
+ # OrderedHash:: An ordered hash with tasks names as keys and Task
263
265
  # objects as values.
264
266
  #
265
267
  def all_tasks
266
268
  @all_tasks ||= ActiveSupport::OrderedHash.new
267
269
  end
270
+ # Do not call all tasks outside this class, instead use: tasks or lambda functions
271
+ private :all_tasks
272
+
273
+ # Goes up the class inheritance chain to build the tasks.
274
+ #
275
+ # Example heirarchy:
276
+ #
277
+ # Jets::Lambda::Functions > Jets::Controller::Base > ApplicationController ...
278
+ # > PostsController > ChildPostsController
279
+ #
280
+ # Do not include tasks from the direct subclasses of Jets::Lambda::Functions
281
+ # because those classes are abstract. Dont want those methods to be included.
282
+ def find_all_tasks(public: true)
283
+ klass = self
284
+ direct_subclasses = Jets::Lambda::Functions.subclasses
285
+ lookup = []
286
+
287
+ # Go up class inheritance and builds lookup structure in memory
288
+ until direct_subclasses.include?(klass)
289
+ lookup << klass.send(:all_tasks) # one place we want to call private all_tasks method
290
+ klass = klass.superclass
291
+ end
292
+ merged_tasks = ActiveSupport::OrderedHash.new
293
+ # Go back down the class inheritance chain in reverse order and merge the tasks
294
+ lookup.reverse.each do |tasks_hash|
295
+ # tasks_hash is a result of all_tasks. Example: PostsController.all_tasks
296
+ merged_tasks.merge!(tasks_hash)
297
+ end
298
+
299
+ # The cfn builders required the right final child class to build the lambda functions correctly.
300
+ merged_tasks.each do |meth, task|
301
+ # Override the class name for the cfn builders
302
+ task = task.clone # do not stomp over current tasks since things are usually looked by reference
303
+ task.instance_variable_set(:@class_name, self.name)
304
+ merged_tasks[meth] = task
305
+ end
306
+
307
+ # Methods can be made private with the :private keyword after the method has been defined.
308
+ # To account for this, loop back thorugh all the methods and check if the method is indeed public.
309
+ tasks = ActiveSupport::OrderedHash.new
310
+ merged_tasks.each do |meth, task|
311
+ if public
312
+ tasks[meth] = task if task.public_meth?
313
+ else
314
+ tasks[meth] = task unless task.public_meth?
315
+ end
316
+ end
317
+ tasks
318
+ end
319
+ memoize :find_all_tasks
320
+
321
+ def all_public_tasks
322
+ find_all_tasks(public: true)
323
+ end
324
+
325
+ def all_private_tasks
326
+ find_all_tasks(public: false)
327
+ end
268
328
 
269
329
  # Returns the tasks for this class in Array form.
270
330
  #
@@ -272,13 +332,7 @@ module Jets::Lambda::Dsl
272
332
  # Array of task objects
273
333
  #
274
334
  def tasks
275
- all_tasks.values
276
- end
277
-
278
- # Used in Jets::Cfn::Builders::Interface#build
279
- # Overridden in rule/dsl.rb
280
- def build?
281
- !tasks.empty?
335
+ all_public_tasks.values
282
336
  end
283
337
 
284
338
  # The public methods defined in the project app class ulimately become
@@ -287,7 +341,13 @@ module Jets::Lambda::Dsl
287
341
  # Example return value:
288
342
  # [:index, :new, :create, :show]
289
343
  def lambda_functions
290
- all_tasks.keys
344
+ all_public_tasks.keys
345
+ end
346
+
347
+ # Used in Jets::Cfn::Builders::Interface#build
348
+ # Overridden in rule/dsl.rb
349
+ def build?
350
+ !tasks.empty?
291
351
  end
292
352
 
293
353
  # Polymorphic support
@@ -18,5 +18,17 @@ module Jets::Lambda
18
18
 
19
19
  include Dsl # At the end so methods like event, context and method
20
20
  # do not trigger method_added
21
+
22
+ class << self
23
+ # Tracking subclasses because it helps with Lambda::Dsl#find_all_tasks
24
+ def subclasses
25
+ @subclasses ||= []
26
+ end
27
+
28
+ def inherited(base)
29
+ super
30
+ self.subclasses << base if base.name
31
+ end
32
+ end
21
33
  end
22
34
  end
@@ -14,14 +14,25 @@ class Jets::Lambda::Task
14
14
  @replacements = options[:replacements] || {} # added to baseline replacements
15
15
  end
16
16
 
17
- def build_function_iam?
18
- !!(@iam_policy || @managed_iam_policy)
19
- end
20
-
21
17
  def name
22
18
  @meth
23
19
  end
24
20
 
21
+ def public_meth?
22
+ # For anonymous classes (app/functions/hello.rb) the class name will be blank.
23
+ # These types of classes are treated specially and has only one handler method
24
+ # that is registered. So we know it is public.
25
+ return true if @class_name.nil? || @class_name == ''
26
+
27
+ klass = @class_name.constantize
28
+ public_methods = klass.public_instance_methods
29
+ public_methods.include?(meth.to_sym)
30
+ end
31
+
32
+ def build_function_iam?
33
+ !!(@iam_policy || @managed_iam_policy)
34
+ end
35
+
25
36
  @@lang_exts = {
26
37
  ruby: '.rb',
27
38
  python: '.py',
@@ -17,6 +17,8 @@ module Jets
17
17
  end
18
18
 
19
19
  def run(event, context={})
20
+ check_private_method!
21
+
20
22
  if task.lang == :ruby
21
23
  # controller = PostsController.new(event, content)
22
24
  # resp = controller.edit
@@ -54,8 +56,20 @@ module Jets
54
56
  end
55
57
 
56
58
  def task
57
- @app_class.all_tasks[@app_meth]
59
+ task = @app_class.all_public_tasks[@app_meth]
60
+ # Provider user a better error message to user than a nil failure.
61
+ unless task
62
+ raise "Unable to find #{@app_class}##{@app_meth}"
63
+ end
64
+ task
58
65
  end
59
66
  memoize :task
67
+
68
+ def check_private_method!
69
+ private_detected = @app_class.all_private_tasks.keys.include?(@app_meth)
70
+ return unless private_detected # Ok to continue
71
+
72
+ raise "The #{@app_class}##{@app_meth} is a private method. Unable to call it unless it is public"
73
+ end
60
74
  end
61
75
  end
@@ -58,7 +58,7 @@ class Jets::Route
58
58
  rescue NameError
59
59
  return false
60
60
  end
61
- controller_class.all_tasks.keys.include?(action_name.to_sym)
61
+ controller_class.lambda_functions.include?(action_name.to_sym)
62
62
  end
63
63
 
64
64
  # Extracts the path parameters from the actual path
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.0.5"
2
+ VERSION = "1.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen