hoboken 0.0.1.beta2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +33 -0
  3. data/.github/ISSUE_TEMPLATE/code_change.md +11 -0
  4. data/.github/PULL_REQUEST_TEMPLATE.md +25 -0
  5. data/.github/dependabot.yml +7 -0
  6. data/.github/workflows/ruby.yml +28 -0
  7. data/.gitignore +3 -0
  8. data/.rubocop.yml +41 -0
  9. data/.ruby-version +1 -0
  10. data/.tool-versions +1 -0
  11. data/CHANGELOG.md +131 -0
  12. data/CODE_OF_CONDUCT.md +8 -0
  13. data/CONTRIBUTING.md +16 -0
  14. data/Gemfile +2 -0
  15. data/IDEAS.md +57 -0
  16. data/LICENSE.txt +1 -1
  17. data/README.md +28 -17
  18. data/Rakefile +14 -8
  19. data/bin/hoboken +2 -1
  20. data/hoboken.gemspec +63 -16
  21. data/lib/hoboken/actions.rb +11 -6
  22. data/lib/hoboken/add_ons/active_record.rb +142 -0
  23. data/lib/hoboken/add_ons/airbrake.rb +64 -0
  24. data/lib/hoboken/add_ons/github_action.rb +14 -0
  25. data/lib/hoboken/add_ons/heroku.rb +29 -0
  26. data/lib/hoboken/add_ons/internationalization.rb +28 -0
  27. data/lib/hoboken/add_ons/metrics.rb +60 -0
  28. data/lib/hoboken/add_ons/omniauth.rb +174 -0
  29. data/lib/hoboken/add_ons/rubocop.rb +46 -0
  30. data/lib/hoboken/add_ons/sequel.rb +135 -0
  31. data/lib/hoboken/add_ons/sidekiq.rb +137 -0
  32. data/lib/hoboken/add_ons/travis.rb +15 -0
  33. data/lib/hoboken/add_ons/turnip.rb +109 -0
  34. data/lib/hoboken/add_ons/twbs.rb +50 -0
  35. data/lib/hoboken/add_ons/vcr.rb +54 -0
  36. data/lib/hoboken/generate.rb +146 -46
  37. data/lib/hoboken/templates/Gemfile.erb.tt +43 -8
  38. data/lib/hoboken/templates/README.md.tt +117 -35
  39. data/lib/hoboken/templates/Rakefile.tt +20 -16
  40. data/lib/hoboken/templates/active_record.rake +11 -0
  41. data/lib/hoboken/templates/airbrake.rb.tt +13 -0
  42. data/lib/hoboken/templates/classic.rb.tt +25 -11
  43. data/lib/hoboken/templates/classic_environment.rb.tt +51 -0
  44. data/lib/hoboken/templates/config.ru.tt +4 -2
  45. data/lib/hoboken/templates/console +19 -0
  46. data/lib/hoboken/templates/db.rb.tt +24 -0
  47. data/lib/hoboken/templates/example_worker.rb.tt +14 -0
  48. data/lib/hoboken/templates/github_action.tt +28 -0
  49. data/lib/hoboken/templates/gitignore +8 -0
  50. data/lib/hoboken/templates/metrics.rake.tt +12 -9
  51. data/lib/hoboken/templates/modular.rb.tt +28 -15
  52. data/lib/hoboken/templates/modular_environment.rb.tt +62 -0
  53. data/lib/hoboken/templates/puma.rb.tt +21 -0
  54. data/lib/hoboken/templates/rspec.rake.tt +9 -0
  55. data/lib/hoboken/templates/rubocop.yml.tt +51 -0
  56. data/lib/hoboken/templates/seeds.rb +12 -0
  57. data/lib/hoboken/templates/sequel.rake +21 -0
  58. data/lib/hoboken/templates/server +15 -0
  59. data/lib/hoboken/templates/setup +28 -0
  60. data/lib/hoboken/templates/sidekiq.rb.tt +21 -0
  61. data/lib/hoboken/templates/spec/app_spec.rb.tt +13 -0
  62. data/lib/hoboken/templates/spec/example_worker_spec.rb.tt +16 -0
  63. data/lib/hoboken/templates/spec/rack_matchers.rb.tt +58 -0
  64. data/lib/hoboken/templates/spec/spec_helper.rb.tt +37 -0
  65. data/lib/hoboken/templates/spec/turnip_helper.rb.tt +10 -0
  66. data/lib/hoboken/templates/styles.css.tt +1 -1
  67. data/lib/hoboken/templates/support/rack_helpers.rb.tt +55 -0
  68. data/lib/hoboken/templates/support/rack_test_assertions.rb.tt +113 -0
  69. data/lib/hoboken/templates/test/test_helper.rb.tt +47 -0
  70. data/lib/hoboken/templates/test/unit/app_test.rb.tt +11 -3
  71. data/lib/hoboken/templates/test/unit/example_worker_test.rb.tt +20 -0
  72. data/lib/hoboken/templates/test_unit.rake.tt +18 -0
  73. data/lib/hoboken/templates/vcr_setup.rb.tt +15 -0
  74. data/lib/hoboken/templates/views/index.erb.tt +11 -4
  75. data/lib/hoboken/templates/views/layout.erb.tt +7 -4
  76. data/lib/hoboken/version.rb +3 -1
  77. data/lib/hoboken.rb +147 -325
  78. data/test/fixtures/Gemfile +3 -3
  79. data/test/fixtures/Gemfile.pristine +3 -2
  80. data/test/integration/active_record_test.rb +66 -0
  81. data/test/integration/airbrake_test.rb +31 -0
  82. data/test/integration/generate_classic_test.rb +75 -0
  83. data/test/integration/generate_modular_test.rb +83 -0
  84. data/test/integration/github_action_test.rb +13 -0
  85. data/test/integration/heroku_test.rb +14 -0
  86. data/test/integration/internationalization_test.rb +26 -0
  87. data/test/integration/metrics_test.rb +54 -0
  88. data/test/integration/omniauth_test.rb +143 -0
  89. data/test/integration/rubocop_test.rb +39 -0
  90. data/test/integration/sequel_test.rb +64 -0
  91. data/test/integration/sidekiq_test.rb +105 -0
  92. data/test/integration/travis_test.rb +13 -0
  93. data/test/integration/turnip_test.rb +51 -0
  94. data/test/integration/twitter_bootstrap_test.rb +39 -0
  95. data/test/integration/vcr_test.rb +54 -0
  96. data/test/test_helper.rb +109 -0
  97. data/test/unit/hoboken_actions_test.rb +82 -53
  98. data/www/Gemfile +4 -0
  99. data/www/README.md +2 -0
  100. data/www/config.rb +11 -0
  101. data/www/source/documentation.html.erb +274 -0
  102. data/www/source/images/hoboken-running.png +0 -0
  103. data/www/source/images/hoboken.png +0 -0
  104. data/www/source/images/sinatra.png +0 -0
  105. data/www/source/index.html.erb +44 -0
  106. data/www/source/javascripts/all.js +1 -0
  107. data/www/source/layouts/layout.erb +38 -0
  108. data/www/source/stylesheets/all.css.scss +116 -0
  109. data/www/source/stylesheets/normalize.css +375 -0
  110. metadata +655 -29
  111. data/lib/hoboken/templates/sprockets.rake +0 -33
  112. data/lib/hoboken/templates/sprockets_chain.rb +0 -26
  113. data/lib/hoboken/templates/sprockets_helper.rb +0 -13
  114. data/lib/hoboken/templates/test/support/rack_test_assertions.rb.tt +0 -79
  115. data/lib/hoboken/templates/test/unit/test_helper.rb.tt +0 -36
