lam 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +16 -8
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -3
- data/Gemfile.lock +107 -0
- data/Guardfile +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -17
- data/Rakefile +4 -0
- data/bin/lam +14 -0
- data/bin/lamb +14 -0
- data/lam.gemspec +18 -20
- data/lib/lam.rb +10 -1
- data/lib/lam/base_controller.rb +54 -0
- data/lib/lam/build.rb +43 -0
- data/lib/lam/build/handler_generator.rb +34 -0
- data/lib/lam/build/lambda_deducer.rb +47 -0
- data/lib/lam/build/templates/handler.js +156 -0
- data/lib/lam/build/traveling_ruby.rb +108 -0
- data/lib/lam/cli.rb +23 -0
- data/lib/lam/cli/help.rb +19 -0
- data/lib/lam/command.rb +25 -0
- data/lib/lam/process.rb +18 -0
- data/lib/lam/process/base_processor.rb +23 -0
- data/lib/lam/process/controller_processor.rb +36 -0
- data/lib/lam/process/help.rb +11 -0
- data/lib/lam/process/processor_deducer.rb +52 -0
- data/lib/lam/util.rb +13 -0
- data/lib/lam/version.rb +1 -1
- data/notes/design.md +43 -0
- data/notes/traveling-ruby-packaging-lam.md +26 -0
- data/notes/traveling-ruby-packaging.md +103 -0
- data/notes/traveling-ruby.md +82 -0
- data/spec/fixtures/project/.gitignore +3 -0
- data/spec/fixtures/project/.ruby-version +1 -0
- data/spec/fixtures/project/Gemfile +4 -0
- data/spec/fixtures/project/Gemfile.lock +35 -0
- data/spec/fixtures/project/app/controllers/application_controller.rb +2 -0
- data/spec/fixtures/project/app/controllers/posts_controller.rb +12 -0
- data/spec/fixtures/project/bin/lam +22 -0
- data/spec/fixtures/project/handlers/controllers/posts.js +156 -0
- data/spec/lib/cli_spec.rb +20 -0
- data/spec/lib/lam/base_controller_spec.rb +18 -0
- data/spec/lib/lam/build/lambda_deducer_spec.rb +20 -0
- data/spec/lib/lam/build_spec.rb +29 -0
- data/spec/lib/lam/process/controller_processor_spec.rb +22 -0
- data/spec/lib/lam/process/infer_spec.rb +24 -0
- data/spec/lib/lam/process_spec.rb +18 -0
- data/spec/spec_helper.rb +25 -0
- metadata +191 -21
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 816d582bb2efa679feebdd2cbff48d276f4d3ed6
|
4
|
+
data.tar.gz: 023a055c5c5565ca00c6533fcfd8ec6857da300b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca24b7941f7ce3a6664d1db1b92fb4a8de478ae095c2371a6f88b3c77e76a6ea5217c781eed2854e5be454006d76cc02e1421bbfc3874f6a50b3dca4e36d8a96
|
7
|
+
data.tar.gz: 50b794a91cfdeb6d48d3fb146c03b2c8565958b609e66fb8d2d6b74b143323b937ae951d8a86540eea02ce9b0ad87c5ccd86a6d94787afad54bcfd8af8220cd4
|
data/.gitignore
CHANGED
@@ -1,8 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
InstalledFiles
|
7
|
+
_yardoc
|
8
|
+
coverage
|
9
|
+
doc/
|
10
|
+
lib/bundler/man
|
11
|
+
pkg
|
12
|
+
rdoc
|
13
|
+
spec/reports
|
14
|
+
test/tmp
|
15
|
+
test/version_tmp
|
16
|
+
tmp
|
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in lam.gemspec
|
3
|
+
# Specify your gem dependencies in lam.gemspec
|
6
4
|
gemspec
|
5
|
+
|
6
|
+
gem "codeclimate-test-reporter", group: :test, require: nil
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
lam (0.0.1)
|
5
|
+
activesupport
|
6
|
+
colorize
|
7
|
+
hashie
|
8
|
+
thor
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
activesupport (5.1.4)
|
14
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
i18n (~> 0.7)
|
16
|
+
minitest (~> 5.1)
|
17
|
+
tzinfo (~> 1.1)
|
18
|
+
byebug (9.1.0)
|
19
|
+
codeclimate-test-reporter (1.0.8)
|
20
|
+
simplecov (<= 0.13)
|
21
|
+
coderay (1.1.2)
|
22
|
+
colorize (0.8.1)
|
23
|
+
concurrent-ruby (1.0.5)
|
24
|
+
diff-lcs (1.3)
|
25
|
+
docile (1.1.5)
|
26
|
+
ffi (1.9.18)
|
27
|
+
formatador (0.2.5)
|
28
|
+
guard (2.14.1)
|
29
|
+
formatador (>= 0.2.4)
|
30
|
+
listen (>= 2.7, < 4.0)
|
31
|
+
lumberjack (~> 1.0)
|
32
|
+
nenv (~> 0.1)
|
33
|
+
notiffany (~> 0.0)
|
34
|
+
pry (>= 0.9.12)
|
35
|
+
shellany (~> 0.0)
|
36
|
+
thor (>= 0.18.1)
|
37
|
+
guard-bundler (2.1.0)
|
38
|
+
bundler (~> 1.0)
|
39
|
+
guard (~> 2.2)
|
40
|
+
guard-compat (~> 1.1)
|
41
|
+
guard-compat (1.2.1)
|
42
|
+
guard-rspec (4.7.3)
|
43
|
+
guard (~> 2.1)
|
44
|
+
guard-compat (~> 1.1)
|
45
|
+
rspec (>= 2.99.0, < 4.0)
|
46
|
+
hashie (3.5.6)
|
47
|
+
i18n (0.9.0)
|
48
|
+
concurrent-ruby (~> 1.0)
|
49
|
+
json (2.1.0)
|
50
|
+
listen (3.1.5)
|
51
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
52
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
53
|
+
ruby_dep (~> 1.2)
|
54
|
+
lumberjack (1.0.12)
|
55
|
+
method_source (0.9.0)
|
56
|
+
minitest (5.10.3)
|
57
|
+
nenv (0.3.0)
|
58
|
+
notiffany (0.1.1)
|
59
|
+
nenv (~> 0.1)
|
60
|
+
shellany (~> 0.0)
|
61
|
+
pry (0.11.2)
|
62
|
+
coderay (~> 1.1.0)
|
63
|
+
method_source (~> 0.9.0)
|
64
|
+
rake (12.2.1)
|
65
|
+
rb-fsevent (0.10.2)
|
66
|
+
rb-inotify (0.9.10)
|
67
|
+
ffi (>= 0.5.0, < 2)
|
68
|
+
rspec (3.7.0)
|
69
|
+
rspec-core (~> 3.7.0)
|
70
|
+
rspec-expectations (~> 3.7.0)
|
71
|
+
rspec-mocks (~> 3.7.0)
|
72
|
+
rspec-core (3.7.0)
|
73
|
+
rspec-support (~> 3.7.0)
|
74
|
+
rspec-expectations (3.7.0)
|
75
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
76
|
+
rspec-support (~> 3.7.0)
|
77
|
+
rspec-mocks (3.7.0)
|
78
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
79
|
+
rspec-support (~> 3.7.0)
|
80
|
+
rspec-support (3.7.0)
|
81
|
+
ruby_dep (1.5.0)
|
82
|
+
shellany (0.0.1)
|
83
|
+
simplecov (0.13.0)
|
84
|
+
docile (~> 1.1.0)
|
85
|
+
json (>= 1.8, < 3)
|
86
|
+
simplecov-html (~> 0.10.0)
|
87
|
+
simplecov-html (0.10.2)
|
88
|
+
thor (0.20.0)
|
89
|
+
thread_safe (0.3.6)
|
90
|
+
tzinfo (1.2.3)
|
91
|
+
thread_safe (~> 0.1)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
ruby
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler
|
98
|
+
byebug
|
99
|
+
codeclimate-test-reporter
|
100
|
+
guard
|
101
|
+
guard-bundler
|
102
|
+
guard-rspec
|
103
|
+
lam!
|
104
|
+
rake
|
105
|
+
|
106
|
+
BUNDLED WITH
|
107
|
+
1.15.4
|
data/Guardfile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
guard "bundler", cmd: "bundle" do
|
2
|
+
watch("Gemfile")
|
3
|
+
watch(/^.+\.gemspec/)
|
4
|
+
end
|
5
|
+
|
6
|
+
guard :rspec, cmd: "bundle exec rspec" do
|
7
|
+
require "guard/rspec/dsl"
|
8
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
9
|
+
|
10
|
+
# RSpec files
|
11
|
+
rspec = dsl.rspec
|
12
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
13
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
14
|
+
watch(rspec.spec_files)
|
15
|
+
|
16
|
+
# Ruby files
|
17
|
+
ruby = dsl.ruby
|
18
|
+
puts "ruby.lib_files #{ruby.lib_files.inspect}"
|
19
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
20
|
+
|
21
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
22
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Tung Nguyen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,35 +1,37 @@
|
|
1
1
|
# Lam
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://magnum.travis-ci.com/)](https://magnum.travis-ci.com/)
|
4
|
+
[![Code Climate](https://codeclimate.com/)](https://codeclimate.com/)
|
5
|
+
[![Code Climate](https://codeclimate.com/)](https://codeclimate.com/)
|
4
6
|
|
5
|
-
|
7
|
+
To these the lam, run these commands:
|
8
|
+
|
9
|
+
TODO: Write a gem description
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
9
13
|
Add this line to your application's Gemfile:
|
10
14
|
|
11
|
-
```
|
12
|
-
gem
|
15
|
+
```sh
|
16
|
+
gem "lam"
|
13
17
|
```
|
14
18
|
|
15
19
|
And then execute:
|
16
20
|
|
17
|
-
|
21
|
+
```sh
|
22
|
+
$ bundle
|
23
|
+
```
|
18
24
|
|
19
25
|
Or install it yourself as:
|
20
26
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
26
|
-
|
27
|
-
## Development
|
28
|
-
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
-
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
27
|
+
```
|
28
|
+
$ gem install lam
|
29
|
+
```
|
32
30
|
|
33
31
|
## Contributing
|
34
32
|
|
35
|
-
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
data/bin/lam
ADDED
data/bin/lamb
ADDED
data/lam.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# coding: utf-8
|
2
2
|
lib = File.expand_path("../lib", __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require "lam/version"
|
@@ -8,27 +8,25 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Lam::VERSION
|
9
9
|
spec.authors = ["Tung Nguyen"]
|
10
10
|
spec.email = ["tongueroo@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{Lambda tool}
|
11
|
+
spec.description = %q{Test}
|
12
|
+
spec.summary = %q{Test}
|
14
13
|
spec.homepage = "https://github.com/tongueroo/lam"
|
14
|
+
spec.license = "MIT"
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
20
|
-
else
|
21
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
-
"public gem pushes."
|
23
|
-
end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
-
f.match(%r{^(test|spec|features)/})
|
27
|
-
end
|
28
|
-
spec.bindir = "exe"
|
29
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
30
19
|
spec.require_paths = ["lib"]
|
31
20
|
|
32
|
-
spec.
|
33
|
-
spec.
|
21
|
+
spec.add_dependency "thor"
|
22
|
+
spec.add_dependency "hashie"
|
23
|
+
spec.add_dependency "colorize"
|
24
|
+
spec.add_dependency "activesupport"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler"
|
27
|
+
spec.add_development_dependency "byebug"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
spec.add_development_dependency "guard"
|
30
|
+
spec.add_development_dependency "guard-bundler"
|
31
|
+
spec.add_development_dependency "guard-rspec"
|
34
32
|
end
|
data/lib/lam.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
|
+
$:.unshift(File.expand_path("../", __FILE__))
|
1
2
|
require "lam/version"
|
3
|
+
require 'active_support/core_ext/string'
|
2
4
|
|
3
5
|
module Lam
|
4
|
-
|
6
|
+
autoload :Util, "lam/util"
|
7
|
+
autoload :Command, "lam/command"
|
8
|
+
autoload :CLI, "lam/cli"
|
9
|
+
autoload :Build, 'lam/build'
|
10
|
+
autoload :Process, 'lam/process'
|
11
|
+
autoload :BaseController, 'lam/base_controller'
|
12
|
+
|
13
|
+
extend Util
|
5
14
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Lam
|
4
|
+
class BaseController
|
5
|
+
attr_reader :event, :context
|
6
|
+
def initialize(event, context)
|
7
|
+
@event = event
|
8
|
+
@context = context
|
9
|
+
end
|
10
|
+
|
11
|
+
# The public methods defined in the user's custom class will become
|
12
|
+
# lambda functions.
|
13
|
+
# Returns Example:
|
14
|
+
# ["FakeController#handler1", "FakeController#handler2"]
|
15
|
+
def lambda_functions
|
16
|
+
# public_instance_methods(false) - to not include inherited methods
|
17
|
+
self.class.public_instance_methods(false) - Object.public_instance_methods
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.lambda_functions
|
21
|
+
new(nil, nil).lambda_functions
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
def render(options={})
|
26
|
+
# render json: {"mytestdata": "value1"}, status: 200, headers: {...}
|
27
|
+
if options.has_key?(:json)
|
28
|
+
# Transform the structure to Lambda Proxy structure
|
29
|
+
# {statusCode: ..., body: ..., headers: }
|
30
|
+
status = options.delete(:status)
|
31
|
+
body = options.delete(:json)
|
32
|
+
result = options.merge(
|
33
|
+
statusCode: status,
|
34
|
+
body: body
|
35
|
+
)
|
36
|
+
# render text: "text"
|
37
|
+
elsif options.has_key?(:text)
|
38
|
+
result = options.delete(:text)
|
39
|
+
else
|
40
|
+
raise "Unsupported render option. Only :text and :json supported. options #{options.inspect}"
|
41
|
+
end
|
42
|
+
|
43
|
+
result
|
44
|
+
end
|
45
|
+
|
46
|
+
# API Gateway LAMBDA_PROXY wraps the event in its own structure.
|
47
|
+
# We unwrap the "body" before sending it back
|
48
|
+
# For regular Lambda function calls, no need to unwrap but need to
|
49
|
+
# transform it to a string with JSON.dump.
|
50
|
+
def normalize_event_body(event)
|
51
|
+
body = event.has_key?("body") ? event["body"] : JSON.dump(event)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/lam/build.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'pp'
|
2
|
+
|
3
|
+
class Lam::Build
|
4
|
+
autoload :LambdaDeducer, "lam/build/lambda_deducer"
|
5
|
+
autoload :HandlerGenerator, "lam/build/handler_generator"
|
6
|
+
autoload :TravelingRuby, "lam/build/traveling_ruby"
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def run
|
13
|
+
puts "Building project for Lambda..."
|
14
|
+
build
|
15
|
+
end
|
16
|
+
|
17
|
+
def build
|
18
|
+
handlers.each do |handler|
|
19
|
+
HandlerGenerator.new(handler).generate
|
20
|
+
end
|
21
|
+
|
22
|
+
TravelingRuby.new.build unless @options[:noop]
|
23
|
+
end
|
24
|
+
|
25
|
+
def handlers
|
26
|
+
handlers = []
|
27
|
+
expression = "#{Lam.root}app/controllers/**/*.rb"
|
28
|
+
Dir.glob(expression).each do |path|
|
29
|
+
next unless File.file?(path)
|
30
|
+
next if path.include?("application_controller.rb")
|
31
|
+
|
32
|
+
path = relative_path(path)
|
33
|
+
handlers += LambdaDeducer.new(path).deduce.handlers
|
34
|
+
end
|
35
|
+
# pp handlers
|
36
|
+
handlers
|
37
|
+
end
|
38
|
+
|
39
|
+
# Rids of the Lam.root at beginning
|
40
|
+
def relative_path(path)
|
41
|
+
path.sub(Lam.root, '')
|
42
|
+
end
|
43
|
+
end
|