Class: Steep::Drivers::Init

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

Constant Summary collapse

TEMPLATE =
<<~EOF
# target :lib do
#   signature "sig"
#
#   check "lib"                       # Directory name
#   check "Gemfile"                   # File name
#   check "app/models/**/*.rb"        # Glob
#   # ignore "lib/templates/*.rb"
#
#   # library "pathname", "set"       # Standard libraries
#   # library "strong_json"           # Gems
# end

# target :spec do
#   signature "sig", "sig-private"
#
#   check "spec"
#
#   # library "pathname", "set"       # Standard libraries
#   # library "rspec"
# end
EOF

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#load_config, #type_check

Constructor Details

#initialize(stdout:, stderr:) ⇒ Init

Returns a new instance of Init.



33
34
35
36
37
# File 'lib/steep/drivers/init.rb', line 33

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



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/steep/drivers/init.rb', line 39

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