-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify storage options #211
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
03bb008
feat(recipes): unify paperclip and active_storage questions
difernandez 55338f3
test(file-storage): move existing active_storage tests and add papaer…
difernandez 7f6590b
feat(application): change ask/create of active_storage/paperclip
difernandez 8380c95
feat(cli-options): update options to show storage as flag
difernandez 3c620c1
refactor(README): rename storage section to active_storage
difernandez db71b6e
refactor(): erase unused paperclip/active_storage files
difernandez 0bbb1ff
feat(file-storage): add deprecation message to paperclip option
difernandez d3a3f17
feat(cli-options): add active_storage as default value
difernandez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
class Recipes::FileStorage < Rails::AppBuilder | ||
def ask | ||
storages = { | ||
active_storage: 'ActiveStorage', | ||
paperclip: '[DEPRECATED] Paperclip', | ||
none: 'None, thanks' | ||
} | ||
|
||
storage = answer(:storage) do | ||
storages.keys[Ask.list('Which storage are you going to use?', storages.values)] | ||
end | ||
|
||
set(:storage, storage.to_sym) | ||
end | ||
|
||
def create | ||
add_chosen_storage(check_rspec: false) | ||
end | ||
|
||
def install | ||
ask | ||
add_chosen_storage(check_rspec: true) | ||
end | ||
|
||
def installed? | ||
gem_exists?(/paperclip/) || file_exist?('config/storage.yml') | ||
end | ||
|
||
private | ||
|
||
def paperclip_config | ||
@paperclip_config ||= | ||
<<~RUBY | ||
config.paperclip_defaults = { | ||
storage: :s3, | ||
s3_protocol: 'https', | ||
s3_region: ENV.fetch('AWS_REGION', 'us-east-1'), | ||
s3_credentials: { | ||
bucket: ENV['S3_BUCKET'] | ||
} | ||
} | ||
RUBY | ||
end | ||
|
||
def config_rspec_for_paperclip | ||
copy_file '../assets/testing/platanus.png', 'spec/assets/platanus.png' | ||
copy_file '../assets/testing/paperclip.rb', 'spec/support/paperclip.rb' | ||
end | ||
|
||
def add_paperclip | ||
gather_gem 'paperclip', '~> 5.0' | ||
application paperclip_config, env: 'production' | ||
append_to_file '.gitignore', "/public/system/*\n" | ||
end | ||
|
||
def add_active_storage | ||
after(:gem_install) { run('bundle exec rails active_storage:install') } | ||
copy_file('../assets/config/storage.yml', 'config/storage.yml', force: true) | ||
active_storage_service_regexp = /config.active_storage.service = :local\n/ | ||
gsub_file 'config/environments/production.rb', active_storage_service_regexp do | ||
'config.active_storage.service = :amazon' | ||
end | ||
end | ||
|
||
def common_setup | ||
add_readme_section :internal_dependencies, get(:storage) | ||
append_to_file '.env.development', "S3_BUCKET=\n" | ||
end | ||
|
||
def add_chosen_storage(check_rspec:) | ||
return if get(:storage) == :none | ||
|
||
common_setup | ||
case get(:storage) | ||
when :paperclip | ||
add_paperclip | ||
config_rspec_for_paperclip if !check_rspec || gem_exists?(/rspec-rails/) | ||
when :active_storage | ||
add_active_storage | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "File Storage" do | ||
context "when selecting active_storage" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project(storage: :active_storage) | ||
end | ||
|
||
it "customizes config file" do | ||
content = IO.read("#{project_path}/config/storage.yml") | ||
expect(content).to include("bucket: <%= ENV['S3_BUCKET'] %>") | ||
end | ||
|
||
it "adds brief to README file" do | ||
content = IO.read("#{project_path}/README.md") | ||
expect(content).to include("Active Storage") | ||
end | ||
|
||
it "uses amazon on production env" do | ||
content = IO.read("#{project_path}/config/environments/production.rb") | ||
expect(content).to include("config.active_storage.service = :amazon") | ||
end | ||
|
||
it "adds S3 bucket ENV vars" do | ||
content = IO.read("#{project_path}/.env.development") | ||
expect(content).to include("S3_BUCKET=") | ||
end | ||
end | ||
|
||
context "when selecting paperclip" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project(storage: :paperclip) | ||
end | ||
|
||
it "adds the Paperclip gem to Gemfile" do | ||
gemfile_content = IO.read("#{project_path}/Gemfile") | ||
expect(gemfile_content).to include("gem 'paperclip'") | ||
end | ||
|
||
it "adds brief to README file" do | ||
content = IO.read("#{project_path}/README.md") | ||
expect(content).to include("Paperclip") | ||
end | ||
|
||
it "adds local file storage path to gitignore" do | ||
content = IO.read("#{project_path}/.gitignore") | ||
expect(content).to include("/public/system/*") | ||
end | ||
|
||
it "adds paperclip_defaults config to production" do | ||
content = IO.read("#{project_path}/config/environments/production.rb") | ||
expect(content).to include("config.paperclip_defaults") | ||
end | ||
|
||
it "adds S3 bucket ENV var" do | ||
content = IO.read("#{project_path}/.env.development") | ||
expect(content).to include("S3_BUCKET=") | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no dejarias
active_storage
por defecto?? creo que es el que debieramos empujar mas a usar. Sobre todo quepaperclip
esta deprecado...