svrless 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fa4ee241942179aafc8a3afdeb61575f273ca3602cf6ca00f3b3fceab4c7417b
4
+ data.tar.gz: 1211b439d3251317f88183f6602318b10e192afc990006d88d9da04b1ef79203
5
+ SHA512:
6
+ metadata.gz: ec5e5621c3878e06748773898bb2a181446e6d8235a96a0f949aae36415eec4fe37211f03e6a4b6e609f7f595291044deba3256dae8c58031714fce08be2d85e
7
+ data.tar.gz: a01d89cf80dc8f6bdb65608af7148f446138f1247009bc715c46a4da85b401d2443aa5d297704d43abb4a587d0172c519b755c38c3bd91105254e5fba36b7c6d
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
data/.rubocop.yml ADDED
@@ -0,0 +1,14 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: double_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-02-11
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in svrless.gemspec
6
+
7
+ gem "rake", "~> 13.0"
8
+
9
+ gem "minitest", "~> 5.0"
10
+
11
+ gem "rubocop", "~> 1.7"
12
+
13
+ gem "activesupport"
data/Gemfile.lock ADDED
@@ -0,0 +1,49 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (6.1.2.1)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 1.6, < 2)
7
+ minitest (>= 5.1)
8
+ tzinfo (~> 2.0)
9
+ zeitwerk (~> 2.3)
10
+ ast (2.4.2)
11
+ concurrent-ruby (1.1.8)
12
+ i18n (1.8.9)
13
+ concurrent-ruby (~> 1.0)
14
+ minitest (5.13.0)
15
+ parallel (1.20.1)
16
+ parser (3.0.0.0)
17
+ ast (~> 2.4.1)
18
+ rainbow (3.0.0)
19
+ rake (13.0.1)
20
+ regexp_parser (2.0.3)
21
+ rexml (3.2.3)
22
+ rubocop (1.9.1)
23
+ parallel (~> 1.10)
24
+ parser (>= 3.0.0.0)
25
+ rainbow (>= 2.2.2, < 4.0)
26
+ regexp_parser (>= 1.8, < 3.0)
27
+ rexml
28
+ rubocop-ast (>= 1.2.0, < 2.0)
29
+ ruby-progressbar (~> 1.7)
30
+ unicode-display_width (>= 1.4.0, < 3.0)
31
+ rubocop-ast (1.4.1)
32
+ parser (>= 2.7.1.5)
33
+ ruby-progressbar (1.11.0)
34
+ tzinfo (2.0.4)
35
+ concurrent-ruby (~> 1.0)
36
+ unicode-display_width (2.0.0)
37
+ zeitwerk (2.4.2)
38
+
39
+ PLATFORMS
40
+ x86_64-darwin-20
41
+
42
+ DEPENDENCIES
43
+ activesupport
44
+ minitest (~> 5.0)
45
+ rake (~> 13.0)
46
+ rubocop (~> 1.7)
47
+
48
+ BUNDLED WITH
49
+ 2.2.9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 SVRLESS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # SVRLESS
2
+
3
+ Serverless framework for Rails developers. Very much still in very early development. A roadmap will be published soon.
4
+
5
+ ## Required
6
+
7
+ AWS SAM CLI is required to build and deploy the templates generated by this gem.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'svrless'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install svrless
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ To create a new svrless project
30
+
31
+ $ mkdir your-project-dir
32
+
33
+ $ cd your-project-dir
34
+
35
+ $ svrless
36
+
37
+ # uncomment the posts resource in routes
38
+
39
+ $ ruby config/routes.rb
40
+
41
+ $ bundle install
42
+
43
+ $ sam build
44
+
45
+ $ sam local start-api
46
+
47
+ $ make a POST request to http://localhost:3000/posts to see your lambda in action
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/svrless.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "svrless"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/bin/svrless ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ puts "Generating a SVRLESS application..."
6
+
7
+ Dir.mkdir("app") unless Dir.exist?("app")
8
+ Dir.mkdir("app/functions") unless Dir.exist?("app/functions")
9
+ Dir.mkdir("app/shared") unless Dir.exist?("app/shared")
10
+ Dir.mkdir("app/shared/ruby") unless Dir.exist?("app/shared/ruby")
11
+ Dir.mkdir("app/shared/ruby/lib") unless Dir.exist?("app/shared/ruby/lib")
12
+ Dir.mkdir("config") unless Dir.exist?("config")
13
+ FileUtils.touch("template.yaml")
14
+ FileUtils.touch("README.md")
15
+ FileUtils.touch(".rubocop.yml")
16
+ FileUtils.touch("Gemfile")
17
+ FileUtils.touch("start-server.sh")
18
+ FileUtils.touch("start-dev-server.sh")
19
+
20
+ File.open("Gemfile", "w") do |f|
21
+ f.write "source 'https://rubygems.org'\n"
22
+ end
23
+
24
+ File.open("config/routes.rb", "w") do |f|
25
+ f.write "require 'svrless'\n"
26
+ f.write "\n"
27
+ f.write "class Routes\n"
28
+ f.write " include Event\n"
29
+ f.write "\n"
30
+ f.write " # resource :post\n"
31
+ f.write "end\n"
32
+ end
33
+
34
+ puts "DONE!"
@@ -0,0 +1,179 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/all"
4
+ require "yaml"
5
+
6
+ module Event
7
+ module ClassMethods
8
+ def events(*args, resource)
9
+ raise StandardError, "Event: You need to supply at least one argument" if args.empty?
10
+
11
+ events = args
12
+ generate(events, resource)
13
+ end
14
+
15
+ def resource(args)
16
+ resource = args
17
+ events(:create, :show, :update, :destroy, resource)
18
+ generate_function_files(:create, :show, :update, :destroy, resource)
19
+ generate_svrless_controller
20
+ end
21
+
22
+ def generate(events, resource)
23
+ puts "Generating resource..."
24
+ # make_function_files
25
+ output = File.open("template.yaml", "w")
26
+ output << main_representation(events, resource)
27
+ output.close
28
+ puts "DONE!"
29
+ end
30
+
31
+ def main_representation(events, resource)
32
+ {
33
+ a_w_s_template_format_version: "2010-09-09",
34
+ transform: "AWS::Serverless-2016-10-31",
35
+ resources: resources_hash(events, resource)
36
+ }.deep_transform_keys { |k| k.to_s.capitalize.camelize }.to_yaml
37
+ end
38
+
39
+ def resources_hash(events, resource)
40
+ layer.merge(function_hash(events, resource))
41
+ end
42
+
43
+ def layer
44
+ {
45
+ svrless_layer: {
46
+ type: "AWS::Serverless::LayerVersion",
47
+ properties: {
48
+ layer_name: "svrless-layer",
49
+ description: "All the business logic should go in here",
50
+ content_uri: "app/shared/.",
51
+ compatible_runtimes: ["ruby2.7"]
52
+ }
53
+ }
54
+ }
55
+ end
56
+
57
+ def function_hash(events, resource)
58
+ {
59
+ "#{plural_classname(resource)}_controller": {
60
+ type: "AWS::Serverless::Function",
61
+ properties: {
62
+ code_uri: "app/functions/#{plural_classname(resource)}",
63
+ events: hash_of_events(events, resource),
64
+ function_name: "#{plural_classname(resource)}_controller".capitalize.camelize,
65
+ handler: "controller.#{full_classname(resource)}.router",
66
+ Layers: [{ Ref: "SvrlessLayer" }],
67
+ runtime: "ruby2.7"
68
+ }
69
+ }
70
+ }
71
+ end
72
+
73
+ def hash_of_events(events, resource)
74
+ h = {}
75
+ events.each do |event|
76
+ h.merge!(
77
+ {
78
+ "#{event}": {
79
+ type: "Api",
80
+ properties: {
81
+ method: method_from_event(event: event),
82
+ path: path_from_event(event: event, resource: resource)
83
+ }
84
+ }
85
+ }
86
+ )
87
+ end
88
+ h
89
+ end
90
+
91
+ def plural_classname(resource)
92
+ resource.to_s.pluralize
93
+ end
94
+
95
+ def method_from_event(event:)
96
+ case event
97
+ when :create
98
+ "post"
99
+ when :show
100
+ "get"
101
+ when :update
102
+ "put"
103
+ when :destroy
104
+ "delete"
105
+ end
106
+ end
107
+
108
+ def path_from_event(event:, resource:)
109
+ case event
110
+ when :create
111
+ "/#{plural_classname(resource)}"
112
+ when :show
113
+ "/#{plural_classname(resource)}/{id}"
114
+ when :update
115
+ "/#{plural_classname(resource)}/{id}"
116
+ when :destroy
117
+ "/#{plural_classname(resource)}/{id}"
118
+ end
119
+ end
120
+
121
+ def full_classname(resource)
122
+ "#{plural_classname(resource)}_controller".camelize
123
+ end
124
+
125
+ def generate_function_files(*args, resource)
126
+ Dir.mkdir("app") unless Dir.exist?("app")
127
+ Dir.mkdir("app/functions") unless Dir.exist?("app/functions")
128
+ unless Dir.exist?("app/functions/#{plural_classname(resource)}")
129
+ Dir.mkdir("app/functions/#{plural_classname(resource)}")
130
+ end
131
+ FileUtils.touch("app/functions/#{plural_classname(resource)}/controller.rb")
132
+ File.open("app/functions/#{plural_classname(resource)}/controller.rb", "w") do |f|
133
+ f.write "require 'svrless_controller'"
134
+ f.write "\n"
135
+ f.write "\n"
136
+ f.write "class #{full_classname(resource)} < SvrlessController"
137
+ f.write "\n"
138
+ args.each_with_index do |method, index|
139
+ f.write " def self.#{method}(event:, context:)\n"
140
+ f.write " {\n"
141
+ f.write " statusCode: 200,\n"
142
+ f.write " body: { hello: 'world' }.to_json\n"
143
+ f.write " }\n"
144
+ f.write " end\n"
145
+ f.write "\n" unless args.size == index + 1
146
+ end
147
+ f.write "end"
148
+ f.write "\n"
149
+ end
150
+ end
151
+
152
+ def generate_svrless_controller
153
+ Dir.mkdir("app") unless Dir.exist?("app")
154
+ Dir.mkdir("app/shared") unless Dir.exist?("app/shared")
155
+ Dir.mkdir("app/shared/ruby") unless Dir.exist?("app/shared/ruby")
156
+ Dir.mkdir("app/shared/ruby/lib") unless Dir.exist?("app/shared/ruby/lib")
157
+ File.open("app/shared/ruby/lib/svrless_controller.rb", "w") do |f|
158
+ f.write "class SvrlessController\n"
159
+ f.write " def self.router(event:, context:)\n"
160
+ f.write " case event['httpMethod']\n"
161
+ f.write " when 'GET'\n"
162
+ f.write " show(event: event, context: context)\n"
163
+ f.write " when 'POST'\n"
164
+ f.write " create(event: event, context: context)\n"
165
+ f.write " when 'DELETE'\n"
166
+ f.write " destroy(event: event, context: context)\n"
167
+ f.write " else\n"
168
+ f.write " update(event: event, context: context)\n"
169
+ f.write " end\n"
170
+ f.write " end\n"
171
+ f.write "end\n"
172
+ end
173
+ end
174
+ end
175
+
176
+ def self.included(klass)
177
+ klass.extend ClassMethods
178
+ end
179
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Svrless
4
+ VERSION = "0.1.1"
5
+ end
data/lib/svrless.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "svrless/version"
4
+ require_relative "svrless/event"
5
+
6
+ module Svrless
7
+ class Error < StandardError; end
8
+ end
data/svrless.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/svrless/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "svrless"
7
+ spec.version = Svrless::VERSION
8
+ spec.authors = ["zrthko"]
9
+ spec.email = ["zrthko@svrless.org"]
10
+ spec.summary = "Serverless framework for Rails developers."
11
+ spec.description = "Bridging the gap between monolithic style development with a serverless backend."
12
+ spec.homepage = "https://github.com/svrless/svrless"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new("~> 2.7.0")
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/svrless/svrless"
17
+ spec.metadata["changelog_uri"] = "https://github.com/svrless/svrless/blob/main/CHANGELOG.md"
18
+ spec.executables << "svrless"
19
+ spec.require_paths = ["lib"]
20
+ spec.add_dependency "activesupport", "~> 5.0.0.0"
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: svrless
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - zrthko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.0.0.0
27
+ description: Bridging the gap between monolithic style development with a serverless
28
+ backend.
29
+ email:
30
+ - zrthko@svrless.org
31
+ executables:
32
+ - svrless
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - ".gitignore"
37
+ - ".rubocop.yml"
38
+ - CHANGELOG.md
39
+ - Gemfile
40
+ - Gemfile.lock
41
+ - LICENSE
42
+ - README.md
43
+ - Rakefile
44
+ - bin/console
45
+ - bin/setup
46
+ - bin/svrless
47
+ - lib/svrless.rb
48
+ - lib/svrless/event.rb
49
+ - lib/svrless/version.rb
50
+ - svrless.gemspec
51
+ homepage: https://github.com/svrless/svrless
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/svrless/svrless
56
+ source_code_uri: https://github.com/svrless/svrless
57
+ changelog_uri: https://github.com/svrless/svrless/blob/main/CHANGELOG.md
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 2.7.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubygems_version: 3.1.4
74
+ signing_key:
75
+ specification_version: 4
76
+ summary: Serverless framework for Rails developers.
77
+ test_files: []