@@ -1,15 +1,50 @@
1
- source "https://rubygems.org"
2
- ruby "<%= options[:ruby_version] %>"
1
+ # frozen_string_literal: true
3
2
 
4
- gem "rack_csrf", "~> 2.4.0"
5
- gem "sinatra", "~> 1.4.3"
6
- gem "thin", "~> 1.5.1"
3
+ source 'https://rubygems.org'
4
+ ruby '<%= options[:ruby_version] %>'
5
+
6
+ <% unless options[:api_only] -%>
7
+ gem 'erubi', '~> 1.10'
8
+ <% end -%>
9
+ gem 'puma', '~> 5.2'
10
+ <% unless options[:api_only] -%>
11
+ gem 'rack_csrf', '~> 2.6'
12
+ <% end -%>
13
+ gem 'rake', '~> 12.3'
14
+ gem 'sinatra', '~> 2.1'
15
+ <% unless options[:api_only] -%>
16
+ gem 'sinatra-asset-pipeline', '~> 2.2'
17
+ <% end -%>
18
+ gem 'sinatra-contrib', '~> 2.1'
19
+ <% unless options[:api_only] -%>
20
+ gem 'sinatra-flash', '~> 0.3'
21
+ <% end -%>
22
+ <% unless options[:api_only] -%>
23
+
24
+ group :assets do
25
+ gem 'sassc', '~> 2.4'
26
+ gem 'uglifier', '~> 4.2'
27
+ end
28
+ <% end -%>
7
29
 
