提交 d02844f2 编写于 作者: K Koichi ITO

Use frozen string literal in Active Storage

上级 98360a96
...@@ -88,6 +88,7 @@ Style/FrozenStringLiteralComment: ...@@ -88,6 +88,7 @@ Style/FrozenStringLiteralComment:
- 'actioncable/**/*' - 'actioncable/**/*'
- 'activejob/**/*' - 'activejob/**/*'
- 'activerecord/**/*' - 'activerecord/**/*'
- 'activestorage/**/*'
- 'actionmailer/**/*' - 'actionmailer/**/*'
- 'actionview/**/*' - 'actionview/**/*'
- 'actionpack/**/*' - 'actionpack/**/*'
......
# frozen_string_literal: true
require "bundler/setup" require "bundler/setup"
require "bundler/gem_tasks" require "bundler/gem_tasks"
require "rake/testtask" require "rake/testtask"
......
# frozen_string_literal: true
# Take a signed permanent reference for a blob and turn it into an expiring service URL for download. # Take a signed permanent reference for a blob and turn it into an expiring service URL for download.
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the # Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
# security-through-obscurity factor of the signed blob references, you'll need to implement your own # security-through-obscurity factor of the signed blob references, you'll need to implement your own
......
# frozen_string_literal: true
# Creates a new blob on the server side in anticipation of a direct-to-service upload from the client side. # Creates a new blob on the server side in anticipation of a direct-to-service upload from the client side.
# When the client-side upload is completed, the signed_blob_id can be submitted as part of the form to reference # When the client-side upload is completed, the signed_blob_id can be submitted as part of the form to reference
# the blob that was created up front. # the blob that was created up front.
......
# frozen_string_literal: true
# Serves files stored with the disk service in the same way that the cloud services do. # Serves files stored with the disk service in the same way that the cloud services do.
# This means using expiring, signed URLs that are meant for immediate access, not permanent linking. # This means using expiring, signed URLs that are meant for immediate access, not permanent linking.
# Always go through the BlobsController, or your own authenticated controller, rather than directly # Always go through the BlobsController, or your own authenticated controller, rather than directly
......
# frozen_string_literal: true
# Take a signed permanent reference for a variant and turn it into an expiring service URL for download. # Take a signed permanent reference for a variant and turn it into an expiring service URL for download.
# Note: These URLs are publicly accessible. If you need to enforce access protection beyond the # Note: These URLs are publicly accessible. If you need to enforce access protection beyond the
# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own # security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own
......
# frozen_string_literal: true
# Provides delayed purging of attachments or blobs using their +#purge_later+ method. # Provides delayed purging of attachments or blobs using their +#purge_later+ method.
class ActiveStorage::PurgeJob < ActiveJob::Base class ActiveStorage::PurgeJob < ActiveJob::Base
# FIXME: Limit this to a custom ActiveStorage error # FIXME: Limit this to a custom ActiveStorage error
......
# frozen_string_literal: true
require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/delegation"
# Attachments associate records with blobs. Usually that's a one record-many blobs relationship, # Attachments associate records with blobs. Usually that's a one record-many blobs relationship,
......
# frozen_string_literal: true
# A blob is a record that contains the metadata about a file and a key for where that file resides on the service. # A blob is a record that contains the metadata about a file and a key for where that file resides on the service.
# Blobs can be created in two ways: # Blobs can be created in two ways:
# #
......
# frozen_string_literal: true
# Encapsulates a string representing a filename to provide convenience access to parts of it and a sanitized version. # Encapsulates a string representing a filename to provide convenience access to parts of it and a sanitized version.
# This is what's returned by `ActiveStorage::Blob#filename`. A Filename instance is comparable so it can be used for sorting. # This is what's returned by `ActiveStorage::Blob#filename`. A Filename instance is comparable so it can be used for sorting.
class ActiveStorage::Filename class ActiveStorage::Filename
......
# frozen_string_literal: true
# Image blobs can have variants that are the result of a set of transformations applied to the original. # Image blobs can have variants that are the result of a set of transformations applied to the original.
# These variants are used to create thumbnails, fixed-size avatars, or any other derivative image from the # These variants are used to create thumbnails, fixed-size avatars, or any other derivative image from the
# original. # original.
......
# frozen_string_literal: true
require "active_support/core_ext/object/inclusion" require "active_support/core_ext/object/inclusion"
# A set of transformations that can be applied to a blob to create a variant. This class is exposed via # A set of transformations that can be applied to a blob to create a variant. This class is exposed via
......
# frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
get "/rails/active_storage/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob get "/rails/active_storage/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob
......
# frozen_string_literal: true
class CreateActiveStorageTables < ActiveRecord::Migration[5.1] class CreateActiveStorageTables < ActiveRecord::Migration[5.1]
def change def change
create_table :active_storage_blobs do |t| create_table :active_storage_blobs do |t|
......
# frozen_string_literal: true
#-- #--
# Copyright (c) 2017 David Heinemeier Hansson # Copyright (c) 2017 David Heinemeier Hansson
# #
......
# frozen_string_literal: true
require "action_dispatch" require "action_dispatch"
require "action_dispatch/http/upload" require "action_dispatch/http/upload"
require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/delegation"
......
# frozen_string_literal: true
module ActiveStorage module ActiveStorage
# Provides the class-level DSL for declaring that an Active Record model has attached blobs. # Provides the class-level DSL for declaring that an Active Record model has attached blobs.
module Attached::Macros module Attached::Macros
......
# frozen_string_literal: true
module ActiveStorage module ActiveStorage
# Decorated proxy object representing of multiple attachments to a model. # Decorated proxy object representing of multiple attachments to a model.
class Attached::Many < Attached class Attached::Many < Attached
......
# frozen_string_literal: true
module ActiveStorage module ActiveStorage
# Representation of a single attachment to a model. # Representation of a single attachment to a model.
class Attached::One < Attached class Attached::One < Attached
......
# frozen_string_literal: true
module ActiveStorage module ActiveStorage
# Returns the version of the currently loaded Active Storage as a <tt>Gem::Version</tt> # Returns the version of the currently loaded Active Storage as a <tt>Gem::Version</tt>
def self.gem_version def self.gem_version
......
# frozen_string_literal: true
require "active_support/log_subscriber" require "active_support/log_subscriber"
module ActiveStorage module ActiveStorage
class LogSubscriber < ActiveSupport::LogSubscriber class LogSubscriber < ActiveSupport::LogSubscriber
def service_upload(event) def service_upload(event)
message = "Uploaded file to key: #{key_in(event)}" message = "Uploaded file to key: #{key_in(event)}"
message << " (checksum: #{event.payload[:checksum]})" if event.payload[:checksum] message += " (checksum: #{event.payload[:checksum]})" if event.payload[:checksum]
info event, color(message, GREEN) info event, color(message, GREEN)
end end
......
# frozen_string_literal: true
require "active_storage/log_subscriber" require "active_storage/log_subscriber"
module ActiveStorage module ActiveStorage
......
# frozen_string_literal: true
require "active_support/core_ext/numeric/bytes" require "active_support/core_ext/numeric/bytes"
require "azure/storage" require "azure/storage"
require "azure/storage/core/auth/shared_access_signature" require "azure/storage/core/auth/shared_access_signature"
......
# frozen_string_literal: true
module ActiveStorage module ActiveStorage
class Service::Configurator #:nodoc: class Service::Configurator #:nodoc:
attr_reader :configurations attr_reader :configurations
......
# frozen_string_literal: true
require "fileutils" require "fileutils"
require "pathname" require "pathname"
require "digest/md5" require "digest/md5"
......
# frozen_string_literal: true
require "google/cloud/storage" require "google/cloud/storage"
require "active_support/core_ext/object/to_query" require "active_support/core_ext/object/to_query"
......
# frozen_string_literal: true
require "active_support/core_ext/module/delegation" require "active_support/core_ext/module/delegation"
module ActiveStorage module ActiveStorage
......
# frozen_string_literal: true
require "aws-sdk" require "aws-sdk"
require "active_support/core_ext/numeric/bytes" require "active_support/core_ext/numeric/bytes"
......
# frozen_string_literal: true
require_relative "gem_version" require_relative "gem_version"
module ActiveStorage module ActiveStorage
......
# frozen_string_literal: true
namespace :activestorage do namespace :activestorage do
desc "Copy over the migration needed to the application" desc "Copy over the migration needed to the application"
task install: :environment do task install: :environment do
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
class ActiveStorageCreateUsers < ActiveRecord::Migration[5.1] class ActiveStorageCreateUsers < ActiveRecord::Migration[5.1]
def change def change
create_table :users do |t| create_table :users do |t|
......
# frozen_string_literal: true
require_relative "create_users_migration" require_relative "create_users_migration"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
......
# frozen_string_literal: true
require_relative "config/application" require_relative "config/application"
Rails.application.load_tasks Rails.application.load_tasks
# frozen_string_literal: true
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
end end
# frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
end end
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base class ApplicationJob < ActiveJob::Base
end end
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true self.abstract_class = true
end end
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__) ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
load Gem.bin_path("bundler", "bundle") load Gem.bin_path("bundler", "bundle")
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
APP_PATH = File.expand_path("../config/application", __dir__) APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot" require_relative "../config/boot"
require "rails/commands" require "rails/commands"
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../config/boot" require_relative "../config/boot"
require "rake" require "rake"
Rake.application.run Rake.application.run
#!/usr/bin/env ruby #!/usr/bin/env ruby
# frozen_string_literal: true
VENDOR_PATH = File.expand_path("..", __dir__) VENDOR_PATH = File.expand_path("..", __dir__)
Dir.chdir(VENDOR_PATH) do Dir.chdir(VENDOR_PATH) do
begin begin
......
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application. # This file is used by Rack-based servers to start the application.
require_relative "config/environment" require_relative "config/environment"
......
# frozen_string_literal: true
require_relative "boot" require_relative "boot"
require "rails" require "rails"
......
# frozen_string_literal: true
# Set up gems listed in the Gemfile. # Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__) ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
......
# frozen_string_literal: true
# Load the Rails application. # Load the Rails application.
require_relative "application" require_relative "application"
......
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
......
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
......
# frozen_string_literal: true
Rails.application.configure do Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb. # Settings specified here will take precedence over those in config/application.rb.
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# ApplicationController.renderer.defaults.merge!( # ApplicationController.renderer.defaults.merge!(
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets. # Version of your assets, change this if you want to expire all your assets.
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars. # Specify a serializer for the signed and encrypted cookie jars.
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file. # Configure sensitive parameters which will be filtered from the log file.
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections # Add new inflection rules using the following format. Inflections
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks: # Add new mime types for use in respond_to blocks:
......
# frozen_string_literal: true
# Be sure to restart your server when you modify this file. # Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which # This file contains settings for ActionController::ParamsWrapper which
......
# frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
end end
# frozen_string_literal: true
%w( %w(
.ruby-version .ruby-version
.rbenv-vars .rbenv-vars
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
class ActiveStorage::FilenameTest < ActiveSupport::TestCase class ActiveStorage::FilenameTest < ActiveSupport::TestCase
...@@ -10,8 +12,8 @@ class ActiveStorage::FilenameTest < ActiveSupport::TestCase ...@@ -10,8 +12,8 @@ class ActiveStorage::FilenameTest < ActiveSupport::TestCase
end end
test "sanitize transcodes to valid UTF-8" do test "sanitize transcodes to valid UTF-8" do
{ "\xF6".force_encoding(Encoding::ISO8859_1) => "ö", { "\xF6".dup.force_encoding(Encoding::ISO8859_1) => "ö",
"\xC3".force_encoding(Encoding::ISO8859_1) => "Ã", "\xC3".dup.force_encoding(Encoding::ISO8859_1) => "Ã",
"\xAD" => "�", "\xAD" => "�",
"\xCF" => "�", "\xCF" => "�",
"\x00" => "", "\x00" => "",
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
require "uri" require "uri"
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
require "net/http" require "net/http"
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase
......
# frozen_string_literal: true
require "service/shared_service_tests" require "service/shared_service_tests"
require "net/http" require "net/http"
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "active_support/core_ext/securerandom" require "active_support/core_ext/securerandom"
...@@ -5,7 +7,7 @@ module ActiveStorage::Service::SharedServiceTests ...@@ -5,7 +7,7 @@ module ActiveStorage::Service::SharedServiceTests
extend ActiveSupport::Concern extend ActiveSupport::Concern
FIXTURE_KEY = SecureRandom.base58(24) FIXTURE_KEY = SecureRandom.base58(24)
FIXTURE_DATA = "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\020\001\003\000\000\000%=m\"\000\000\000\006PLTE\000\000\000\377\377\377\245\331\237\335\000\000\0003IDATx\234c\370\377\237\341\377_\206\377\237\031\016\2603\334?\314p\1772\303\315\315\f7\215\031\356\024\203\320\275\317\f\367\201R\314\f\017\300\350\377\177\000Q\206\027(\316]\233P\000\000\000\000IEND\256B`\202".force_encoding(Encoding::BINARY) FIXTURE_DATA = "\211PNG\r\n\032\n\000\000\000\rIHDR\000\000\000\020\000\000\000\020\001\003\000\000\000%=m\"\000\000\000\006PLTE\000\000\000\377\377\377\245\331\237\335\000\000\0003IDATx\234c\370\377\237\341\377_\206\377\237\031\016\2603\334?\314p\1772\303\315\315\f7\215\031\356\024\203\320\275\317\f\367\201R\314\f\017\300\350\377\177\000Q\206\027(\316]\233P\000\000\000\000IEND\256B`\202".dup.force_encoding(Encoding::BINARY)
included do included do
setup do setup do
......
# frozen_string_literal: true
require "test_helper" require "test_helper"
require "database/setup" require "database/setup"
......
# frozen_string_literal: true
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__) require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
require "bundler/setup" require "bundler/setup"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册