Class: Steep::Drivers::Validate

Inherits:
Object
  • Object
show all
Includes:
Utils::EachSignature
Defined in:
lib/steep/drivers/validate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::EachSignature

#each_file_in_dir, #each_ruby_file, #each_ruby_source, #each_signature

Constructor Details

#initialize(signature_dirs:, stdout:, stderr:) ⇒ Validate

Returns a new instance of Validate.



9
10
11
12
13
14
15
# File 'lib/steep/drivers/validate.rb', line 9

def initialize(signature_dirs:, stdout:, stderr:)
  @signature_dirs = signature_dirs
  @stdout = stdout
  @stderr = stderr

  self.verbose = false
end

Instance Attribute Details

#signature_dirsObject (readonly)

Returns the value of attribute signature_dirs.



4
5
6
# File 'lib/steep/drivers/validate.rb', line 4

def signature_dirs
  @signature_dirs
end

#stderrObject (readonly)

Returns the value of attribute stderr.



6
7
8
# File 'lib/steep/drivers/validate.rb', line 6

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



5
6
7
# File 'lib/steep/drivers/validate.rb', line 5

def stdout
  @stdout
end

#verboseObject

Returns the value of attribute verbose.



7
8
9
# File 'lib/steep/drivers/validate.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/steep/drivers/validate.rb', line 19

def run
  Steep.logger.level = Logger::DEBUG if verbose

  env = AST::Signature::Env.new

  each_signature(signature_dirs, verbose) do |signature|
    env.add signature
  end

  builder = Interface::Builder.new(signatures: env)
  check = Subtyping::Check.new(builder: builder)

  validator = Utils::Validator.new(stdout: stdout, stderr: stderr, verbose: verbose)

  validator.run(env: env, builder: builder, check: check) do |sig|
    stderr.puts "Validating #{sig.name} (#{sig.location.name}:#{sig.location.start_line})..." if verbose
  end ? 0 : 1
end