8
30
  group :development do
9
- gem "rake", "~> 10.1.0"
10
- gem "sinatra-reloader", "~> 1.0"
31
+ gem 'better_errors', '~> 2.9'
32
+ gem 'binding_of_caller', '~> 1.0'
33
+ gem 'dotenv', '~> 2.7'
34
+ gem 'pry-byebug', '~> 3.9'
35
+ gem 'racksh', '~> 1.0'
11
36
  end
12
37
 
13
38
  group :test do
14
- gem "contest", "~> 0.1.3"
39
+ <% if 'test-unit' == options[:test_framework] -%>
40
+ gem 'contest', '~> 0.1'
41
+ <% end -%>
42
+ gem 'rack-test', '~> 1.1'
43
+ <% if 'rspec' == options[:test_framework] -%>
44
+ gem 'rspec', '~> 3.10'
45
+ <% end -%>
46
+ <% if 'test-unit' == options[:test_framework] -%>
47
+ gem 'test-unit', '~> 3.4'
48
+ <% end -%>
49
+ gem 'warning', '~> 1.2'
15
50
  end
@@ -1,50 +1,132 @@
1
1
  # <%= titleized_name %>
2
2
 
3
+ ## Overview
4
+
3
5
  TODO: Project description.
4
6
 
7
+ ### Features
8
+ #### Feature A
9
+ TODO: Describe feature.
10
+
11
+ #### Feature B
12
+ TODO: Describe feature.
13
+
14
+ ### Links
15
+ * [Production](TODO)
16
+ * [QA](TODO)
17
+ * [Issue Tracking](TODO)
18
+ * [Continuous Integration](TODO)
19
+
20
+ ### Table of Contents
21
+
22
+ * [Overview](#overview)
23
+ * [Getting Started](#getting-started)
24
+ * [Configuration](#configuration)
25
+ <% if 'rspec' == options[:test_framework] -%>
26
+ * [Specs](#specs)
27
+ <% else -%>
28
+ * [Tests](#tests)
29
+ <% end -%>
30
+ * [Rake Tasks](#rake-tasks)
31
+ * [Logging](#logging)
32
+ * [Deploying](#deploying)
33
+ * [Dev Notes](#dev-notes)
34
+
5
35
  ## Getting Started
6
36
 
7
- ### Starting the Server
37
+ The following pre-requisites are needed to build this project:
38
+ * Ruby <%= RUBY_VERSION %>
8
39
 
9
- ### Project Layout
40
+ After cloning this repository, the project can be setup by running the `./bin/setup` script. This script will install dependencies and perform any other required setup tasks.
10
41
 
11
- ## Notes / Use
42
+ Once setup is complete, you can start a local development server by running the `./bin/server` script. Additionally, you can start a development console using the `./bin/console` script. The console uses the [racksh](https://github.com/sickill/racksh) gem which exposes a `$rack` variable that can be used to make simulated HTTP requests.
12
43
 
13
- ## Contributing
44
+ ## Configuration
45
+ Environment variables are used for project configuration. For local development, the `.env` file is used. A sample file is shown below.
14
46
 
15
- ### Issues / Roadmap
47
+ ```
48
+ PORT=9292
49
+ RACK_ENV=development
50
+ SESSION_SECRET=secret
51
+ ```
16
52
 
17
- Use GitHub issues for reporting bug and feature requests.
53
+ Here is a table containing all available environment variable configuration options and their descriptions.
18
54
 
19
- ### Patches / Pull Requests
20
- * Fork the project.
21
- * Make your feature addition or bug fix.
22
- * Add tests for it. This is important so I don’t break it in a future version
23
- unintentionally.
24
- * Commit, do not mess with Rakefile, version, or history (if you want to have
25
- your own version, that is fine but bump version in a commit by itself I can
26
- ignore when I pull).
27
- * Send me a pull request. Bonus points for topic branches.
55
+ <table>
56
+ <thead>
57
+ <tr>
58
+ <th>Name</th>
59
+ <th>Required?</th>
60
+ <th>Default Value</th>
61
+ <th>Description</th>
62
+ </tr>
63
+ </thead>
64
+ <tbody>
65
+ <tr>
66
+ <td>MAX_THREADS</td>
67
+ <td>No</td>
68
+ <td>5</td>
69
+ <td>The maximum number of threads that a Puma worker process should use</td>
70
+ </tr>
71
+ <tr>
72
+ <td>PORT</td>
73
+ <td>No</td>
74
+ <td>9292</td>
75
+ <td>Web server port</td>
76
+ </tr>
77
+ <tr>
78
+ <td>RACK_ENV</td>
79
+ <td>No</td>
80
+ <td>production</td>
81
+ <td>Web server environment (i.e. development, test, production, etc.)</td>
82
+ </tr>
83
+ <tr>
84
+ <td>SESSION_SECRET</td>
85
+ <td>Yes</td>
86
+ <td>None</td>
87
+ <td>Key used for signing and/or encrypting cookies set by the application to maintain session state</td>
88
+ </tr>
89
+ <tr>
90
+ <td>WEB_CONCURRENCY</td>
91
+ <td>No</td>
92
+ <td>1</td>
93
+ <td>The number of Puma worker processes</td>
94
+ </tr>
95
+ </tbody>
96
+ </table>
28
97
 
29
- ## License
30
- (The MIT License)
98
+ ## Development
99
+ This project has the following default behavior:
31
100
 
32
- Copyright (c) <%= Date.today.year %> <%= author %>
101
+ * helpers scripts for common project actions; refer to the `bin` folder
102
+ * uses [Puma](https://github.com/puma/puma) as the default web server
103
+ <% unless options[:api_only] -%>
104
+ * [erubi](https://github.com/jeremyevans/erubi) for templating; escaping is done by default
105
+ * [Rack::Csrf](http://rubygems.org/gems/rack_csrf") is turned on by default
106
+ <% end -%>
107
+ * environment variable support via the [dotenv](http://rubygems.org/gems/dotenv) gem
108
+ * Procfile for [foreman](https://github.com/ddollar/foreman) support
109
+ * code reloading via the [rerun](https://github.com/alexch/rerun) gem is enabled for the development environment
110
+ * [pry-byebug](https://github.com/deivid-rodriguez/pry-byebug") is installed for debugging
33
111
 
34
- Permission is hereby granted, free of charge, to any person obtaining a copy
35
- of this software and associated documentation files (the "Software"), to deal
36
- in the Software without restriction, including without limitation the rights
37
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38
- copies of the Software, and to permit persons to whom the Software is
39
- furnished to do so, subject to the following conditions:
40
-
41
- The above copyright notice and this permission notice shall be included in
42
- all copies or substantial portions of the Software.
43
-
44
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
49
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
50
- SOFTWARE.
112
+ <% if 'rspec' == options[:test_framework] -%>
113
+ ## Specs
114
+ This project uses [RSpec](https://rspec.info/) for testing. Specs can be ran using the rake task `rake spec`.
115
+ <% else -%>
116
+ ## Tests
117
+ This project uses [Test Unit](https://test-unit.github.io/) for testing. Tests can be ran using the rake task `rake test:all`.
118
+ <% end -%>
119
+
120
+ ## Rake Tasks
121
+ To see a list of available tasks run the `rake -T` command.
122
+
123
+ ## Logging
124
+ TODO: Describe how logging is setup (i.e. files, STDOUT, services like Papertrail, DataDog, etc.).
125
+
126
+ ## Deploying
127
+ TODO: Describe how to deploy the project (QA, production, CI setup, etc.). Don't forget to describe how project environment variables are set for the various deployment targets.
128
+
129
+ ## Dev Notes
130
+
131
+ ## License
132
+ Copyright (c) <%= Date.today.year %> <%= author %>
@@ -1,23 +1,27 @@
1
- require "rake/testtask"
1
+ # frozen_string_literal: true
2
+ <% unless options[:api_only] -%>
2
3
 
3
- task :default => "test:all"
4
+ require 'sinatra/asset_pipeline/task'
5
+ require_relative 'config/environment'
6
+
7
+ <% if 'modular' == options[:type] -%>
8
+ Sinatra::AssetPipeline::Task.define! <%= camel_name %>::App
9
+ <% else -%>
10
+ Sinatra::AssetPipeline::Task.define! Sinatra::Application
11
+ <% end -%>
12
+ <% end -%>
4
13
 
5
14
  # Import any external rake tasks
6
15
  Dir.glob('tasks/*.rake').each { |r| import r }
7
16
 
8
- desc "Start the development server"
9
- task :server do
10
- port = ENV["PORT"] || 9292
11
- rack_env = ENV["RACK_ENV"] || "development"
12
- exec("bundle exec thin start -p #{port} -e #{rack_env}")
13
- end
17
+ <% if 'test-unit' == options[:test_framework] -%>
18
+ task default: 'test:all'
14
19
 
15
- namespace :test do
16
- Rake::TestTask.new(:unit) do |t|
17
- t.libs << 'test/unit'
18
- t.test_files = Dir["test/unit/**/*_test.rb"]
19
- end
20
+ desc 'Run CI checks'
21
+ task ci: ['test:all']
22
+ <% else -%>
23
+ task default: 'spec'
20
24
 
21
- desc "Run all tests"
22
- task :all => %w[test:unit]
23
- end
25
+ desc 'Run CI checks'
26
+ task ci: ['spec']
27
+ <% end -%>
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sinatra/activerecord/rake'
4
+
5
+ namespace :db do
6
+ # rubocop:disable Rake/Desc
7
+ task :load_config do
8
+ require_relative '../config/environment'
9
+ end
10
+ # rubocop:enable Rake/Desc
11
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'airbrake'
4
+
5
+ Airbrake.configure do |c|
6
+ c.environment = ENV['RACK_ENV']
7
+ c.ignore_environments = %w[development test]
8
+ c.project_id = ENV['AIRBRAKE_PROJECT_ID']
9
+ c.project_key = ENV['AIRBRAKE_PROJECT_KEY']
10
+
11
+ # Set your application's version, or use a Git SHA
12
+ # c.app_version = '1.0.0' or `git rev-parse --short HEAD`
13
+ end
@@ -1,15 +1,29 @@
1
- require "sinatra"
2
- require "rack/csrf"
1
+ # frozen_string_literal: true
3
2
 
4
- Dir.glob(File.join("helpers", "**", "*.rb")).each do |helper|
5
- require_relative helper
6
- end
7
-
8
- require "sinatra/reloader" if development?
3
+ <% unless options[:api_only] -%>
4
+ require 'erubi'
5
+ require 'rack/csrf'
6
+ <% end -%>
7
+ require 'sinatra'
8
+ <% unless options[:api_only] -%>
9
+ require 'sinatra/asset_pipeline'
10
+ <% end -%>
11
+ <% if options[:api_only] -%>
12
+ require 'sinatra/json'
13
+ <% else -%>
14
+ require 'sinatra/flash'
15
+ <% end -%>
16
+ <% unless options[:api_only] -%>
17
+ require 'sinatra/sprockets-helpers'
18
+ require 'uglifier'
19
+ <% end -%>
9
20
 
10
- use Rack::Session::Cookie, :secret => "TODO: CHANGE ME"
11
- use Rack::Csrf, :raise => true
12
-
13
- get "/" do
21
+ <% if options[:api_only] -%>
22
+ get '/' do
23
+ json message: 'Smoke test successful!'
24
+ end
25
+ <% else -%>
26
+ get '/' do
14
27
  erb :index
15
28
  end
29
+ <% end -%>
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ unless 'production' == ENV['RACK_ENV']
6
+ require 'dotenv'
7
+ Dotenv.load
8
+ end
9
+
10
+ require_relative '../app'
11
+
12
+ configure do
13
+ <% if options[:api_only] -%>
14
+ # Configuration common to all environments goes here...
15
+ <% else -%>
16
+ use Rack::Session::Cookie, secret: ENV['SESSION_SECRET']
17
+ use Rack::Csrf, raise: true, skip_if: proc {
18
+ 'test' == ENV.fetch('RACK_ENV', 'production')
19
+ }
20
+
21
+ set :erb, { escape_html: true }
22
+
23
+ set :assets_precompile, %w[
24
+ javascripts/app.js
25
+ stylesheets/styles.scss
26
+ *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2
27
+ ]
28
+ set :assets_paths, %w[assets vendor] + Sprockets.paths
29
+ set :assets_css_compressor, :scss
30
+ set :assets_js_compressor, Uglifier.new(harmony: true)
31
+ register Sinatra::AssetPipeline
32
+ <% end -%>
33
+ end
34
+
35
+ configure :development do
36
+ require 'better_errors'
37
+ use BetterErrors::Middleware
38
+ BetterErrors.application_root = File.expand_path('..', __dir__)
39
+ end
40
+
41
+ configure :test do
42
+ set :raise_errors, true
43
+ set :dump_errors, false
44
+ set :show_exceptions, false
45
+ end
46
+
47
+ configure :production do
48
+ before do
49
+ redirect request.url.sub('http', 'https') unless request.secure?
50
+ end
51
+ end
@@ -1,3 +1,5 @@
1
- require "bundler/setup"
2
- require File.expand_path("../app", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'config/environment'
4
+
3
5
  run Sinatra::Application
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+
6
+ APP_ROOT = File.expand_path('..', __dir__)
7
+
8
+ def system!(*args)
9
+ system(*args) || abort("\n== Command #{args} failed ==")
10
+ end
11
+
12
+ FileUtils.chdir APP_ROOT do
13
+ puts '== Starting application console =='
14
+ puts 'Console supports racksh. A `$rack` global variable is provided for'
15
+ puts "making simulated requests (i.e. `$rack.get '/'`)."
16
+ puts "\nSee the racksh gem for more details."
17
+ puts "https://github.com/sickill/racksh\n\n"
18
+ system! 'bundle exec racksh'
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ if ENV['DATABASE_URL']
4
+ require 'logger'
5
+ require 'sequel'
6
+
7
+ args = 'test' == ENV['RACK_ENV'] ? ['tmp/db_test.log', 'daily'] : [$stdout]
8
+ DB = Sequel.connect(ENV['DATABASE_URL'], loggers: [Logger.new(*args)])
9
+ Sequel.extension :migration
10
+
11
+ unless Dir.glob('db/migrate/*.rb').empty?
12
+ begin
13
+ Sequel::Migrator.check_current(DB, 'db/migrate')
14
+ rescue Sequel::Migrator::NotCurrentError
15
+ puts 'Pending migrations detected... running migrations'
16
+ Sequel::Migrator.run(DB, 'db/migrate')
17
+ puts 'Database migrations completed'
18
+ end
19
+ end
20
+ DB.freeze unless 'development' == ENV['RACK_ENV']
21
+ puts 'Database connected'
22
+ else
23
+ puts 'DATABASE_URL not set; skipping database initialization'
24
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Example Sidekiq worker. Refer to Sidekiq's documentation[1] for
4
+ # more information.
5
+ #
6
+ # [1]: https://github.com/mperham/sidekiq/wiki/Best-Practices
7
+ #
8
+ class ExampleWorker
9
+ include Sidekiq::Worker
10
+
11
+ def perform
12
+ logger.info 'Doing some work!'
13
+ end
14
+ end
@@ -0,0 +1,28 @@
1
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
2
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
3
+
4
+ name: Ruby
5
+
6
+ on:
7
+ push:
8
+ pull_request:
9
+ schedule:
10
+ - cron: "0 4 * * *"
11
+
12
+ jobs:
13
+ test:
14
+
15
+ runs-on: ubuntu-latest
16
+ strategy:
17
+ matrix:
18
+ ruby-version: [<%= RUBY_VERSION %>]
19
+
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - name: Set up Ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true
27
+ - name: Run tests
28
+ run: bundle exec rake ci
@@ -1,4 +1,12 @@
1
1
  .DS_Store
2
2
  .bundle
3
+ .byebug_history
4
+ .env
5
+ .env.test
6
+ .rspec_status
3
7
  /tmp
8
+ coverage
9
+ db/*.db
10
+ public
11
+ spec/examples.txt
4
12
  tags
@@ -1,9 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  unless 'production' == ENV['RACK_ENV']
4
+ require 'bundler/setup'
2
5
  require 'flay'
3
- desc "Analyze code for structural similarities"
6
+
7
+ desc 'Analyze code for structural similarities'
4
8
  task :flay do
5
9
  flay = Flay.new
6
- files = FileList["app.rb", "app/**/*.rb"]
10
+ files = FileList['app.rb', 'app/**/*.rb']
7
11
  flay.process(*files)
8
12
  threshold = 200
9
13
 
@@ -13,21 +17,20 @@ unless 'production' == ENV['RACK_ENV']
13
17
  end
14
18
  end
15
19
 
16
- require "flog"
20
+ require 'flog'
17
21
  desc 'Analyze code complexity'
18
22
  task :flog do
19
23
  flog = Flog.new
20
- flog.flog FileList["app.rb", "app/**/*.rb"]
24
+ files = FileList['app.rb', 'app/**/*.rb']
25
+ flog.flog(*files)
21
26
  threshold = 50
22
27
 
23
- bad_methods = flog.totals.select do |name, score|
28
+ bad_methods = flog.totals.select do |_name, score|
24
29
  score > threshold
25
30
  end
26
31
 
27
- bad_methods.sort do |a, b|
28
- a[1] <=> b[1]
29
- end.each do |name, score|
30
- puts "%8.1f: %s" % [score, name]
32
+ bad_methods.sort_by { |a| a[1] }.each do |name, score|
33
+ puts format('%<score>8.1f: %<name>s', score: score, name: name)
31
34
  end
32
35
 
33
36
  unless bad_methods.empty?
@@ -1,26 +1,39 @@
1
- require "sinatra/base"
2
- require "rack/csrf"
1
+ # frozen_string_literal: true
3
2
 
4
- Dir.glob(File.join("helpers", "**", "*.rb")).each do |helper|
3
+ <% unless options[:api_only] -%>
4
+ require 'erubi'
5
+ require 'rack/csrf'
6
+ <% end -%>
7
+ require 'sinatra/base'
8
+ <% unless options[:api_only] -%>
9
+ require 'sinatra/asset_pipeline'
10
+ <% end -%>
11
+ <% if options[:api_only] -%>
12
+ require 'sinatra/json'
13
+ <% else -%>
14
+ require 'sinatra/flash'
15
+ <% end -%>
16
+ <% unless options[:api_only] -%>
17
+ require 'sinatra/sprockets-helpers'
18
+ require 'uglifier'
19
+ <% end -%>
20
+
21
+ Dir.glob(File.join('helpers', '**', '*.rb')).each do |helper|
5
22
  require_relative helper
6
23
  end
7
24
 
8
25
  module <%= camel_name %>
26
+ # Sinatra web application
27
+ #
9
28
  class App < Sinatra::Base
10
- set :root, File.dirname(__FILE__)
11
-
12
- enable :logging
13
-
14
- use Rack::Session::Cookie, :secret => "TODO: CHANGE ME"
15
- use Rack::Csrf, :raise => true
16
-
17
- configure :development do
18
- require "sinatra/reloader"
19
- register Sinatra::Reloader
29
+ <% if options[:api_only] -%>
30
+ get '/' do
31
+ json message: 'Smoke test successful!'
20
32
  end
21
-
22
- get "/" do
33
+ <% else -%>
34
+ get '/' do
23
35
  erb :index
24
36
  end
37
+ <% end -%>
25
38
  end
26
39
  end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ unless 'production' == ENV['RACK_ENV']
6
+ require 'dotenv'
7
+ Dotenv.load
8
+ end
9
+
10
+ require_relative '../app'
11
+
12
+ module <%= camel_name %>
13
+ # Re-opening application to apply configuration.
14
+ #
15
+ class App < Sinatra::Base
16
+ configure do
17
+ set :root, File.expand_path('..', __dir__)
18
+ <% unless options[:api_only] -%>
19
+ set :erb, { escape_html: true }
20
+ <% end -%>
21
+
22
+ enable :logging
23
+ <% unless options[:api_only] -%>
24
+
25
+ use Rack::Session::Cookie, secret: ENV['SESSION_SECRET']
26
+ use Rack::Csrf, raise: true, skip_if: proc {
27
+ 'test' == ENV.fetch('RACK_ENV', 'production')
28
+ }
29
+
30
+ register Sinatra::Flash
31
+
32
+ set :assets_precompile, %w[
33
+ javascripts/app.js
34
+ stylesheets/styles.scss
35
+ *.png *.jpg *.svg *.eot *.ttf *.woff *.woff2
36
+ ]
37
+ set :assets_paths, %w[assets vendor] + Sprockets.paths
38
+ set :assets_css_compressor, :scss
39
+ set :assets_js_compressor, Uglifier.new(harmony: true)
40
+ register Sinatra::AssetPipeline
41
+ <% end -%>
42
+ end
43
+
44
+ configure :development do
45
+ require 'better_errors'
46
+ use BetterErrors::Middleware
47
+ BetterErrors.application_root = File.expand_path('..', __dir__)
48
+ end
49
+
50
+ configure :test do
51
+ set :raise_errors, true
52
+ set :dump_errors, false
53
+ set :show_exceptions, false
54
+ end
55
+
56
+ configure :production do
57
+ before do
58
+ redirect request.url.sub('http', 'https') unless request.secure?
59
+ end
60
+ end
61
+ end
62
+ end