class RuboCop::Schema::ExtensionSpec
Constants
- KNOWN_CLASSES
- KNOWN_GEMS
Attributes
specs[R]
Public Class Methods
from_lockfile(lockfile)
click to toggle source
@param [Pathname] lockfile
# 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)
click to toggle source
# 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()
click to toggle source
# 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
new(specs)
click to toggle source
# File lib/rubocop/schema/extension_spec.rb, line 54 def initialize(specs) @specs = specs.dup.sort_by(&:name).freeze end
Public Instance Methods
empty?()
click to toggle source
# File lib/rubocop/schema/extension_spec.rb, line 62 def empty? @specs.empty? end
to_s()
click to toggle source
# File lib/rubocop/schema/extension_spec.rb, line 58 def to_s @specs.join '-' end