class RuboCop::Schema::DefaultsRipper

Constants

EXCLUDE_ATTRIBUTES
TYPE_MAP

Attributes

cops[R]

@return [Array<CopInfo>]

Public Class Methods

new(defaults) click to toggle source

@param [Hash] defaults

# File lib/rubocop/schema/defaults_ripper.rb, line 20
def initialize(defaults)
  @cops = defaults.map do |cop_name, attributes|
    next unless attributes.is_a? Hash

    CopInfo.new(
      name:               cop_name,
      description:        attributes['Description'],
      enabled_by_default: attributes['Enabled'] == true,
      attributes:         transform_attributes(attributes)
    )
  end.compact
end

Private Instance Methods

transform_attributes(hash) click to toggle source
# File lib/rubocop/schema/defaults_ripper.rb, line 35
def transform_attributes(hash)
  hash.map do |name, default|
    next if EXCLUDE_ATTRIBUTES.include? name

    Attribute.new(
      name:    name,
      type:    TYPE_MAP.find { |_, v| v.any? { |c| default.is_a? c } }&.first&.to_s,
      default: default
    )
  end.compact
end