eivo-rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +19 -0
  5. data/README.md +46 -0
  6. data/Rakefile +1 -0
  7. data/app/controllers/eivo/application_controller.rb +11 -0
  8. data/app/controllers/eivo/concerns/exception.rb +23 -0
  9. data/app/controllers/eivo/concerns/resource.rb +65 -0
  10. data/app/controllers/eivo/concerns/resources.rb +73 -0
  11. data/app/controllers/eivo/status_controller.rb +11 -0
  12. data/bin/eivo +5 -0
  13. data/config/initializers/sentry.rb +8 -0
  14. data/config/routes.rb +7 -0
  15. data/eivo-rails.gemspec +29 -0
  16. data/lib/eivo-rails/cli.rb +12 -0
  17. data/lib/eivo-rails/engine.rb +9 -0
  18. data/lib/eivo-rails/environments/development.rb +61 -0
  19. data/lib/eivo-rails/environments/production.rb +88 -0
  20. data/lib/eivo-rails/environments/staging.rb +11 -0
  21. data/lib/eivo-rails/environments/test.rb +44 -0
  22. data/lib/eivo-rails.rb +24 -0
  23. data/lib/generators/eivo/USAGE +3 -0
  24. data/lib/generators/eivo/install_generator.rb +104 -0
  25. data/lib/generators/eivo/templates/.env.example +5 -0
  26. data/lib/generators/eivo/templates/.ruby-version +1 -0
  27. data/lib/generators/eivo/templates/Gemfile +47 -0
  28. data/lib/generators/eivo/templates/Procfile +1 -0
  29. data/lib/generators/eivo/templates/app/controllers/application_controller.rb +2 -0
  30. data/lib/generators/eivo/templates/config/application.rb +20 -0
  31. data/lib/generators/eivo/templates/config/database.example.yml +24 -0
  32. data/lib/generators/eivo/templates/config/puma.rb +30 -0
  33. data/lib/generators/eivo/templates/db/migrate/enable_btree_gin_extension.rb +7 -0
  34. data/lib/generators/eivo/templates/db/migrate/enable_pg_stat_statements_extension.rb +7 -0
  35. data/lib/generators/eivo/templates/db/migrate/enable_pgcrypto_extension.rb +7 -0
  36. data/lib/generators/eivo/templates/db/migrate/enable_unaccent_extension.rb +7 -0
  37. metadata +164 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4b0b26d128dd6c4795f2f6104c96023fb5a7d956
