File: source_linter.rb

package info (click to toggle)
ruby-librarian 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 632 kB
  • sloc: ruby: 6,109; makefile: 11
file content (55 lines) | stat: -rw-r--r-- 1,124 bytes parent folder | download | duplicates (7)
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