Sha256: a29debbb16119ab291b1b00ab94f211e5d2fcbc2a8d5ba0c77caf9547a0ffed0

Contents?: true

Size: 1.42 KB

Versions: 6869

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    # Common functionality for handling percent literal delimiters.
    class PreferredDelimiters
      attr_reader :type, :config

      PERCENT_LITERAL_TYPES = %w[% %i %I %q %Q %r %s %w %W %x].freeze

      def initialize(type, config, preferred_delimiters)
        @type = type
        @config = config
        @preferred_delimiters = preferred_delimiters
      end

      def delimiters
        preferred_delimiters[type].split(//)
      end

      private

      def ensure_valid_preferred_delimiters
        invalid = preferred_delimiters_config.keys -
                  (PERCENT_LITERAL_TYPES + %w[default])
        return if invalid.empty?

        raise ArgumentError,
              "Invalid preferred delimiter config key: #{invalid.join(', ')}"
      end

      def preferred_delimiters
        @preferred_delimiters ||=
          begin
            ensure_valid_preferred_delimiters

            if preferred_delimiters_config.key?('default')
              Hash[PERCENT_LITERAL_TYPES.map do |type|
                [type, preferred_delimiters_config[type] ||
                  preferred_delimiters_config['default']]
              end]
            else
              preferred_delimiters_config
            end
          end
      end

      def preferred_delimiters_config
        config.for_cop('Style/PercentLiteralDelimiters')['PreferredDelimiters']
      end
    end
  end
end

Version data entries

6,869 entries across 6,843 versions & 29 rubygems

Version Path
cybrid_api_organization_ruby-0.123.118 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.117 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.116 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.115 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
ory-client-1.15.17 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.114 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.113 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_organization_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_bank_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb
cybrid_api_id_ruby-0.123.112 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/mixin/preferred_delimiters.rb