natra 0.0.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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +11 -0
  4. data/.rspec +3 -0
  5. data/.travis.yml +4 -0
  6. data/CODE_OF_CONDUCT.md +74 -0
  7. data/Gemfile +14 -0
  8. data/Gemfile.lock +167 -0
  9. data/Guardfile +75 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +60 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +6 -0
  14. data/bin/natra +7 -0
  15. data/bin/setup +6 -0
  16. data/lib/extensions/string.rb +37 -0
  17. data/lib/natra.rb +9 -0
  18. data/lib/natra/cli.rb +20 -0
  19. data/lib/natra/generators/app/app_generator.rb +150 -0
  20. data/lib/natra/generators/app/templates/Dockerfile +24 -0
  21. data/lib/natra/generators/app/templates/Gemfile +35 -0
  22. data/lib/natra/generators/app/templates/Guardfile +20 -0
  23. data/lib/natra/generators/app/templates/README.md +52 -0
  24. data/lib/natra/generators/app/templates/Rakefile +4 -0
  25. data/lib/natra/generators/app/templates/app/controllers/application_controller.rb +14 -0
  26. data/lib/natra/generators/app/templates/app/models/.gitkeep +0 -0
  27. data/lib/natra/generators/app/templates/app/views/layout.erb.tt +20 -0
  28. data/lib/natra/generators/app/templates/app/views/welcome.erb +22 -0
  29. data/lib/natra/generators/app/templates/bin/ci +6 -0
  30. data/lib/natra/generators/app/templates/bin/setup +7 -0
  31. data/lib/natra/generators/app/templates/config.ru +11 -0
  32. data/lib/natra/generators/app/templates/config/db.yml +35 -0
  33. data/lib/natra/generators/app/templates/config/environment.rb +19 -0
  34. data/lib/natra/generators/app/templates/config/initializers/database.rb +11 -0
  35. data/lib/natra/generators/app/templates/config/initializers/oj.rb +5 -0
  36. data/lib/natra/generators/app/templates/config/initializers/redis.rb +7 -0
  37. data/lib/natra/generators/app/templates/config/puma.rb +11 -0
  38. data/lib/natra/generators/app/templates/config/redis.yml +14 -0
  39. data/lib/natra/generators/app/templates/docker-compose.yml +22 -0
  40. data/lib/natra/generators/app/templates/gitignore +12 -0
  41. data/lib/natra/generators/app/templates/public/favicon.ico +0 -0
  42. data/lib/natra/generators/app/templates/public/images/.gitkeep +0 -0
  43. data/lib/natra/generators/app/templates/public/images/corneal-small.png +0 -0
  44. data/lib/natra/generators/app/templates/public/javascripts/.gitkeep +0 -0
  45. data/lib/natra/generators/app/templates/public/stylesheets/main.css +115 -0
  46. data/lib/natra/generators/app/templates/rspec +2 -0
  47. data/lib/natra/generators/app/templates/rubocop.yml +79 -0
  48. data/lib/natra/generators/app/templates/secrets.env +16 -0
  49. data/lib/natra/generators/app/templates/spec/application_controller_spec.rb +13 -0
  50. data/lib/natra/generators/app/templates/spec/spec_helper.rb +36 -0
  51. data/lib/natra/generators/controller/controller_generator.rb +37 -0
  52. data/lib/natra/generators/controller/templates/controller.rb.erb +37 -0
  53. data/lib/natra/generators/controller/templates/views/edit.html.erb +1 -0
  54. data/lib/natra/generators/controller/templates/views/index.html.erb +1 -0
  55. data/lib/natra/generators/controller/templates/views/new.html.erb +1 -0
  56. data/lib/natra/generators/controller/templates/views/show.html.erb +1 -0
  57. data/lib/natra/generators/model/migration.rb.erb +10 -0
  58. data/lib/natra/generators/model/model.rb.erb +2 -0
  59. data/lib/natra/generators/model/model_generator.rb +59 -0
  60. data/lib/natra/generators/scaffold/scaffold_generator.rb +22 -0
  61. data/lib/natra/version.rb +3 -0
  62. data/natra.gemspec +41 -0
  63. metadata +180 -0
