Skip to content

Commit

Permalink
[Shared] Rename modules to mitigate global scope pollution (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mth0158 committed Nov 12, 2024
1 parent 7bfca94 commit cd2a20e
Show file tree
Hide file tree
Showing 34 changed files with 236 additions and 182 deletions.
20 changes: 10 additions & 10 deletions lib/active_storage_validations/aspect_ratio_validator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/attachable'
require_relative 'shared/errorable'
require_relative 'shared/optionable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_optionable'
require_relative 'shared/asv_symbolizable'

module ActiveStorageValidations
class AspectRatioValidator < ActiveModel::EachValidator # :nodoc
include ActiveStorageable
include Attachable
include Errorable
include Optionable
include Symbolizable
include ASVActiveStorageable
include ASVAttachable
include ASVErrorable
include ASVOptionable
include ASVSymbolizable

AVAILABLE_CHECKS = %i[with].freeze
NAMED_ASPECT_RATIOS = %i[square portrait landscape].freeze
Expand Down
12 changes: 6 additions & 6 deletions lib/active_storage_validations/attached_validator.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/errorable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_symbolizable'

module ActiveStorageValidations
class AttachedValidator < ActiveModel::EachValidator # :nodoc:
include ActiveStorageable
include Errorable
include Symbolizable
include ASVActiveStorageable
include ASVErrorable
include ASVSymbolizable

ERROR_TYPES = %i[blank].freeze

Expand Down
16 changes: 8 additions & 8 deletions lib/active_storage_validations/base_size_validator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/errorable'
require_relative 'shared/optionable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_optionable'
require_relative 'shared/asv_symbolizable'

module ActiveStorageValidations
class BaseSizeValidator < ActiveModel::EachValidator # :nodoc:
include ActiveStorageable
include Errorable
include Optionable
include Symbolizable
include ASVActiveStorageable
include ASVErrorable
include ASVOptionable
include ASVSymbolizable

delegate :number_to_human_size, to: ActiveSupport::NumberHelper

Expand Down
8 changes: 4 additions & 4 deletions lib/active_storage_validations/content_type_spoof_detector.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# frozen_string_literal: true

require_relative 'shared/attachable'
require_relative 'shared/loggable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_loggable'
require 'open3'

module ActiveStorageValidations
class ContentTypeSpoofDetector
class FileCommandLineToolNotInstalledError < StandardError; end

include Attachable
include Loggable
include ASVAttachable
include ASVLoggable

def initialize(record, attribute, attachable)
@record = record
Expand Down
20 changes: 10 additions & 10 deletions lib/active_storage_validations/content_type_validator.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/attachable'
require_relative 'shared/errorable'
require_relative 'shared/optionable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_optionable'
require_relative 'shared/asv_symbolizable'
require_relative 'content_type_spoof_detector'

module ActiveStorageValidations
class ContentTypeValidator < ActiveModel::EachValidator # :nodoc:
include ActiveStorageable
include Attachable
include Errorable
include Optionable
include Symbolizable
include ASVActiveStorageable
include ASVAttachable
include ASVErrorable
include ASVOptionable
include ASVSymbolizable

AVAILABLE_CHECKS = %i[with in].freeze
ERROR_TYPES = %i[
Expand Down
20 changes: 10 additions & 10 deletions lib/active_storage_validations/dimension_validator.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/attachable'
require_relative 'shared/errorable'
require_relative 'shared/optionable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_optionable'
require_relative 'shared/asv_symbolizable'

module ActiveStorageValidations
class DimensionValidator < ActiveModel::EachValidator # :nodoc
include ActiveStorageable
include Attachable
include Errorable
include Optionable
include Symbolizable
include ASVActiveStorageable
include ASVAttachable
include ASVErrorable
include ASVOptionable
include ASVSymbolizable

AVAILABLE_CHECKS = %i[width height min max].freeze
ERROR_TYPES = %i[
Expand Down
16 changes: 8 additions & 8 deletions lib/active_storage_validations/limit_validator.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/errorable'
require_relative 'shared/optionable'
require_relative 'shared/symbolizable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_errorable'
require_relative 'shared/asv_optionable'
require_relative 'shared/asv_symbolizable'

module ActiveStorageValidations
class LimitValidator < ActiveModel::EachValidator # :nodoc:
include ActiveStorageable
include Errorable
include Optionable
include Symbolizable
include ASVActiveStorageable
include ASVErrorable
include ASVOptionable
include ASVSymbolizable

AVAILABLE_CHECKS = %i[max min].freeze
ERROR_TYPES = %i[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/allow_blankable'
require_relative 'shared/attachable'
require_relative 'shared/contextable'
require_relative 'shared/messageable'
require_relative 'shared/rspecable'
require_relative 'shared/validatable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_allow_blankable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_contextable'
require_relative 'shared/asv_messageable'
require_relative 'shared/asv_rspecable'
require_relative 'shared/asv_validatable'

module ActiveStorageValidations
module Matchers
Expand All @@ -15,13 +15,13 @@ def validate_aspect_ratio_of(attribute_name)
end

class AspectRatioValidatorMatcher
include ActiveStorageable
include AllowBlankable
include Attachable
include Contextable
include Messageable
include Rspecable
include Validatable
include ASVActiveStorageable
include ASVAllowBlankable
include ASVAttachable
include ASVContextable
include ASVMessageable
include ASVRspecable
include ASVValidatable

def initialize(attribute_name)
initialize_allow_blankable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/attachable'
require_relative 'shared/contextable'
require_relative 'shared/messageable'
require_relative 'shared/rspecable'
require_relative 'shared/validatable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_contextable'
require_relative 'shared/asv_messageable'
require_relative 'shared/asv_rspecable'
require_relative 'shared/asv_validatable'

module ActiveStorageValidations
module Matchers
Expand All @@ -14,12 +14,12 @@ def validate_attached_of(attribute_name)
end

class AttachedValidatorMatcher
include ActiveStorageable
include Attachable
include Contextable
include Messageable
include Rspecable
include Validatable
include ASVActiveStorageable
include ASVAttachable
include ASVContextable
include ASVMessageable
include ASVRspecable
include ASVValidatable

def initialize(attribute_name)
initialize_contextable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# Big thank you to the paperclip validation matchers:
# https://github.com/thoughtbot/paperclip/blob/v6.1.0/lib/paperclip/matchers/validate_attachment_size_matcher.rb

require_relative 'shared/active_storageable'
require_relative 'shared/allow_blankable'
require_relative 'shared/attachable'
require_relative 'shared/contextable'
require_relative 'shared/messageable'
require_relative 'shared/rspecable'
require_relative 'shared/validatable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_allow_blankable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_contextable'
require_relative 'shared/asv_messageable'
require_relative 'shared/asv_rspecable'
require_relative 'shared/asv_validatable'

module ActiveStorageValidations
module Matchers
class BaseSizeValidatorMatcher
# BaseSizeValidatorMatcher is an abstract class and shouldn't be instantiated directly.

include ActiveStorageable
include AllowBlankable
include Attachable
include Contextable
include Messageable
include Rspecable
include Validatable
include ASVActiveStorageable
include ASVAllowBlankable
include ASVAttachable
include ASVContextable
include ASVMessageable
include ASVRspecable
include ASVValidatable

def initialize(attribute_name)
initialize_allow_blankable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Big thank you to the paperclip validation matchers:
# https://github.com/thoughtbot/paperclip/blob/v6.1.0/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb

require_relative 'shared/active_storageable'
require_relative 'shared/allow_blankable'
require_relative 'shared/attachable'
require_relative 'shared/contextable'
require_relative 'shared/messageable'
require_relative 'shared/rspecable'
require_relative 'shared/validatable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_allow_blankable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_contextable'
require_relative 'shared/asv_messageable'
require_relative 'shared/asv_rspecable'
require_relative 'shared/asv_validatable'

module ActiveStorageValidations
module Matchers
Expand All @@ -18,13 +18,13 @@ def validate_content_type_of(attribute_name)
end

class ContentTypeValidatorMatcher
include ActiveStorageable
include AllowBlankable
include Attachable
include Contextable
include Messageable
include Rspecable
include Validatable
include ASVActiveStorageable
include ASVAllowBlankable
include ASVAttachable
include ASVContextable
include ASVMessageable
include ASVRspecable
include ASVValidatable

def initialize(attribute_name)
initialize_allow_blankable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require_relative 'shared/active_storageable'
require_relative 'shared/allow_blankable'
require_relative 'shared/attachable'
require_relative 'shared/contextable'
require_relative 'shared/messageable'
require_relative 'shared/rspecable'
require_relative 'shared/validatable'
require_relative 'shared/asv_active_storageable'
require_relative 'shared/asv_allow_blankable'
require_relative 'shared/asv_attachable'
require_relative 'shared/asv_contextable'
require_relative 'shared/asv_messageable'
require_relative 'shared/asv_rspecable'
require_relative 'shared/asv_validatable'

module ActiveStorageValidations
module Matchers
Expand All @@ -15,13 +15,13 @@ def validate_dimensions_of(attribute_name)
end

class DimensionValidatorMatcher
include ActiveStorageable
include AllowBlankable
include Attachable
include Contextable
include Messageable
include Rspecable
include Validatable
include ASVActiveStorageable
include ASVAllowBlankable
include ASVAttachable
include ASVContextable
include ASVMessageable
include ASVRspecable
include ASVValidatable

def initialize(attribute_name)
initialize_allow_blankable
Expand Down
Loading

0 comments on commit cd2a20e

Please sign in to comment.