Class: Steep::Drivers::Init

Inherits:
Object show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/init.rb

Constant Summary collapse

TEMPLATE =
<<~EOF
# D = Steep::Diagnostic
#
# target :lib do
#   signature "sig"
#   ignore_signature "sig/test"
#
#   check "lib"                       # Directory name
#   check "path/to/source.rb"         # File name
#   check "app/models/**/*.rb"        # Glob
#   # ignore "lib/templates/*.rb"
#
#   # library "pathname"              # Standard libraries
#   # library "strong_json"           # Gems
#
#   # configure_code_diagnostics(D::Ruby.default)      # `default` diagnostics setting (applies by default)
#   # configure_code_diagnostics(D::Ruby.strict)       # `strict` diagnostics setting
#   # configure_code_diagnostics(D::Ruby.lenient)      # `lenient` diagnostics setting
#   # configure_code_diagnostics(D::Ruby.silent)       # `silent` diagnostics setting
#   # configure_code_diagnostics do |hash|             # You can setup everything yourself
#   #   hash[D::Ruby::NoMethod] = :information
#   # end
# end

# target :test do
#   unreferenced!                     # Skip type checking the `lib` code when types in `test` target is changed
#   signature "sig/test"              # Put RBS files for tests under `sig/test`
#   check "test"                      # Type check Ruby scripts under `test`
#
#   configure_code_diagnostics(D::Ruby.lenient)      # Weak type checking for test code
#
#   # library "pathname"              # Standard libraries
# end
EOF

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#disable_install_collection, #steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#install_collection, #keep_diagnostic?, #load_config, #request_id, #shutdown_exit, #wait_for_message, #wait_for_response_id

Constructor Details

#initialize(stdout:, stderr:) ⇒ Init

Returns a new instance of Init.



45
46
47
48
49
# File 'lib/steep/drivers/init.rb', line 45

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr
  @force_write = false
end

Instance Attribute Details

#force_writeObject

Returns the value of attribute force_write.



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

def force_write
  @force_write
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#runObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/steep/drivers/init.rb', line 51

def run
  path = steepfile || Pathname("Steepfile")

  if path.file? && !force_write
    stdout.puts "#{path} already exists, --force to overwrite"
    return 1
  end

  stdout.puts "Writing #{path}..."
  path.write(TEMPLATE)

  0
end