Class: RuboCop::Cop::PreferredDelimiters
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/rubocop/cop/mixin/preferred_delimiters.rb |
Overview
Common functionality for handling percent literal delimiters.
Constant Summary
-
PERCENT_LITERAL_TYPES =
# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 9%w[% %i %I %q %Q %r %s %w %W %x].freeze
Class Method Summary
Instance Attribute Summary
Instance Method Summary
- #delimiters
- #ensure_valid_preferred_delimiters private
- #preferred_delimiters private
- #preferred_delimiters_config private
Constructor Details
.new(type, config, preferred_delimiters) ⇒ PreferredDelimiters
# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 11
def initialize(type, config, preferred_delimiters) @type = type @config = config @preferred_delimiters = preferred_delimiters end
Instance Attribute Details
#config (readonly)
[ GitHub ]#type (readonly)
[ GitHub ]# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 7
attr_reader :type, :config
Instance Method Details
#delimiters
[ GitHub ]# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 17
def delimiters preferred_delimiters[type].chars end
#ensure_valid_preferred_delimiters (private)
# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 23
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
#preferred_delimiters (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 30
def preferred_delimiters @preferred_delimiters ||= begin ensure_valid_preferred_delimiters if preferred_delimiters_config.key?('default') PERCENT_LITERAL_TYPES.to_h do |type| [type, preferred_delimiters_config[type] || preferred_delimiters_config['default']] end else preferred_delimiters_config end end end
#preferred_delimiters_config (private)
[ GitHub ]# File 'lib/rubocop/cop/mixin/preferred_delimiters.rb', line 45
def preferred_delimiters_config config.for_cop('Style/PercentLiteralDelimiters')['PreferredDelimiters'] end