Class: Orthoses::ExcludeRBS

Inherits:
Object
  • Object
show all
Defined in:
lib/orthoses/exclude_rbs.rb

Overview

Exclude RBS from output.

Examples:

use Orthoses::ExcludeRBS, paths: Dir['sig/hand-written/**/*.rbs']

Instance Method Summary collapse

Constructor Details

#initialize(loader, paths: nil, rbs: nil) ⇒ ExcludeRBS

Returns a new instance of ExcludeRBS.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
# File 'lib/orthoses/exclude_rbs.rb', line 8

def initialize(loader, paths: nil, rbs: nil)
  raise ArgumentError, ':paths or :rbs keyword is required' if paths.nil? && rbs.nil?

  @loader = loader
  @paths = paths
  @rbs = rbs
end

Instance Method Details

#add_signature_to_known_env(rbs) ⇒ Object



31
32
33
34
# File 'lib/orthoses/exclude_rbs.rb', line 31

def add_signature_to_known_env(rbs)
  buffer, directives, decls = ::RBS::Parser.parse_signature(rbs)
  Utils.rbs_environment.add_signature(buffer: buffer, directives: directives, decls: decls)
end

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/orthoses/exclude_rbs.rb', line 16

def call
  case
  when @paths
    @paths.each do |path|
      add_signature_to_known_env(File.read(path.to_s))
    end
  when @rbs
    add_signature_to_known_env(@rbs)
  else
    raise "bug"
  end

  @loader.call
end