4
+ data.tar.gz: e9b0b4250a33b6b6a08a7c9700afb9553f63092d
5
+ SHA512:
6
+ metadata.gz: d05c3a87a47cbb98193da87fc5e581c89061797184aabdc47ca1628825a2efacc07a566a79c51f5cde67f911d1fbc2c216097b06246354611dfe7f19954b9f48
7
+ data.tar.gz: d1cffbafa610b523041d31903c87a998f8f3677cf27612fc5cd06ec3060386e9b7bb334764f7272173bc1da9fdd4535c745d2a24135e2fca28b28cc6414a1194
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .DS_Store
2
+ /.bundle/
3
+ /pkg/
4
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2019 Jonathan VUKOVICH-TRIBOUHARET
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # EIVO Rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/eivo-rails.svg)](http://badge.fury.io/rb/eivo-rails)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'eivo-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install eivo-rails -N
20
+
21
+ ## Usage
22
+
23
+ If you don't have a Ruby On Rails project:
24
+
25
+ $ rails new ../example/ -d postgresql --skip-yarn --skip-active-storage --skip-action-cable --skip-spring --skip-coffee --skip-turbolinks --skip-test --skip-system-test --skip-bootsnap --skip-action-mailer
26
+
27
+ Then:
28
+
29
+ $ rails g eivo:install
30
+
31
+ Add missing credentials:
32
+
33
+ $ rails credentials:edit
34
+
35
+ ```
36
+ sentry:
37
+ dsn: ""
38
+ ```
39
+
40
+ ### Warning
41
+
42
+ SSL / TLS must be managed by the web server (nginx), don't enable `force_ssl` option.
43
+
44
+ ## License
45
+
46
+ This project is released under the MIT license. See the LICENSE file for more info.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class ApplicationController < ::ActionController::Base
5
+
6
+ include EIVO::Concerns::Exception
7
+
8
+ include HttpAcceptLanguage::AutoLocale
9
+
10
+ end
11
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ module Concerns
5
+ module Exception
6
+
7
+ extend ::ActiveSupport::Concern
8
+
9
+ included do
10
+ before_action :set_exception_context
11
+ end
12
+
13
+ def set_exception_context
14
+ ::Raven.extra_context(
15
+ params: params.to_unsafe_h,
16
+ url: request.url,
17
+ request_id: request.request_id
18
+ )
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ module Concerns
5
+ module Resource
6
+ extend ::ActiveSupport::Concern
7
+
8
+ def show
9
+ @object ||= collection
10
+ end
11
+
12
+ def new
13
+ @object ||= collection.new
14
+ end
15
+
16
+ def create
17
+ @object ||= collection.new(object_params_create)
18
+ if @object.save
19
+ render :new
20
+ else
21
+ redirect_to action: :index
22
+ end
23
+ end
24
+
25
+ def edit
26
+ @object ||= collection
27
+ end
28
+
29
+ def update
30
+ @object ||= collection
31
+ if @object.update(object_params_update)
32
+ render :edit
33
+ else
34
+ redirect_to action: :index
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @object ||= collection
40
+
41
+ @object.destroy
42
+ redirect_to action: :index
43
+ end
44
+
45
+ protected
46
+
47
+ def collection
48
+ raise NotImplementedError
49
+ end
50
+
51
+ def object_params
52
+ raise NotImplementedError
53
+ end
54
+
55
+ def object_params_create
56
+ object_params
57
+ end
58
+
59
+ def object_params_update
60
+ object_params
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ module Concerns
5
+ module Resources
6
+ extend ::ActiveSupport::Concern
7
+
8
+ def index
9
+ @objects ||= collection_index
10
+ end
11
+
12
+ def show
13
+ @object ||= collection.find(params[:id])
14
+ end
15
+
16
+ def new
17
+ @object ||= collection.new
18
+ end
19
+
20
+ def create
21
+ @object ||= collection.new(object_params_create)
22
+ if @object.save
23
+ redirect_to action: :index
24
+ else
25
+ render :new
26
+ end
27
+ end
28
+
29
+ def edit
30
+ @object ||= collection.find(params[:id])
31
+ end
32
+
33
+ def update
34
+ @object ||= collection.find(params[:id])
35
+ if @object.update(object_params_update)
36
+ redirect_to action: :index
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ def destroy
43
+ @object ||= collection.find(params[:id])
44
+ @object.destroy
45
+
46
+ redirect_to action: :index
47
+ end
48
+
49
+ protected
50
+
51
+ def collection
52
+ raise NotImplementedError
53
+ end
54
+
55
+ def collection_index
56
+ collection
57
+ end
58
+
59
+ def object_params
60
+ raise NotImplementedError
61
+ end
62
+
63
+ def object_params_create
64
+ object_params
65
+ end
66
+
67
+ def object_params_update
68
+ object_params
69
+ end
70
+
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class StatusController < ApplicationController
5
+
6
+ def index
7
+ head :ok
8
+ end
9
+
10
+ end
11
+ end
data/bin/eivo ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eivo-rails/cli'
4
+
5
+ EIVO::CLI.start
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'raven'
4
+
5
+ Raven.configure do |config|
6
+ config.environments = %w[ staging production ]
7
+ config.dsn = Rails.application.credentials.dig(:sentry, :dsn)
8
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ EIVO::Engine.routes.draw do
4
+ scope module: 'eivo' do
5
+ get :status, to: 'status#index'
6
+ end
7
+ end
@@ -0,0 +1,29 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'eivo-rails'
5
+ spec.version = '0.0.1'
6
+ spec.authors = ['Jonathan VUKOVICH-TRIBOUHARET']
7
+ spec.email = ['jonathan@eivo.co']
8
+
9
+ spec.summary = 'EIVO Rails'
10
+ spec.description = 'EIVO Rails'
11
+ spec.homepage = 'https://www.eivo.co'
12
+ spec.license = 'MIT'
13
+
14
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
+ `git ls-files -z`.split("\x0")
16
+ end
17
+ spec.executables << 'eivo'
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'thor'
21
+
22
+ spec.add_dependency 'oj'
23
+ spec.add_dependency 'multi_json'
24
+
25
+ spec.add_dependency 'sentry-raven'
26
+
27
+ spec.add_development_dependency 'bundler'
28
+ spec.add_development_dependency 'rake'
29
+ end
@@ -0,0 +1,12 @@
1
+ require 'thor'
2
+
3
+ module EIVO
4
+ class CLI < Thor
5
+
6
+ desc 'install', 'Initialize default files'
7
+ def install(args = nil)
8
+ system("rails g eivo:install #{args}")
9
+ end
10
+
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class Engine < ::Rails::Engine
5
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
6
+ inflect.acronym 'EIVO'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class Environment
5
+ def self.development
6
+ Rails.application.configure do
7
+ # Settings specified here will take precedence over those in config/application.rb.
8
+
9
+ # In the development environment your application's code is reloaded on
10
+ # every request. This slows down response time but is perfect for development
11
+ # since you don't have to restart the web server when you make code changes.
12
+ config.cache_classes = false
13
+
14
+ # Do not eager load code on boot.
15
+ config.eager_load = false
16
+
17
+ # Show full error reports.
18
+ config.consider_all_requests_local = true
19
+
20
+ # Enable/disable caching. By default caching is disabled.
21
+ # Run rails dev:cache to toggle caching.
22
+ if Rails.root.join('tmp', 'caching-dev.txt').exist?
23
+ config.action_controller.perform_caching = true
24
+
25
+ config.cache_store = :memory_store
26
+ config.public_file_server.headers = {
27
+ 'Cache-Control' => "public, max-age=#{2.days.to_i}"
28
+ }
29
+ else
30
+ config.action_controller.perform_caching = false
31
+
32
+ config.cache_store = :null_store
33
+ end
34
+
35
+ # Print deprecation notices to the Rails logger.
36
+ config.active_support.deprecation = :log
37
+
38
+ # Raise an error on page load if there are pending migrations.
39
+ config.active_record.migration_error = :page_load
40
+
41
+ # Highlight code that triggered database queries in logs.
42
+ config.active_record.verbose_query_logs = true
43
+
44
+ # Debug mode disables concatenation and preprocessing of assets.
45
+ # This option may cause significant delays in view rendering with a large
46
+ # number of complex assets.
47
+ config.assets.debug = true
48
+
49
+ # Suppress logger output for asset requests.
50
+ config.assets.quiet = true
51
+
52
+ # Raises error for missing translations
53
+ # config.action_view.raise_on_missing_translations = true
54
+
55
+ # Use an evented file watcher to asynchronously detect changes in source code,
56
+ # routes, locales, etc. This feature depends on the listen gem.
57
+ config.file_watcher = ActiveSupport::EventedFileUpdateChecker
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class Environment
5
+ def self.production
6
+ Rails.application.configure do
7
+ # Settings specified here will take precedence over those in config/application.rb.
8
+
9
+ # Code is not reloaded between requests.
10
+ config.cache_classes = true
11
+
12
+ # Eager load code on boot. This eager loads most of Rails and
13
+ # your application in memory, allowing both threaded web servers
14
+ # and those relying on copy on write to perform better.
15
+ # Rake tasks automatically ignore this option for performance.
16
+ config.eager_load = true
17
+
18
+ # Full error reports are disabled and caching is turned on.
19
+ config.consider_all_requests_local = false
20
+ config.action_controller.perform_caching = true
21
+
22
+ # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
23
+ # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
24
+ # config.require_master_key = true
25
+
26
+ # Disable serving static files from the `/public` folder by default since
27
+ # Apache or NGINX already handles this.
28
+ config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
29
+
30
+ # Compress JavaScripts and CSS.
31
+ config.assets.js_compressor = :uglifier
32
+ # config.assets.css_compressor = :sass
33
+
34
+ # Do not fallback to assets pipeline if a precompiled asset is missed.
35
+ config.assets.compile = false
36
+
37
+ # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
38
+
39
+ # Enable serving of images, stylesheets, and JavaScripts from an asset server.
40
+ # config.action_controller.asset_host = 'http://assets.example.com'
41
+
42
+ # Specifies the header that your server uses for sending files.
43
+ # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
44
+ config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
45
+
46
+ # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
47
+ # config.force_ssl = true
48
+
49
+ # Use the lowest log level to ensure availability of diagnostic information
50
+ # when problems arise.
51
+ config.log_level = :debug
52
+
53
+ # Prepend all log lines with the following tags.
54
+ config.log_tags = [ :request_id ]
55
+
56
+ # Use a different cache store in production.
57
+ # config.cache_store = :mem_cache_store
58
+
59
+ # Use a real queuing backend for Active Job (and separate queues per environment)
60
+ # config.active_job.queue_adapter = :resque
61
+ # config.active_job.queue_name_prefix = "id_yokitup_com_#{Rails.env}"
62
+
63
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
64
+ # the I18n.default_locale when a translation cannot be found).
65
+ config.i18n.fallbacks = true
66
+
67
+ # Send deprecation notices to registered listeners.
68
+ config.active_support.deprecation = :notify
69
+
70
+ # Use default logging formatter so that PID and timestamp are not suppressed.
71
+ config.log_formatter = ::Logger::Formatter.new
72
+
73
+ # Use a different logger for distributed setups.
74
+ # require 'syslog/logger'
75
+ # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
76
+
77
+ if ENV["RAILS_LOG_TO_STDOUT"].present?
78
+ logger = ActiveSupport::Logger.new(STDOUT)
79
+ logger.formatter = config.log_formatter
80
+ config.logger = ActiveSupport::TaggedLogging.new(logger)
81
+ end
82
+
83
+ # Do not dump schema after migrations.
84
+ config.active_record.dump_schema_after_migration = false
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'production'
4
+
5
+ module EIVO
6
+ class Environment
7
+ def self.staging
8
+ production
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module EIVO
4
+ class Environment
5
+ def self.test
6
+ Rails.application.configure do
7
+ # Settings specified here will take precedence over those in config/application.rb.
8
+
9
+ # The test environment is used exclusively to run your application's
10
+ # test suite. You never need to work with it otherwise. Remember that
11
+ # your test database is "scratch space" for the test suite and is wiped
12
+ # and recreated between test runs. Don't rely on the data there!
13
+ config.cache_classes = true
14
+
15
+ # Do not eager load code on boot. This avoids loading your whole application
16
+ # just for the purpose of running a single test. If you are using a tool that
17
+ # preloads Rails for running tests, you may have to set it to true.
18
+ config.eager_load = false
19
+
20
+ # Configure public file server for tests with Cache-Control for performance.
21
+ config.public_file_server.enabled = true
22
+ config.public_file_server.headers = {
23
+ 'Cache-Control' => "public, max-age=#{1.hour.to_i}"
24
+ }
25
+
26
+ # Show full error reports and disable caching.
27
+ config.consider_all_requests_local = true
28
+ config.action_controller.perform_caching = false
29
+
30
+ # Raise exceptions instead of rendering exception templates.
31
+ config.action_dispatch.show_exceptions = false
32
+
33
+ # Disable request forgery protection in test environment.
34
+ config.action_controller.allow_forgery_protection = false
35
+
36
+ # Print deprecation notices to the stderr.
37
+ config.active_support.deprecation = :stderr
38
+
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/eivo-rails.rb ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'raven'
4
+
5
+ require 'oj'
6
+ require 'multi_json'
7
+
8
+ require_relative 'eivo-rails/engine'
9
+
10
+ module EIVO
11
+ class << self
12
+ def configure(application)
13
+ application.config.load_defaults 5.2
14
+ application.config.require_master_key = true
15
+
16
+ application.config.generators do |g|
17
+ g.orm :active_record, primary_key_type: :uuid
18
+ end
19
+
20
+ require_relative "eivo-rails/environments/#{Rails.env}"
21
+ EIVO::Environment.send(Rails.env)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ Initialize default files
2
+
3
+ rails g eivo:install
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ module EIVO
6
+ class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def self.namespace(name = nil)
12
+ @namespace ||= super.sub('e_i_v_o', 'eivo')
13
+ end
14
+
15
+ # Implement the required interface for Rails::Generators::Migration.
16
+ def self.next_migration_number(dirname)
17
+ next_migration_number = current_migration_number(dirname) + 1
18
+ ActiveRecord::Migration.next_migration_number(next_migration_number)
19
+ end
20
+
21
+ def create_initializer_file
22
+ @application = Rails.application.class.parent_name
23
+
24
+ remove_dir 'config/environments'
25
+
26
+ copy_file 'Gemfile'
27
+ copy_file 'Procfile'
28
+ copy_file '.env.example'
29
+ copy_file '.ruby-version'
30
+
31
+ create_restart_files
32
+
33
+ template 'config/application.rb'
34
+ copy_file 'config/puma.rb'
35
+ template 'config/database.example.yml'
36
+ template 'config/database.example.yml', 'config/database.yml', skip: true
37
+
38
+ copy_file 'app/controllers/application_controller.rb'
39
+
40
+ migration_template 'db/migrate/enable_pgcrypto_extension.rb', 'db/migrate/enable_pgcrypto_extension.rb', skip: true
41
+ migration_template 'db/migrate/enable_pg_stat_statements_extension.rb', 'db/migrate/enable_pg_stat_statements_extension.rb', skip: true
42
+ migration_template 'db/migrate/enable_btree_gin_extension.rb', 'db/migrate/enable_btree_gin_extension.rb', skip: true
43
+ migration_template 'db/migrate/enable_unaccent_extension.rb', 'db/migrate/enable_unaccent_extension.rb', skip: true
44
+
45
+ route "mount EIVO::Engine => '/'"
46
+ end
47
+
48
+ def create_restart_files
49
+ restart_code = <<-'EOF'
50
+ ### EIVO begin ###
51
+
52
+ bundle exec rails assets:precompile
53
+ bundle exec pumactl -F config/puma.rb restart
54
+
55
+ ### EIVO end ###
56
+ EOF
57
+
58
+ stop_code = <<-'EOF'
59
+ ### EIVO begin ###
60
+
61
+ bundle exec pumactl -F config/puma.rb stop
62
+
63
+ ### EIVO end ###
64
+ EOF
65
+
66
+ header_production = <<-'EOF'
67
+ #!/usr/bin/env bash
68
+ export RACK_ENV="production"
69
+ export RAILS_ENV="production"
70
+
71
+ EOF
72
+ header_staging = <<-'EOF'
73
+ #!/usr/bin/env bash
74
+ export RACK_ENV="staging"
75
+ export RAILS_ENV="staging"
76
+
77
+ EOF
78
+
79
+ create_file 'restart_production.sh', header_production, skip: true
80
+ create_file 'stop_production.sh', header_production, skip: true
81
+ create_file 'restart_staging.sh', header_staging, skip: true
82
+ create_file 'stop_staging.sh', header_staging, skip: true
83
+
84
+ # Remove old code if present
85
+ regexp = /\n### EIVO begin ###.*### EIVO end ###/m
86
+ gsub_file 'restart_production.sh', regexp, ''
87
+ gsub_file 'restart_staging.sh', regexp, ''
88
+ gsub_file 'stop_production.sh', regexp, ''
89
+ gsub_file 'stop_staging.sh', regexp, ''
90
+
91
+ # Inject new code
92
+ inject_into_file 'restart_production.sh', restart_code, after: header_production
93
+ inject_into_file 'stop_production.sh', stop_code, after: header_production
94
+ inject_into_file 'restart_staging.sh', restart_code, after: header_staging
95
+ inject_into_file 'stop_staging.sh', stop_code, after: header_staging
96
+
97
+ chmod 'restart_production.sh', 0755
98
+ chmod 'stop_production.sh', 0755
99
+ chmod 'restart_staging.sh', 0755
100
+ chmod 'stop_staging.sh', 0755
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,5 @@
1
+ WEB_CONCURRENCY="0"
2
+ RAILS_MAX_THREADS="5"
3
+ DB_POOL="5" # RAILS_MAX_THREADS
4
+ DB_STATEMENT_TIMEOUT="10000"
5
+ REDIS_URL="redis://localhost:6379/0"
@@ -0,0 +1 @@
1
+ ruby-2.6.3
@@ -0,0 +1,47 @@
1
+ source 'https://rubygems.org'
2
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
+
4
+ ruby '2.6.3'
5
+
6
+ gem 'rails', '~> 5.2.3'
7
+ gem 'pg', '>= 0.18', '< 2.0'
8
+ gem 'puma', '~> 3.11'
9
+ gem 'sass-rails', '~> 5.0'
10
+ gem 'uglifier', '>= 1.3.0'
11
+ gem 'mini_racer', platforms: :ruby
12
+
13
+ group :development, :test do
14
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
15
+ end
16
+
17
+ group :development do
18
+ gem 'web-console', '>= 3.3.0'
19
+ gem 'listen', '>= 3.0.5', '< 3.2'
20
+ end
21
+
22
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
23
+
24
+ group :development, :test do
25
+ gem 'derailed_benchmarks'
26
+ gem 'factory_bot_rails'
27
+ gem 'faker'
28
+ gem 'rspec-rails'
29
+ gem 'brakeman'
30
+ gem 'rubocop'
31
+ gem 'rubocop-rspec'
32
+ gem 'webmock'
33
+ end
34
+
35
+ gem 'eivo-rails'
36
+
37
+ gem 'bcrypt'
38
+ gem 'jwt'
39
+
40
+ gem 'validates_email_format_of'
41
+ gem 'validates_phone_format_of'
42
+ gem 'validates_timeliness'
43
+
44
+ gem 'rails-i18n'
45
+ gem 'http_accept_language'
46
+
47
+ ### EIVO ###
@@ -0,0 +1 @@
1
+ web: bundle exec puma -C config/puma.rb
@@ -0,0 +1,2 @@
1
+ class ApplicationController < EIVO::ApplicationController
2
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'boot'
4
+
5
+ require 'rails'
6
+ require 'active_model/railtie'
7
+ require 'active_record/railtie'
8
+ require 'action_controller/railtie'
9
+ require "action_view/railtie"
10
+ require "sprockets/railtie"
11
+
12
+ Bundler.require(*Rails.groups)
13
+
14
+ module <%= @application %>
15
+ class Application < Rails::Application
16
+ EIVO.configure(self)
17
+
18
+ config.i18n.available_locales = %w(en fr)
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ default: &default
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ pool: <%%= ENV.fetch('DB_POOL') { 5 } %>
5
+ host: db
6
+ username: postgres
7
+ variables:
8
+ statement_timeout: <%%= ENV.fetch('DB_STATEMENT_TIMEOUT') { 10000 } %>
9
+
10
+ development:
11
+ <<: *default
12
+ database: <%= @application.parameterize %>_development
13
+
14
+ test:
15
+ <<: *default
16
+ database: <%= @application.parameterize %>_test
17
+
18
+ staging:
19
+ <<: *default
20
+ database: <%= @application.parameterize %>_staging
21
+
22
+ production:
23
+ <<: *default
24
+ database: <%= @application.parameterize %>
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ workers ENV.fetch('WEB_CONCURRENCY') { 0 }
4
+ threads_count = ENV.fetch('RAILS_MAX_THREADS') { 5 }
5
+ threads threads_count, threads_count
6
+
7
+ environment ENV.fetch('RAILS_ENV') { "development" }
8
+
9
+ if ['production', 'staging'].include?(ENV['RAILS_ENV'])
10
+ bind 'unix://tmp/sockets/puma.sock'
11
+ pidfile 'tmp/pids/puma.pid'
12
+ state_path 'tmp/pids/puma.state'
13
+ daemonize true
14
+ else
15
+ port ENV.fetch('PORT') { 3000 }
16
+ end
17
+
18
+ before_fork do
19
+ ActiveRecord::Base.connection.disconnect!
20
+ end
21
+
22
+ on_worker_boot do
23
+ ActiveSupport.on_load(:active_record) do
24
+ ActiveRecord::Base.establish_connection
25
+ end
26
+ end
27
+
28
+ preload_app!
29
+
30
+ plugin :tmp_restart
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EnableBtreeGinExtension < ActiveRecord::Migration[5.2]
4
+ def change
5
+ enable_extension 'btree_gin'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EnablePgStatStatementsExtension < ActiveRecord::Migration[5.2]
4
+ def change
5
+ enable_extension 'pg_stat_statements'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EnablePgcryptoExtension < ActiveRecord::Migration[5.2]
4
+ def change
5
+ enable_extension 'pgcrypto'
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class EnableUnaccentExtension < ActiveRecord::Migration[5.2]
4
+ def change
5
+ enable_extension 'unaccent'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eivo-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan VUKOVICH-TRIBOUHARET
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-03 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: oj
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: multi_json
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: sentry-raven
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: rake
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
+ description: EIVO Rails
98
+ email:
99
+ - jonathan@eivo.co
100
+ executables:
101
+ - eivo
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE
108
+ - README.md
109
+ - Rakefile
110
+ - app/controllers/eivo/application_controller.rb
111
+ - app/controllers/eivo/concerns/exception.rb
112
+ - app/controllers/eivo/concerns/resource.rb
113
+ - app/controllers/eivo/concerns/resources.rb
114
+ - app/controllers/eivo/status_controller.rb
115
+ - bin/eivo
116
+ - config/initializers/sentry.rb
117
+ - config/routes.rb
118
+ - eivo-rails.gemspec
119
+ - lib/eivo-rails.rb
120
+ - lib/eivo-rails/cli.rb
121
+ - lib/eivo-rails/engine.rb
122
+ - lib/eivo-rails/environments/development.rb
123
+ - lib/eivo-rails/environments/production.rb
124
+ - lib/eivo-rails/environments/staging.rb
125
+ - lib/eivo-rails/environments/test.rb
126
+ - lib/generators/eivo/USAGE
127
+ - lib/generators/eivo/install_generator.rb
128
+ - lib/generators/eivo/templates/.env.example
129
+ - lib/generators/eivo/templates/.ruby-version
130
+ - lib/generators/eivo/templates/Gemfile
131
+ - lib/generators/eivo/templates/Procfile
132
+ - lib/generators/eivo/templates/app/controllers/application_controller.rb
133
+ - lib/generators/eivo/templates/config/application.rb
134
+ - lib/generators/eivo/templates/config/database.example.yml
135
+ - lib/generators/eivo/templates/config/puma.rb
136
+ - lib/generators/eivo/templates/db/migrate/enable_btree_gin_extension.rb
137
+ - lib/generators/eivo/templates/db/migrate/enable_pg_stat_statements_extension.rb
138
+ - lib/generators/eivo/templates/db/migrate/enable_pgcrypto_extension.rb
139
+ - lib/generators/eivo/templates/db/migrate/enable_unaccent_extension.rb
140
+ homepage: https://www.eivo.co
141
+ licenses:
142
+ - MIT
143
+ metadata: {}
144
+ post_install_message:
145
+ rdoc_options: []
146
+ require_paths:
147
+ - lib
148
+ required_ruby_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ">="
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 2.4.5
161
+ signing_key:
162
+ specification_version: 4
163
+ summary: EIVO Rails
164
+ test_files: []