Use frozen string literal in Active Storage

This commit is contained in:
Koichi ITO 2017-08-12 21:32:15 +09:00
parent 98360a96cc
commit d02844f249
75 changed files with 149 additions and 4 deletions

View File

@ -88,6 +88,7 @@ Style/FrozenStringLiteralComment:
- 'actioncable/**/*'
- 'activejob/**/*'
- 'activerecord/**/*'
- 'activestorage/**/*'
- 'actionmailer/**/*'
- 'actionview/**/*'
- 'actionpack/**/*'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "bundler/setup"
require "bundler/gem_tasks"
require "rake/testtask"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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
# security-through-obscurity factor of the signed blob references, you'll need to implement your own

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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
# the blob that was created up front.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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.
# Always go through the BlobsController, or your own authenticated controller, rather than directly

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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
# security-through-obscurity factor of the signed blob and variation reference, you'll need to implement your own

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Provides delayed purging of attachments or blobs using their +#purge_later+ method.
class ActiveStorage::PurgeJob < ActiveJob::Base
# FIXME: Limit this to a custom ActiveStorage error

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "active_support/core_ext/module/delegation"
# Attachments associate records with blobs. Usually that's a one record-many blobs relationship,

View File

@ -1,3 +1,5 @@
# 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.
# Blobs can be created in two ways:
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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.
class ActiveStorage::Filename

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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
# original.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.routes.draw do
get "/rails/active_storage/blobs/:signed_id/*filename" => "active_storage/blobs#show", as: :rails_service_blob

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CreateActiveStorageTables < ActiveRecord::Migration[5.1]
def change
create_table :active_storage_blobs do |t|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
#--
# Copyright (c) 2017 David Heinemeier Hansson
#

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "action_dispatch"
require "action_dispatch/http/upload"
require "active_support/core_ext/module/delegation"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ActiveStorage
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
module Attached::Macros

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ActiveStorage
# Decorated proxy object representing of multiple attachments to a model.
class Attached::Many < Attached

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ActiveStorage
# Representation of a single attachment to a model.
class Attached::One < Attached

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ActiveStorage
# Returns the version of the currently loaded Active Storage as a <tt>Gem::Version</tt>
def self.gem_version

View File

@ -1,10 +1,12 @@
# frozen_string_literal: true
require "active_support/log_subscriber"
module ActiveStorage
class LogSubscriber < ActiveSupport::LogSubscriber
def service_upload(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)
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "active_storage/log_subscriber"
module ActiveStorage

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "active_support/core_ext/numeric/bytes"
require "azure/storage"
require "azure/storage/core/auth/shared_access_signature"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ActiveStorage
class Service::Configurator #:nodoc:
attr_reader :configurations

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "fileutils"
require "pathname"
require "digest/md5"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "google/cloud/storage"
require "active_support/core_ext/object/to_query"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "active_support/core_ext/module/delegation"
module ActiveStorage

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "aws-sdk"
require "active_support/core_ext/numeric/bytes"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "gem_version"
module ActiveStorage

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
namespace :activestorage do
desc "Copy over the migration needed to the application"
task install: :environment do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ActiveStorageCreateUsers < ActiveRecord::Migration[5.1]
def change
create_table :users do |t|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "create_users_migration"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "config/application"
Rails.application.load_tasks

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
module ApplicationHelper
end

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end

View File

@ -1,3 +1,5 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
load Gem.bin_path("bundler", "bundle")

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
APP_PATH = File.expand_path("../config/application", __dir__)
require_relative "../config/boot"
require "rails/commands"

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "../config/boot"
require "rake"
Rake.application.run

View File

@ -1,4 +1,6 @@
#!/usr/bin/env ruby
# frozen_string_literal: true
VENDOR_PATH = File.expand_path("..", __dir__)
Dir.chdir(VENDOR_PATH) do
begin

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application.
require_relative "config/environment"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_relative "boot"
require "rails"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Load the Rails application.
require_relative "application"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# ApplicationController.renderer.defaults.merge!(

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# 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.

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
# 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.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections

View File

@ -1,3 +1,4 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which

View File

@ -1,2 +1,4 @@
# frozen_string_literal: true
Rails.application.routes.draw do
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
%w(
.ruby-version
.rbenv-vars

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
class ActiveStorage::FilenameTest < ActiveSupport::TestCase
@ -10,8 +12,8 @@ class ActiveStorage::FilenameTest < ActiveSupport::TestCase
end
test "sanitize transcodes to valid UTF-8" do
{ "\xF6".force_encoding(Encoding::ISO8859_1) => "ö",
"\xC3".force_encoding(Encoding::ISO8859_1) => "Ã",
{ "\xF6".dup.force_encoding(Encoding::ISO8859_1) => "ö",
"\xC3".dup.force_encoding(Encoding::ISO8859_1) => "Ã",
"\xAD" => "<EFBFBD>",
"\xCF" => "<EFBFBD>",
"\x00" => "",

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
require "uri"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
class ActiveStorage::Service::ConfiguratorTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
class ActiveStorage::Service::DiskServiceTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
require "net/http"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
class ActiveStorage::Service::MirrorServiceTest < ActiveSupport::TestCase

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "service/shared_service_tests"
require "net/http"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "active_support/core_ext/securerandom"
@ -5,7 +7,7 @@ module ActiveStorage::Service::SharedServiceTests
extend ActiveSupport::Concern
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
setup do

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "test_helper"
require "database/setup"

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
require "bundler/setup"