Last active
February 24, 2017 05:05
-
-
Save ichi/fc4e47dde9ad57dbe7c4d2d3149f52f4 to your computer and use it in GitHub Desktop.
refile in rails5
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
# config/application.rb | |
module MyApp | |
class Application < Rails::Application | |
config.refile = config_for(:refile) | |
end | |
end |
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
# NOTE: https://github.com/refile/refile/pull/486 | |
# NOTE: https://github.com/refile/refile/issues/447 | |
gem 'refile', github: 'jastkand/refile', branch: 'mime-types-v3', require: 'refile/rails' | |
gem 'sinatra', '~> 2.0.0.beta2', require: false | |
# gem 'refile-s3' |
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
# config/initializers/refile.rb | |
Refile.types[:video] = Refile::Type.new(:video, | |
content_type: %w[video/mp4] | |
) | |
if Rails.configuration.refile['backend'] == 's3' | |
require 'refile/s3' | |
Refile.cache = Refile::S3.new(prefix: "#{Rails.env}/cache", **Rails.configuration.refile['options'].to_hash.symbolize_keys) | |
Refile.store = Refile::S3.new(prefix: "#{Rails.env}/store", **Rails.configuration.refile['options'].to_hash.symbolize_keys) | |
end | |
Refile.app_host = Rails.configuration.refile['app_host'] | |
Refile.cdn_host = Rails.configuration.refile['cdn_host'] |
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
default: &default | |
backend: file_system | |
options: {} | |
app_host: 'http://localhost:3000' | |
cdn_host: | |
s3: &s3 | |
backend: s3 | |
options: | |
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %> | |
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> | |
region: ap-northeast-1 | |
bucket: bucket_name | |
development: | |
<<: *default | |
test: | |
<<: *default | |
staging: | |
<<: *s3 | |
cdn_host: 'https://hogehoge.cloudfront.net' | |
production: | |
<<: *s3 | |
cdn_host: 'https://fugafuga.cloudfront.net' |
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
# spec/support/refile.rb | |
require "refile/file_double" | |
module RefileHelper | |
def refile_double(type: nil) | |
content_type = Refile.types[type].content_type.sample if type | |
extension = MIME::Types[content_type].first.extensions.first if content_type | |
Refile::FileDouble.new("dummy", Faker::File.file_name(nil, nil, extension), content_type: content_type) | |
end | |
end | |
FactoryGirl::SyntaxRunner.send(:include, RefileHelper) | |
RSpec.configure do |config| | |
config.include RefileHelper | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment