class Macros4Cuke::Application

Runner for the Macros4Cuke application.

Attributes

options[R]

Public Class Methods

new() click to toggle source
# File lib/macros4cuke/application.rb, line 14
def initialize()
  @options = {}
end

Public Instance Methods

run!(theCmdLineArgs) click to toggle source

Entry point for the application object.

# File lib/macros4cuke/application.rb, line 19
def run!(theCmdLineArgs)
  @options = options_from(theCmdLineArgs)
  return unless options[:setup]
  
  options[:setup].each do |a_path|
    setup_project(a_path)
  end
end

Protected Instance Methods

options_from(theCmdLineArgs) click to toggle source

Retrieve the user-entered command-line options

# File lib/macros4cuke/application.rb, line 31
def options_from(theCmdLineArgs)
  cli = CLI::CmdLine.new
  cli.parse!(theCmdLineArgs.dup)
end
setup_project(aPath) click to toggle source

Make the Cucumber project at the designated path ready for macros. In practice, this is obtained by adding a file in the /features/support dir.

# File lib/macros4cuke/application.rb, line 40
def setup_project(aPath)
  file_name = 'use_macros4cuke'
  prefix = aPath.relative? ? './' : ''
  destination = prefix + aPath.to_s + '/' + file_name + '.rb'

  begin
    raise SupportFileExists.new(destination) if File.exist?(destination)

    template_pathname =
      Macros4Cuke::RootDir + 'templates/use_macros4cuke.erb'
    template = File.read(template_pathname)


    # Create a context for variables used in our templates
    prog_version = Macros4Cuke::Version

    # Create one template engine instance
    engine = ERB.new(template)

    # Generate the text representation with given context
    file_text = engine.result(binding)

    # Write file contents to file in binary mode in order to avoid eol
    # consisting of CRLF
    File.open(destination, 'wb') { |theFile| theFile.write(file_text) }
  rescue Macros4Cuke::CmdLineError => e
    $stderr.puts e.message
    exit
  end
end