class Rspec::Usecases::Generator::BaseGenerator

Base generator contains helper methods

Attributes

document[RW]
options[RW]
output[RW]

Public Class Methods

new(document, options = nil) click to toggle source
# File lib/rspec/usecases/generator/base_generator.rb, line 13
def initialize(document, options = nil)
  @document = document
  @options = options
  @output = ''
end

Public Instance Methods

open_file_in_vscode(file) click to toggle source

Open the file in vscode

# File lib/rspec/usecases/generator/base_generator.rb, line 52
def open_file_in_vscode(file)
  system("code #{file}")
end
prettier_file(file) click to toggle source

Run the file through prettier and then write back to that file

# File lib/rspec/usecases/generator/base_generator.rb, line 42
def prettier_file(file)
  # npm install -g prettier @prettier/plugin-ruby

  cmd = "prettier --check #{file} --write #{file}"

  puts cmd
  system(cmd)
end
print_output() click to toggle source

Print output to console

write_file(file) click to toggle source

Write the file, force creation of folder if needed

# File lib/rspec/usecases/generator/base_generator.rb, line 35
def write_file(file)
  FileUtils.mkdir_p(File.dirname(file))

  File.write(file, @output)
end
write_lf() click to toggle source

Write line feed character ot output buffer

# File lib/rspec/usecases/generator/base_generator.rb, line 25
def write_lf
  @output = "#{@output}\n"
end
write_line(line = nil) click to toggle source

Write line of text to the output buffer and then add line feed character

# File lib/rspec/usecases/generator/base_generator.rb, line 20
def write_line(line = nil)
  @output = "#{@output}#{line}\n" unless line == ''
end