@@ -0,0 +1,6 @@
1
+ #! /usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ RACK_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace
6
+
@@ -0,0 +1,7 @@
1
+ #! /usr/bin/env bash
2
+
3
+ set -e
4
+
5
+ RACK_ENV=development rake db:create db:migrate --trace
6
+ RACK_ENV=development rake db:seed_fu --trace
7
+ RACK_ENV=test DATABASE_URL=$TEST_DATABASE_URL rake db:create db:migrate --trace
@@ -0,0 +1,11 @@
1
+ require './config/environment'
2
+ # Call as early as possible so rack-timeout runs before all other middleware.
3
+ use Rack::Timeout, service_timeout: 5
4
+
5
+ ScoutApm::Rack.install
6
+
7
+ if ActiveRecord::Migrator.needs_migration?
8
+ raise 'Migrations are pending. Run `rake db:migrate` to resolve the issue.'
9
+ end
10
+
11
+ run ApplicationController
@@ -0,0 +1,35 @@
1
+ # Sequel Database Configuration
2
+ <% if @database == "sqlite" %>
3
+ development: "sqlite://db/development.sqlite3"
4
+ test: "sqlite://db/test.sqlite3"
5
+ production: "sqlite://db/production.sqlite3"
6
+ <% elsif @database == "postgres" %>
7
+ development: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_development"
8
+ test: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_test"
9
+ production: "postgres://<%= `whoami`.chop %>@localhost/<%= @name %>_production"
10
+ <% elsif @database == "mysql" %>
11
+ development: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_development"
12
+ test: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_test"
13
+ production: "mysql2://<%= `whoami`.chop %>@localhost/<%= @name %>_production"
14
+ <% elsif @database == "mongo" %>
15
+ development:
16
+ host: localhost
17
+ port: 27017
18
+ database: <%= @name %>_development
19
+ username:
20
+ password:
21
+
22
+ test:
23
+ host: localhost
24
+ port: 27017
25
+ database: <%= @name %>_test
26
+ username:
27
+ password:
28
+
29
+ production:
30
+ host: localhost
31
+ port: 27017
32
+ database: <%= @name %>_production
33
+ username:
34
+ password:
35
+ <% end %>
@@ -0,0 +1,19 @@
1
+ ENV['SINATRA_ENV'] ||= "development"
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ Bundler.require(:default, ENV['SINATRA_ENV'])
5
+ require 'active_support'
6
+ require 'active_support/core_ext/hash/indifferent_access'
7
+ require 'active_support/core_ext/string'
8
+
9
+ require 'rack-timeout'
10
+ require 'scout_apm'
11
+
12
+ require 'oj'
13
+ ActiveRecord::Base.establish_connection(
14
+ :adapter => "sqlite3",
15
+ :database => "db/#{ENV['SINATRA_ENV']}.sqlite"
16
+ )
17
+
18
+ require './app/controllers/application_controller'
19
+ require_all 'app'
@@ -0,0 +1,11 @@
1
+ <% unless @database.empty? -%>
2
+ require "yaml"
3
+ settings = YAML::load_file("config/db.yml")
4
+ <% if @database != 'mongo' -%>
5
+ # Sequel Configuration
6
+ require "sequel"
7
+ DB = Sequel.connect(settings[ENV['RACK_ENV']])
8
+ <% else -%>
9
+ # MongoDB Configuration
10
+ <% end -%>
11
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ Oj.default_options = {
2
+ class_cache: true,
3
+ mode: :strict
4
+ }
5
+
@@ -0,0 +1,7 @@
1
+ require "yaml"
2
+
3
+ # Redis Configuration
4
+ unless ENV['RACK_ENV'] == 'test'
5
+ redis_settings = YAML::load_file("config/redis.yml")
6
+ REDIS = Redis.new(redis_settings[ENV['RACK_ENV']])
7
+ end
@@ -0,0 +1,11 @@
1
+ threads_count = Integer(ENV['PUMA_MAX_THREADS'] || 5)
2
+ port = Integer(ENV['PORT'] || 9292)
3
+
4
+ threads threads_count, threads_count
5
+ workers Integer(ENV['WEB_CONCURRENCY'] || 1)
6
+
7
+ preload_app!
8
+
9
+ environment ENV['RACK_ENV'] || 'development'
10
+
11
+ bind "tcp://0.0.0.0:#{port}"
@@ -0,0 +1,14 @@
1
+ development:
2
+ host: localhost
3
+ port: 6387
4
+ password:
5
+
6
+ test:
7
+ host: localhost
8
+ port: 6387
9
+ password:
10
+
11
+ production:
12
+ host: localhost
13
+ port: 6387
14
+ password:
@@ -0,0 +1,22 @@
1
+ version: "2.3"
2
+
3
+ services:
4
+ web:
5
+ build:
6
+ context: .
7
+ target: development
8
+ command: puma
9
+ volumes:
10
+ - .:/usr/src/app
11
+ ports:
12
+ - '9292:9292'
13
+ links:
14
+ - db
15
+ env_file: secrets.env
16
+ db:
17
+ <%- if @database=='postgres' -%>
18
+ image: postgres:10-alpine
19
+ ports:
20
+ - "54329:5432"
21
+ env_file: secrets.env
22
+ <%- end -%>
@@ -0,0 +1,12 @@
1
+ /tmp
2
+ /log
3
+ /log
4
+ *.swp
5
+ *.swo
6
+ .rspec_status
7
+ coverage
8
+
9
+ client/Gemfile.lock
10
+
11
+ secrets.aes
12
+ secrets.env
@@ -0,0 +1,115 @@
1
+ @media screen {
2
+ /* --- Reset Styles --- */
3
+ * {
4
+ list-style: none;
5
+ margin: 0;
6
+ padding: 0;
7
+ }
8
+
9
+ html, body {
10
+ height: 100%;
11
+ width: 100%;
12
+ }
13
+
14
+ /* --- Welcome Page Styles --- */
15
+ body {
16
+ background-color: lightblue;
17
+ color: #333;
18
+ font-family: Sans-Serif;
19
+ line-height: 18px;
20
+ }
21
+
22
+ .wrapper {
23
+ background: #fff;
24
+ -moz-box-shadow: 0 0 10px rgba(0,0,0,.3);
25
+ -webkit-box-shadow: 0 0 10px rgba(0,0,0,.3);
26
+ box-shadow: 0 0 10px rgba(0,0,0,.3);
27
+ margin: 16px auto;
28
+ max-width: 960px;
29
+ padding: 2.25%; /* 18px / 800px */
30
+ width: 85%;
31
+ }
32
+
33
+ h1 {
34
+ font-size: 36px;
35
+ line-height: 54px;
36
+ }
37
+
38
+ h2 {
39
+ border-bottom: 2px solid #ccc;
40
+ font-size: 24px;
41
+ line-height: 36px;
42
+ margin-bottom: 16px;
43
+ }
44
+
45
+ h3 {
46
+ font-size: 18px;
47
+ line-height: 36px;
48
+ }
49
+
50
+ p {
51
+ margin-bottom: 18px;
52
+ }
53
+
54
+ .main {
55
+ overflow: hidden;
56
+ }
57
+
58
+ .content {
59
+ float: left;
60
+ width: 60%; /* 480px / 800px */
61
+ }
62
+
63
+ .sidebar {
64
+ background: #eee;
65
+ border: 1px solid #ccc;
66
+ float: right;
67
+ padding: 2.08333333333%; /* 5px / 240px */
68
+ width: 30%; /* 240px / 800px */
69
+ }
70
+
71
+ .sidebar ul {
72
+ font-size: 14px;
73
+ }
74
+
75
+ .branding {
76
+ clear: both;
77
+ }
78
+
79
+ footer.branding {
80
+ border-top: 2px solid #ccc;
81
+ margin-top: 20px;
82
+ padding-top: 20px;
83
+ }
84
+ }
85
+
86
+ @media screen and (max-width: 600px) {
87
+ .wrapper {
88
+ -moz-box-shadow: none;
89
+ -webkit-box-shadow: none;
90
+ box-shadow: none;
91
+ width: auto;
92
+ }
93
+
94
+ .content, .sidebar {
95
+ float: none;
96
+ width: 100%;
97
+ }
98
+
99
+ .sidebar {
100
+ background: transparent;
101
+ border: none;
102
+ border-top: 2px solid #ccc;
103
+ padding: 0;
104
+ }
105
+
106
+ h1 {
107
+ font-size: 24px;
108
+ line-height: 36px;
109
+ }
110
+
111
+ h2 {
112
+ font-size: 18px;
113
+ line-height: 24px;
114
+ }
115
+ }
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,79 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ Exclude:
4
+ - lib/swaggering.rb
5
+ - api/**
6
+ - Guardfile
7
+ - my_app.rb
8
+ - spec/spec_helper.rb
9
+ - tmp/**
10
+
11
+ Documentation:
12
+ # don't require classes to be documented
13
+ Enabled: false
14
+
15
+ Style/FrozenStringLiteralComment:
16
+ # don't require frozen literal comment
17
+ Enabled: false
18
+
19
+ Encoding:
20
+ # no need to always specify encoding
21
+ Enabled: false
22
+
23
+ AlignParameters:
24
+ # allow for multi-line methods to have normal indentation.
25
+ # for example:
26
+ #
27
+ # Person.where(
28
+ # first_name: 'tom',
29
+ # last_name: 'foolery'
30
+ # )
31
+ EnforcedStyle: with_fixed_indentation
32
+
33
+ Layout/AlignParameters:
34
+ # allow for end of if to be aligned with a variable.
35
+ # for example:
36
+ #
37
+ # foo = if a == b
38
+ # 'bar'
39
+ # else
40
+ # 'baz'
41
+ # end
42
+ EnforcedStyle: with_fixed_indentation
43
+
44
+ Layout/MultilineMethodCallIndentation:
45
+ EnforcedStyle: indented
46
+
47
+ Layout/MultilineOperationIndentation:
48
+ # allow for operations to be indented at two spaces.
49
+ # for example:
50
+ #
51
+ # @valid ||= present &&
52
+ # positive?
53
+ EnforcedStyle: indented
54
+
55
+ Layout/EndAlignment:
56
+ EnforcedStyleAlignWith: variable
57
+
58
+ ClassAndModuleChildren:
59
+ # ok to use compact style when modules are predefined.
60
+ # for example the following is fine so long as we're sure that
61
+ # module MDB has already been required/defined.
62
+ #
63
+ # class MDB::Person; end
64
+ Enabled: false
65
+
66
+ Metrics/BlockLength:
67
+ # Certain DSL use blocks and can be lengthy
68
+ Exclude:
69
+ - 'spec/**/*'
70
+ - 'Guardfile'
71
+
72
+ Style/PercentLiteralDelimiters:
73
+ PreferredDelimiters:
74
+ default: ()
75
+ "%i": ()
76
+ "%w": ()
77
+
78
+ Style/FormatString:
79
+ Enabled: false
@@ -0,0 +1,16 @@
1
+ SINATRA_ENV=development
2
+ LOG_LEVEL=Logger::INFO
3
+ <%- unless skip_db? -%>
4
+ DATABASE_URL=postgresql://docker:docker@db:5432/<%= @name.camel_case %>?pool=5
5
+ POSTGRES_USER=docker
6
+ POSTGRES_PASSWORD=docker
7
+ POSTGRES_DB=<%= @name.camel_case %>
8
+ <%- end -%>
9
+ <%- if message_producers? -%>
10
+ RABBITMQ_DEFAULT_PASS=admin
11
+ RABBITMQ_DEFAULT_USER=admin
12
+ RABBITMQ_URL=amqp://admin:admin@broker:5672
13
+ RABBITMQ_DEFAULT_VHOST=vhost
14
+ RABBITMQ_LOGGER_LEVEL=Logger::INFO
15
+ RABBITMQ_DEFAULT_EXCHANGE=<%= @name.camel_case %>
16
+ <%- end -%>
@@ -0,0 +1,13 @@
1
+ require_relative "spec_helper"
2
+
3
+ def app
4
+ ApplicationController
5
+ end
6
+
7
+ describe ApplicationController do
8
+ it "responds with a welcome message" do
9
+ get '/'
10
+ expect(last_response.status).to eq(200)
11
+ expect(last_response.body).to include("Welcome to the Sinatra Template!")
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ ENV["SINATRA_ENV"] = "test"
2
+
3
+ require_relative '../config/environment'
4
+ require 'rack/test'
5
+ require 'capybara/rspec'
6
+ require 'capybara/dsl'
7
+
8
+ if ActiveRecord::Migrator.needs_migration?
9
+ raise 'Migrations are pending. Run `rake db:migrate SINATRA_ENV=test` to resolve the issue.'
10
+ end
11
+
12
+ ActiveRecord::Base.logger = nil
13
+
14
+ RSpec.configure do |config|
15
+ config.run_all_when_everything_filtered = true
16
+ config.filter_run :focus
17
+ config.include Rack::Test::Methods
18
+ config.include Capybara::DSL
19
+ DatabaseCleaner.strategy = :truncation
20
+
21
+ config.before do
22
+ DatabaseCleaner.clean
23
+ end
24
+
25
+ config.after do
26
+ DatabaseCleaner.clean
27
+ end
28
+
29
+ config.order = 'default'
30
+ end
31
+
32
+ def app
33
+ Rack::Builder.parse_file('config.ru').first
34
+ end
35
+
36
+ Capybara.app = app