lam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +107 -0
  7. data/Guardfile +22 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +37 -0
  10. data/Rakefile +6 -0
  11. data/bin/lam +14 -0
  12. data/lam.gemspec +32 -0
  13. data/lib/lam.rb +14 -0
  14. data/lib/lam/base_controller.rb +54 -0
  15. data/lib/lam/build.rb +43 -0
  16. data/lib/lam/build/handler_generator.rb +34 -0
  17. data/lib/lam/build/lambda_deducer.rb +47 -0
  18. data/lib/lam/build/templates/handler.js +156 -0
  19. data/lib/lam/build/traveling_ruby.rb +108 -0
  20. data/lib/lam/cli.rb +23 -0
  21. data/lib/lam/cli/help.rb +19 -0
  22. data/lib/lam/command.rb +25 -0
  23. data/lib/lam/process.rb +18 -0
  24. data/lib/lam/process/base_processor.rb +23 -0
  25. data/lib/lam/process/controller_processor.rb +36 -0
  26. data/lib/lam/process/help.rb +11 -0
  27. data/lib/lam/process/processor_deducer.rb +52 -0
  28. data/lib/lam/util.rb +13 -0
  29. data/lib/lam/version.rb +3 -0
  30. data/notes/design.md +43 -0
  31. data/notes/traveling-ruby-packaging-lam.md +26 -0
  32. data/notes/traveling-ruby-packaging.md +103 -0
  33. data/notes/traveling-ruby.md +82 -0
  34. data/spec/fixtures/project/.gitignore +3 -0
  35. data/spec/fixtures/project/.ruby-version +1 -0
  36. data/spec/fixtures/project/Gemfile +4 -0
  37. data/spec/fixtures/project/Gemfile.lock +35 -0
  38. data/spec/fixtures/project/app/controllers/application_controller.rb +2 -0
  39. data/spec/fixtures/project/app/controllers/posts_controller.rb +12 -0
  40. data/spec/fixtures/project/bin/lam +22 -0
  41. data/spec/fixtures/project/handlers/controllers/posts.js +156 -0
  42. data/spec/lib/cli_spec.rb +20 -0
  43. data/spec/lib/lam/base_controller_spec.rb +18 -0
  44. data/spec/lib/lam/build/lambda_deducer_spec.rb +20 -0
  45. data/spec/lib/lam/build_spec.rb +29 -0
  46. data/spec/lib/lam/process/controller_processor_spec.rb +22 -0
  47. data/spec/lib/lam/process/infer_spec.rb +24 -0
  48. data/spec/lib/lam/process_spec.rb +18 -0
  49. data/spec/spec_helper.rb +25 -0
  50. metadata +249 -0
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ # to run specs with what"s remembered from vcr
4
+ # $ rake
5
+ #
6
+ # to run specs with new fresh data from aws api calls
7
+ # $ rake clean:vcr ; time rake
8
+ describe Lam::CLI do
9
+ before(:all) do
10
+ @args = "--noop"
11
+ end
12
+
13
+ describe "lam" do
14
+ it "build" do
15
+ out = execute("bin/lam build #{@args}")
16
+ # puts out
17
+ expect(out).to include("Building project")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ # For testing lambda_function_names
4
+ class FakeController < Lam::BaseController
5
+ def handler1; end
6
+ def handler2; end
7
+ end
8
+
9
+ describe Lam::BaseController do
10
+ describe "lambda_functions" do
11
+ it "should only list public user defined methods" do
12
+ controller = FakeController.new(nil, nil)
13
+ expect(controller.lambda_functions).to eq(
14
+ [:handler1, :handler2]
15
+ )
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ require_relative "../../../spec_helper"
2
+
3
+ describe Lam::Build::LambdaDeducer do
4
+ let(:deducer) do
5
+ Lam::Build::LambdaDeducer.new("app/controllers/posts_controller.rb")
6
+ end
7
+
8
+ describe "LambdaDeducer" do
9
+ it "deduces lambda js info" do
10
+ deducer.run
11
+ expect(deducer.handlers).to eq([
12
+ {
13
+ handler: "handlers/controllers/posts.create",
14
+ js_path: "handlers/controllers/posts.js",
15
+ js_method: "create"
16
+ }
17
+ ])
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe Lam::Build do
4
+ before(:each) do
5
+ FileUtils.rm_f("spec/fixtures/project/handlers/controllers/posts.js")
6
+ end
7
+ let(:build) do
8
+ Lam::Build.new(noop: true)
9
+ end
10
+
11
+ describe "Build" do
12
+ it "#handlers" do
13
+ expect(build.handlers).to eq([
14
+ {
15
+ handler: "handlers/controllers/posts.create",
16
+ js_path: "handlers/controllers/posts.js",
17
+ js_method: "create"
18
+ }
19
+ ])
20
+ end
21
+
22
+ it "builds handlers javascript files" do
23
+ build.build
24
+ file_exist = File.exist?("#{Lam.root}handlers/controllers/posts.js")
25
+ expect(file_exist).to be true
26
+ end
27
+ end
28
+ end
29
+
@@ -0,0 +1,22 @@
1
+ require_relative "../../../spec_helper"
2
+
3
+ describe Lam::Process::ControllerProcessor do
4
+ before(:all) do
5
+ @event = { "we" => "love", "using" => "Lambda" }
6
+ @context = {"test" => "1"}
7
+ end
8
+ let(:processor) do
9
+ Lam::Process::ControllerProcessor.new(
10
+ JSON.dump(@event),
11
+ JSON.dump(@context),
12
+ 'handlers/controllers/posts.create' # handler
13
+ )
14
+ end
15
+
16
+ describe "ControllerProcessor" do
17
+ it "find public_instance_methods" do
18
+ processor.run
19
+ expect(processor.event).to eq(@event)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Lam::Process::ProcessorDeducer do
4
+ describe "ProcessorDeducer" do
5
+ let(:deducer) { Lam::Process::ProcessorDeducer.new(handle) }
6
+
7
+ context("controller") do
8
+ let(:handle) { "handlers/controllers/posts.create" }
9
+ it "deduces processor info" do
10
+ expect(deducer.controller[:path]).to include "app/controllers/posts_controller.rb"
11
+ expect(deducer.controller[:code]).to eq "PostsController.new(event, context).create"
12
+ end
13
+ end
14
+
15
+ context("function") do
16
+ let(:handle) { "handlers/functions/posts.create" }
17
+ it "deduces processor info" do
18
+ expect(deducer.function[:path]).to include "app/functions/posts.rb"
19
+ expect(deducer.function[:code]).to eq "create(event, context)"
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "../../spec_helper"
2
+
3
+ describe Lam::Process do
4
+ before(:all) do
5
+ # @args = "--noop --project-root spec/fixtures/my_project"
6
+ @args = '\'{ "we" : "love", "using" : "Lambda" }\' \'{"test": "1"}\' "handlers/controllers/posts.create"'
7
+ end
8
+
9
+ describe "lam process" do
10
+ it "controller [event] [context] [handler]" do
11
+ out = execute("bin/lam process controller #{@args}")
12
+ # pp out # uncomment to debug
13
+ data = JSON.parse(out)
14
+ expect(data["statusCode"]).to eq 200
15
+ expect(data["body"]).to eq({"we"=>"love", "using"=>"Lambda"})
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,25 @@
1
+ ENV["TEST"] = "1"
2
+ ENV["PROJECT_ROOT"] = "./spec/fixtures/project"
3
+
4
+ # require "simplecov"
5
+ # SimpleCov.start
6
+
7
+ require "pp"
8
+ require "byebug"
9
+ require "fileutils"
10
+
11
+ root = File.expand_path("../../", __FILE__)
12
+ require "#{root}/lib/lam"
13
+
14
+ module Helpers
15
+ def execute(cmd)
16
+ puts "Running: #{cmd}" if ENV["DEBUG"]
17
+ out = `#{cmd}`
18
+ puts out if ENV["DEBUG"]
19
+ out
20
+ end
21
+ end
22
+
23
+ RSpec.configure do |c|
24
+ c.include Helpers
25
+ end
metadata ADDED
@@ -0,0 +1,249 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tung Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Test
154
+ email:
155
+ - tongueroo@gmail.com
156
+ executables:
157
+ - lam
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".ruby-version"
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - Guardfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - bin/lam
171
+ - lam.gemspec
172
+ - lib/lam.rb
173
+ - lib/lam/base_controller.rb
174
+ - lib/lam/build.rb
175
+ - lib/lam/build/handler_generator.rb
176
+ - lib/lam/build/lambda_deducer.rb
177
+ - lib/lam/build/templates/handler.js
178
+ - lib/lam/build/traveling_ruby.rb
179
+ - lib/lam/cli.rb
180
+ - lib/lam/cli/help.rb
181
+ - lib/lam/command.rb
182
+ - lib/lam/process.rb
183
+ - lib/lam/process/base_processor.rb
184
+ - lib/lam/process/controller_processor.rb
185
+ - lib/lam/process/help.rb
186
+ - lib/lam/process/processor_deducer.rb
187
+ - lib/lam/util.rb
188
+ - lib/lam/version.rb
189
+ - notes/design.md
190
+ - notes/traveling-ruby-packaging-lam.md
191
+ - notes/traveling-ruby-packaging.md
192
+ - notes/traveling-ruby.md
193
+ - spec/fixtures/project/.gitignore
194
+ - spec/fixtures/project/.ruby-version
195
+ - spec/fixtures/project/Gemfile
196
+ - spec/fixtures/project/Gemfile.lock
197
+ - spec/fixtures/project/app/controllers/application_controller.rb
198
+ - spec/fixtures/project/app/controllers/posts_controller.rb
199
+ - spec/fixtures/project/bin/lam
200
+ - spec/fixtures/project/handlers/controllers/posts.js
201
+ - spec/lib/cli_spec.rb
202
+ - spec/lib/lam/base_controller_spec.rb
203
+ - spec/lib/lam/build/lambda_deducer_spec.rb
204
+ - spec/lib/lam/build_spec.rb
205
+ - spec/lib/lam/process/controller_processor_spec.rb
206
+ - spec/lib/lam/process/infer_spec.rb
207
+ - spec/lib/lam/process_spec.rb
208
+ - spec/spec_helper.rb
209
+ homepage: https://github.com/tongueroo/lam
210
+ licenses:
211
+ - MIT
212
+ metadata: {}
213
+ post_install_message:
214
+ rdoc_options: []
215
+ require_paths:
216
+ - lib
217
+ required_ruby_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ required_rubygems_version: !ruby/object:Gem::Requirement
223
+ requirements:
224
+ - - ">="
225
+ - !ruby/object:Gem::Version
226
+ version: '0'
227
+ requirements: []
228
+ rubyforge_project:
229
+ rubygems_version: 2.4.5
230
+ signing_key:
231
+ specification_version: 4
232
+ summary: Test
233
+ test_files:
234
+ - spec/fixtures/project/.gitignore
235
+ - spec/fixtures/project/.ruby-version
236
+ - spec/fixtures/project/Gemfile
237
+ - spec/fixtures/project/Gemfile.lock
238
+ - spec/fixtures/project/app/controllers/application_controller.rb
239
+ - spec/fixtures/project/app/controllers/posts_controller.rb
240
+ - spec/fixtures/project/bin/lam
241
+ - spec/fixtures/project/handlers/controllers/posts.js
242
+ - spec/lib/cli_spec.rb
243
+ - spec/lib/lam/base_controller_spec.rb
244
+ - spec/lib/lam/build/lambda_deducer_spec.rb
245
+ - spec/lib/lam/build_spec.rb
246
+ - spec/lib/lam/process/controller_processor_spec.rb
247
+ - spec/lib/lam/process/infer_spec.rb
248
+ - spec/lib/lam/process_spec.rb
249
+ - spec/spec_helper.rb