Class: RuboCop::Schema::ExtensionSpec
- Inherits:
-
Object
- Object
- RuboCop::Schema::ExtensionSpec
- Defined in:
- lib/rubocop/schema/extension_spec.rb
Constant Summary collapse
- KNOWN_CLASSES =
Set.new( %w[ RuboCop RuboCop::Rake RuboCop::RSpec RuboCop::Minitest RuboCop::Performance RuboCop::Rails ] ).freeze
- KNOWN_GEMS =
Set.new(['rubocop', *KNOWN_CLASSES.map { |e| e.sub('::', '-').downcase }]).freeze
Instance Attribute Summary collapse
-
#specs ⇒ Object
readonly
Returns the value of attribute specs.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(specs) ⇒ ExtensionSpec
constructor
A new instance of ExtensionSpec.
- #to_s ⇒ Object
Constructor Details
#initialize(specs) ⇒ ExtensionSpec
Returns a new instance of ExtensionSpec.
54 55 56 |
# File 'lib/rubocop/schema/extension_spec.rb', line 54 def initialize(specs) @specs = specs.dup.sort_by(&:name).freeze end |
Instance Attribute Details
#specs ⇒ Object (readonly)
Returns the value of attribute specs.
52 53 54 |
# File 'lib/rubocop/schema/extension_spec.rb', line 52 def specs @specs end |
Class Method Details
.from_lockfile(lockfile) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/rubocop/schema/extension_spec.rb', line 32 def self.from_lockfile(lockfile) new(lockfile.readlines.map do |line| next unless line =~ /\A\s+(rubocop(?:-\w+)?) \((\d+(?:\.\d+)+)\)\s*\z/ next unless KNOWN_GEMS.include? $1 Spec.new(name: $1, version: $2) end.compact) end |
.from_string(string) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rubocop/schema/extension_spec.rb', line 41 def self.from_string(string) new(string.split('-').each_slice(2).map do |(name, version)| name = "rubocop-#{name}" unless name == 'rubocop' raise ArgumentError, "Unknown gem '#{name}'" unless KNOWN_GEMS.include? name raise ArgumentError, "Invalid version '#{version}'" unless version&.match? /\A\d+(?:\.\d+)+\z/ Spec.new(name: name, version: version) end) end |
.internal ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubocop/schema/extension_spec.rb', line 19 def self.internal @internal ||= new(KNOWN_CLASSES.map do |klass_name| next unless Object.const_defined? klass_name klass = Object.const_get(klass_name) Spec.new( name: klass.name.sub('::', '-').downcase, version: (defined?(klass::VERSION) ? klass::VERSION : klass::Version::STRING) ) end.compact) end |
Instance Method Details
#empty? ⇒ Boolean
62 63 64 |
# File 'lib/rubocop/schema/extension_spec.rb', line 62 def empty? @specs.empty? end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/rubocop/schema/extension_spec.rb', line 58 def to_s @specs.join '-' end |