1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
module Librarian
module Linter
class SourceLinter
class << self
def lint!(klass)
new(klass).lint!
end
end
attr_accessor :klass
private :klass=
def initialize(klass)
self.klass = klass
end
def lint!
lint_class_responds_to! *[
:lock_name,
:from_spec_args,
:from_lock_options,
]
lint_instance_responds_to! *[
:to_spec_args,
:to_lock_options,
:manifests,
:fetch_version,
:fetch_dependencies,
:pinned?,
:unpin!,
:install!,
]
end
private
def lint_class_responds_to!(*names)
missing = names.reject{|name| klass.respond_to?(name)}
return if missing.empty?
raise "class must respond to #{missing.join(', ')}"
end
def lint_instance_responds_to!(*names)
missing = names - klass.public_instance_methods.map(&:to_sym)
return if missing.empty?
raise "instance must respond to #{missing.join(', ')}"
end
end
end
end
|