Class: Steep::Drivers::Init

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

Constant Summary collapse

TEMPLATE =
"# target :lib do\n#   signature \"sig\"\n#\n#   check \"lib\"                       # Directory name\n#   check \"Gemfile\"                   # File name\n#   check \"app/models/**/*.rb\"        # Glob\n#   # ignore \"lib/templates/*.rb\"\n#\n#   # library \"pathname\", \"set\"       # Standard libraries\n#   # library \"strong_json\"           # Gems\n# end\n\n# target :spec do\n#   signature \"sig\", \"sig-private\"\n#\n#   check \"spec\"\n#\n#   # library \"pathname\", \"set\"       # Standard libraries\n#   # library \"rspec\"\n# end\n"

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



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