carrierwave_backgrounder 0.4.3 → 1.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +8 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +1 -1
- data/README.md +59 -67
- data/carrierwave_backgrounder.gemspec +7 -2
- data/lib/backgrounder/orm/activemodel.rb +7 -7
- data/lib/backgrounder/orm/base.rb +18 -12
- data/lib/backgrounder/support/backends.rb +1 -45
- data/lib/backgrounder/version.rb +1 -1
- data/lib/backgrounder/workers/active_job/process_asset.rb +14 -0
- data/lib/backgrounder/workers/active_job/store_asset.rb +14 -0
- data/lib/backgrounder/workers/process_asset.rb +2 -0
- data/lib/backgrounder/workers/process_asset_mixin.rb +16 -7
- data/lib/backgrounder/workers/store_asset.rb +2 -0
- data/lib/backgrounder/workers/store_asset_mixin.rb +14 -19
- data/lib/backgrounder/workers.rb +0 -2
- data/lib/carrierwave_backgrounder.rb +24 -10
- data/lib/generators/carrierwave_backgrounder/install_generator.rb +1 -1
- data/lib/generators/carrierwave_backgrounder/templates/config/initializers/carrierwave_backgrounder.rb +1 -7
- data/spec/backgrounder/orm/activemodel_spec.rb +2 -5
- data/spec/backgrounder/support/backends_spec.rb +0 -159
- data/spec/backgrounder/workers/process_asset_spec.rb +8 -6
- data/spec/backgrounder/workers/store_asset_spec.rb +20 -99
- data/spec/integrations/process_in_background_multi_upload_spec.rb +81 -0
- data/spec/integrations/process_in_background_spec.rb +75 -0
- data/spec/integrations/store_in_background_multi_upload_spec.rb +87 -0
- data/spec/integrations/store_in_background_spec.rb +86 -0
- data/spec/rails_helper.rb +27 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/dummy_app/Gemfile +49 -0
- data/spec/support/dummy_app/README.md +24 -0
- data/spec/support/dummy_app/Rakefile +6 -0
- data/spec/support/dummy_app/app/controllers/application_controller.rb +2 -0
- data/spec/support/dummy_app/app/controllers/concerns/.keep +0 -0
- data/spec/support/dummy_app/app/jobs/application_job.rb +7 -0
- data/spec/support/dummy_app/app/models/admin.rb +10 -0
- data/spec/support/dummy_app/app/models/application_record.rb +3 -0
- data/spec/support/dummy_app/app/models/concerns/.keep +0 -0
- data/spec/support/dummy_app/app/models/user.rb +10 -0
- data/spec/support/dummy_app/app/uploaders/avatar_uploader.rb +67 -0
- data/spec/support/dummy_app/bin/bundle +114 -0
- data/spec/support/dummy_app/bin/rails +4 -0
- data/spec/support/dummy_app/bin/rake +4 -0
- data/spec/support/dummy_app/bin/setup +33 -0
- data/spec/support/dummy_app/config/application.rb +39 -0
- data/spec/support/dummy_app/config/boot.rb +3 -0
- data/spec/support/dummy_app/config/database.yml +25 -0
- data/spec/support/dummy_app/config/environment.rb +8 -0
- data/spec/support/dummy_app/config/environments/development.rb +65 -0
- data/spec/support/dummy_app/config/environments/production.rb +86 -0
- data/spec/support/dummy_app/config/environments/test.rb +63 -0
- data/spec/support/dummy_app/config/initializers/carrierwave_backgrounder.rb +5 -0
- data/spec/support/dummy_app/config/initializers/cors.rb +16 -0
- data/spec/support/dummy_app/config/initializers/filter_parameter_logging.rb +8 -0
- data/spec/support/dummy_app/config/initializers/inflections.rb +16 -0
- data/spec/support/dummy_app/config/locales/en.yml +33 -0
- data/spec/support/dummy_app/config/routes.rb +6 -0
- data/spec/support/dummy_app/config/storage.yml +34 -0
- data/spec/support/dummy_app/config.ru +6 -0
- data/spec/support/dummy_app/db/migrate/20230804214459_create_users.rb +9 -0
- data/spec/support/dummy_app/db/migrate/20230807165013_add_avatar_tmp_column_to_user.rb +5 -0
- data/spec/support/dummy_app/db/migrate/20230808233036_add_avatar_processing_flag_to_users.rb +5 -0
- data/spec/support/dummy_app/db/migrate/20230809215320_create_admins.rb +10 -0
- data/spec/support/dummy_app/db/migrate/20230810182011_add_images_to_users.rb +7 -0
- data/spec/support/dummy_app/db/migrate/20230811155811_add_images_to_admins.rb +6 -0
- data/spec/support/dummy_app/db/schema.rb +34 -0
- data/spec/support/dummy_app/db/seeds.rb +7 -0
- data/spec/support/dummy_app/lib/tasks/.keep +0 -0
- data/spec/support/dummy_app/log/.keep +0 -0
- data/spec/support/dummy_app/public/robots.txt +1 -0
- data/spec/support/dummy_app/storage/.keep +0 -0
- data/spec/support/dummy_app/tmp/.keep +0 -0
- data/spec/support/dummy_app/tmp/development_secret.txt +1 -0
- data/spec/support/dummy_app/tmp/images/.gitkeep +0 -0
- data/spec/support/dummy_app/tmp/pids/.keep +0 -0
- data/spec/support/dummy_app/tmp/storage/.keep +0 -0
- data/spec/support/dummy_app/vendor/.keep +0 -0
- data/spec/support/fixtures/images/test-1.jpg +0 -0
- data/spec/support/fixtures/images/test-2.jpg +0 -0
- data/spec/support/global_macros.rb +29 -0
- data/spec/support/mock_worker.rb +2 -0
- metadata +203 -15
- data/spec/support/backend_constants.rb +0 -58
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe '::store_in_background multi-upload support', clear_images: true do
|
4
|
+
let(:user) { User.new }
|
5
|
+
|
6
|
+
context 'when assigning an asset' do
|
7
|
+
before(:each) do
|
8
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(0)
|
9
|
+
user.update(images: load_files('test-1.jpg', 'test-2.jpg'))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates a temp file and stores the path' do
|
13
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(2)
|
14
|
+
expect(user.images_tmp).to include('test-1.jpg')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'creates a background job in carrierwave queue' do
|
18
|
+
expect(Sidekiq::Queues["carrierwave"].size).to eql(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the <column>_processing flag to true' do
|
22
|
+
expect(user.images_processing).to be(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when processing the worker' do
|
27
|
+
before do
|
28
|
+
user.update(images: load_files('test-1.jpg','test-2.jpg'))
|
29
|
+
expect(user.images_processing).to be(true)
|
30
|
+
process_latest_sidekiq_job
|
31
|
+
user.reload
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'creates the versions' do
|
35
|
+
version_paths = AvatarUploader.versions.keys.map { |key| user.images.map { |i| i.send(key).current_path } }.flatten
|
36
|
+
version_paths.each { |path| expect(File.exist? path).to be(true) }
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the <column>_tmp to nil' do
|
40
|
+
expect(user.avatar_tmp).to be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'removes the files tmp directory' do
|
44
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the <column>_processing flag to false' do
|
48
|
+
expect(user.avatar_processing).to be(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when saving a record' do
|
53
|
+
let!(:user) {
|
54
|
+
Sidekiq::Testing.inline! do
|
55
|
+
User.create(images: load_files('test-1.jpg'))
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
it 'does not enqueue a new job' do
|
60
|
+
expect { user.reload.save }.to_not change(Sidekiq::Queues["carrierwave"], :size)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when setting a column for removal' do
|
65
|
+
let!(:user) {
|
66
|
+
Sidekiq::Testing.inline! do
|
67
|
+
User.create(images: load_files('test-1.jpg'))
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
before do
|
72
|
+
expect(user.reload.images.present?).to be(true)
|
73
|
+
|
74
|
+
user.remove_images = true
|
75
|
+
user.save!
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'removes the attachment' do
|
79
|
+
expect(user.images.present?).to be(false)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'does not enqueue a new job' do
|
83
|
+
expect(Sidekiq::Queues["carrierwave"].size).to be(0)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe '::store_in_background', clear_images: true do
|
4
|
+
let(:user) { User.new }
|
5
|
+
|
6
|
+
context 'when assigning an asset' do
|
7
|
+
before(:each) do
|
8
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(0)
|
9
|
+
user.update(avatar: load_file('test-1.jpg'))
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'creates a temp file and stores the path' do
|
13
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(1)
|
14
|
+
expect(user.avatar_tmp).to include('test-1.jpg')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'creates a background job in carrierwave queue' do
|
18
|
+
expect(Sidekiq::Queues["carrierwave"].size).to eql(1)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'sets the <column>_processing flag to true' do
|
22
|
+
expect(user.avatar_processing).to be(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'when processing the worker' do
|
27
|
+
before do
|
28
|
+
user.update(avatar: load_file('test-1.jpg'))
|
29
|
+
expect(user.avatar_processing).to be(true)
|
30
|
+
process_latest_sidekiq_job
|
31
|
+
user.reload
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'creates the versions' do
|
35
|
+
version_paths = user.avatar.versions.keys.map { |key| user.avatar.send(key).current_path }
|
36
|
+
version_paths.each { |path| expect(File.exist? path).to be(true) }
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'sets the <column>_tmp to nil' do
|
40
|
+
expect(user.avatar_tmp).to be_nil
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'removes the files tmp directory' do
|
44
|
+
expect(file_count('spec/support/dummy_app/tmp/images')).to eql(0)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'sets the <column>_processing flag to false' do
|
48
|
+
expect(user.avatar_processing).to be(false)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'when saving a record' do
|
53
|
+
let!(:user) {
|
54
|
+
Sidekiq::Testing.inline! do
|
55
|
+
User.create(avatar: load_file('test-1.jpg'))
|
56
|
+
end
|
57
|
+
}
|
58
|
+
|
59
|
+
it 'does not enqueue a new job' do
|
60
|
+
expect { user.reload.save }.to_not change(Sidekiq::Queues["carrierwave"], :size)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'when setting a column for removal' do
|
65
|
+
let!(:user) {
|
66
|
+
Sidekiq::Testing.inline! do
|
67
|
+
User.create(avatar: load_file('test-1.jpg'))
|
68
|
+
end
|
69
|
+
}
|
70
|
+
|
71
|
+
before do
|
72
|
+
expect(user.reload.avatar.file.nil?).to be(false)
|
73
|
+
|
74
|
+
user.remove_avatar = true
|
75
|
+
user.save!
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'removes the attachment' do
|
79
|
+
expect(user.avatar.file.nil?).to be(true)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'does not enqueue a new job' do
|
83
|
+
expect(Sidekiq::Queues["carrierwave"].size).to be(0)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
ENV['RAILS_ENV'] ||= 'test'
|
3
|
+
|
4
|
+
require_relative 'support/dummy_app/config/environment'
|
5
|
+
require_relative 'support/global_macros'
|
6
|
+
require 'sidekiq/testing'
|
7
|
+
require 'rspec/rails'
|
8
|
+
require 'backgrounder/railtie'
|
9
|
+
|
10
|
+
begin
|
11
|
+
ActiveRecord::Migration.maintain_test_schema!
|
12
|
+
rescue ActiveRecord::PendingMigrationError => e
|
13
|
+
abort e.to_s.strip
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.include GlobalMacros
|
18
|
+
|
19
|
+
config.after(:example, clear_images: true) do
|
20
|
+
Sidekiq::Queues.clear_all
|
21
|
+
FileUtils.rm_rf Dir.glob("spec/support/dummy_app/tmp/images/*")
|
22
|
+
FileUtils.rm_rf Dir.glob("spec/support/dummy_app/public/uploads/*")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
ActiveRecord::Schema.verbose = false
|
27
|
+
load 'support/dummy_app/db/schema.rb' # use db agnostic schema by default
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,49 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
3
|
+
|
4
|
+
ruby "3.0.0"
|
5
|
+
|
6
|
+
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
|
7
|
+
gem "rails", "~> 7.0.6"
|
8
|
+
|
9
|
+
# Use sqlite3 as the database for Active Record
|
10
|
+
gem "sqlite3", "~> 1.4"
|
11
|
+
|
12
|
+
# Use the Puma web server [https://github.com/puma/puma]
|
13
|
+
# gem "puma", "~> 5.0"
|
14
|
+
|
15
|
+
gem 'carrierwave'
|
16
|
+
gem 'carrierwave_backgrounder', path: "../../../"
|
17
|
+
gem 'sidekiq'
|
18
|
+
|
19
|
+
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
|
20
|
+
# gem "jbuilder"
|
21
|
+
|
22
|
+
# Use Redis adapter to run Action Cable in production
|
23
|
+
# gem "redis", "~> 4.0"
|
24
|
+
|
25
|
+
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
|
26
|
+
# gem "kredis"
|
27
|
+
|
28
|
+
# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
|
29
|
+
# gem "bcrypt", "~> 3.1.7"
|
30
|
+
|
31
|
+
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
|
32
|
+
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
|
33
|
+
|
34
|
+
# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images]
|
35
|
+
# gem "image_processing", "~> 1.2"
|
36
|
+
|
37
|
+
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
|
38
|
+
# gem "rack-cors"
|
39
|
+
|
40
|
+
group :development, :test do
|
41
|
+
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
42
|
+
gem "debug", platforms: %i[ mri mingw x64_mingw ]
|
43
|
+
end
|
44
|
+
|
45
|
+
group :development do
|
46
|
+
# Speed up commands on slow machines / big apps [https://github.com/rails/spring]
|
47
|
+
# gem "spring"
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
File without changes
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class ApplicationJob < ActiveJob::Base
|
2
|
+
# Automatically retry jobs that encountered a deadlock
|
3
|
+
# retry_on ActiveRecord::Deadlocked
|
4
|
+
|
5
|
+
# Most jobs are safe to ignore if the underlying records are no longer available
|
6
|
+
# discard_on ActiveJob::DeserializationError
|
7
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class Admin < ApplicationRecord
|
2
|
+
# Single attachment support
|
3
|
+
mount_uploader :avatar, AvatarUploader
|
4
|
+
process_in_background :avatar
|
5
|
+
|
6
|
+
# Multi attachment support
|
7
|
+
mount_uploaders :images, AvatarUploader
|
8
|
+
process_in_background :images
|
9
|
+
serialize :images, JSON
|
10
|
+
end
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class User < ApplicationRecord
|
2
|
+
# Single attachment support
|
3
|
+
mount_uploader :avatar, AvatarUploader
|
4
|
+
store_in_background :avatar
|
5
|
+
|
6
|
+
# Multi attachment support
|
7
|
+
mount_uploaders :images, AvatarUploader
|
8
|
+
store_in_background :images
|
9
|
+
serialize :images, JSON
|
10
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
|
3
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
4
|
+
# Include RMagick or MiniMagick support:
|
5
|
+
# include CarrierWave::RMagick
|
6
|
+
include CarrierWave::MiniMagick
|
7
|
+
include ::CarrierWave::Backgrounder::Delay
|
8
|
+
|
9
|
+
# Choose what kind of storage to use for this uploader:
|
10
|
+
# storage :aws
|
11
|
+
storage :file
|
12
|
+
# storage :fog
|
13
|
+
|
14
|
+
# Override the directory where uploaded files will be stored.
|
15
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
16
|
+
def store_dir
|
17
|
+
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def cache_dir
|
21
|
+
"../tmp/images"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
25
|
+
# def default_url(*args)
|
26
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
27
|
+
# # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
28
|
+
#
|
29
|
+
# "/images/fallback/" + [version_name, "default.png"].compact.join('_')
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Process files as they are uploaded:
|
33
|
+
# process scale: [200, 300]
|
34
|
+
#
|
35
|
+
# def scale(width, height)
|
36
|
+
# # do something
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Create different versions of your uploaded files:
|
40
|
+
version :thumb do
|
41
|
+
process resize_to_fit: [50, 50]
|
42
|
+
end
|
43
|
+
|
44
|
+
version :large_1920 do
|
45
|
+
process resize_to_limit: [1920, 1920]
|
46
|
+
end
|
47
|
+
|
48
|
+
version :medium_1024 do
|
49
|
+
process resize_to_limit: [1024, 1024]
|
50
|
+
end
|
51
|
+
|
52
|
+
version :small_640 do
|
53
|
+
process resize_to_limit: [640, 640]
|
54
|
+
end
|
55
|
+
|
56
|
+
# Add an allowlist of extensions which are allowed to be uploaded.
|
57
|
+
# For images you might use something like this:
|
58
|
+
# def extension_allowlist
|
59
|
+
# %w(jpg jpeg gif png)
|
60
|
+
# end
|
61
|
+
|
62
|
+
# Override the filename of the uploaded files:
|
63
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
64
|
+
# def filename
|
65
|
+
# "something.jpg" if original_filename
|
66
|
+
# end
|
67
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "rubygems"
|
12
|
+
|
13
|
+
m = Module.new do
|
14
|
+
module_function
|
15
|
+
|
16
|
+
def invoked_as_script?
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
18
|
+
end
|
19
|
+
|
20
|
+
def env_var_version
|
21
|
+
ENV["BUNDLER_VERSION"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cli_arg_version
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
27
|
+
bundler_version = nil
|
28
|
+
update_index = nil
|
29
|
+
ARGV.each_with_index do |a, i|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
31
|
+
bundler_version = a
|
32
|
+
end
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
34
|
+
bundler_version = $1
|
35
|
+
update_index = i
|
36
|
+
end
|
37
|
+
bundler_version
|
38
|
+
end
|
39
|
+
|
40
|
+
def gemfile
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
43
|
+
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
45
|
+
end
|
46
|
+
|
47
|
+
def lockfile
|
48
|
+
lockfile =
|
49
|
+
case File.basename(gemfile)
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
51
|
+
else "#{gemfile}.lock"
|
52
|
+
end
|
53
|
+
File.expand_path(lockfile)
|
54
|
+
end
|
55
|
+
|
56
|
+
def lockfile_version
|
57
|
+
return unless File.file?(lockfile)
|
58
|
+
lockfile_contents = File.read(lockfile)
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
60
|
+
Regexp.last_match(1)
|
61
|
+
end
|
62
|
+
|
63
|
+
def bundler_version
|
64
|
+
@bundler_version ||=
|
65
|
+
env_var_version || cli_arg_version ||
|
66
|
+
lockfile_version
|
67
|
+
end
|
68
|
+
|
69
|
+
def bundler_requirement
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
71
|
+
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
73
|
+
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
75
|
+
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
77
|
+
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
79
|
+
|
80
|
+
requirement
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_bundler!
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
85
|
+
|
86
|
+
activate_bundler
|
87
|
+
end
|
88
|
+
|
89
|
+
def activate_bundler
|
90
|
+
gem_error = activation_error_handling do
|
91
|
+
gem "bundler", bundler_requirement
|
92
|
+
end
|
93
|
+
return if gem_error.nil?
|
94
|
+
require_error = activation_error_handling do
|
95
|
+
require "bundler/version"
|
96
|
+
end
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
99
|
+
exit 42
|
100
|
+
end
|
101
|
+
|
102
|
+
def activation_error_handling
|
103
|
+
yield
|
104
|
+
nil
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
e
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
m.load_bundler!
|
111
|
+
|
112
|
+
if m.invoked_as_script?
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
114
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
# path to your application root.
|
5
|
+
APP_ROOT = File.expand_path("..", __dir__)
|
6
|
+
|
7
|
+
def system!(*args)
|
8
|
+
system(*args) || abort("\n== Command #{args} failed ==")
|
9
|
+
end
|
10
|
+
|
11
|
+
FileUtils.chdir APP_ROOT do
|
12
|
+
# This script is a way to set up or update your development environment automatically.
|
13
|
+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
|
14
|
+
# Add necessary setup steps to this file.
|
15
|
+
|
16
|
+
puts "== Installing dependencies =="
|
17
|
+
system! "gem install bundler --conservative"
|
18
|
+
system("bundle check") || system!("bundle install")
|
19
|
+
|
20
|
+
# puts "\n== Copying sample files =="
|
21
|
+
# unless File.exist?("config/database.yml")
|
22
|
+
# FileUtils.cp "config/database.yml.sample", "config/database.yml"
|
23
|
+
# end
|
24
|
+
|
25
|
+
puts "\n== Preparing database =="
|
26
|
+
system! "bin/rails db:prepare"
|
27
|
+
|
28
|
+
puts "\n== Removing old logs and tempfiles =="
|
29
|
+
system! "bin/rails log:clear tmp:clear"
|
30
|
+
|
31
|
+
puts "\n== Restarting application server =="
|
32
|
+
system! "bin/rails restart"
|
33
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative "boot"
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
# Pick the frameworks you want:
|
5
|
+
require "active_model/railtie"
|
6
|
+
require "active_job/railtie"
|
7
|
+
require "active_record/railtie"
|
8
|
+
# require "active_storage/engine"
|
9
|
+
# require "action_controller/railtie"
|
10
|
+
# require "action_mailer/railtie"
|
11
|
+
# require "action_mailbox/engine"
|
12
|
+
# require "action_text/engine"
|
13
|
+
# require "action_view/railtie"
|
14
|
+
# require "action_cable/engine"
|
15
|
+
# require "rails/test_unit/railtie"
|
16
|
+
|
17
|
+
# Require the gems listed in Gemfile, including any gems
|
18
|
+
# you've limited to :test, :development, or :production.
|
19
|
+
Bundler.require(*Rails.groups)
|
20
|
+
|
21
|
+
module DummyApp
|
22
|
+
class Application < Rails::Application
|
23
|
+
# Initialize configuration defaults for originally generated Rails version.
|
24
|
+
config.load_defaults 7.0
|
25
|
+
|
26
|
+
# Configuration for the application, engines, and railties goes here.
|
27
|
+
#
|
28
|
+
# These settings can be overridden in specific environments using the files
|
29
|
+
# in config/environments, which are processed later.
|
30
|
+
#
|
31
|
+
# config.time_zone = "Central Time (US & Canada)"
|
32
|
+
# config.eager_load_paths << Rails.root.join("extras")
|
33
|
+
|
34
|
+
# Only loads a smaller set of middleware suitable for API only apps.
|
35
|
+
# Middleware like session, flash, cookies can be added back manually.
|
36
|
+
# Skip views, helpers and assets when generating a new resource.
|
37
|
+
config.api_only = true
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite. Versions 3.8.0 and up are supported.
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem "sqlite3"
|
6
|
+
#
|
7
|
+
default: &default
|
8
|
+
adapter: sqlite3
|
9
|
+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
development:
|
13
|
+
<<: *default
|
14
|
+
database: db/development.sqlite3
|
15
|
+
|
16
|
+
# Warning: The database defined as "test" will be erased and
|
17
|
+
# re-generated from your development database when you run "rake".
|
18
|
+
# Do not set this db to the same as development or production.
|
19
|
+
test:
|
20
|
+
<<: *default
|
21
|
+
database: ':memory:'
|
22
|
+
|
23
|
+
production:
|
24
|
+
<<: *default
|
25
|
+
database: db/production.sqlite3
|