class Cukedep::Application

Runner for the Cukedep application.

Attributes

proj_dir[R]

Public Instance Methods

run!(theCmdLineArgs) click to toggle source

Entry point for the application object.

# File lib/cukedep/application.rb, line 15
def run!(theCmdLineArgs)
  options = options_from(theCmdLineArgs)
  create_default_cfg if options[:setup]
  config = Config.load_cfg(Cukedep::YMLFilename)

  # Complain if no project dir is specified
  if config.proj_dir.nil? || config.proj_dir.empty?
    if options[:project]
      @proj_dir = options[:project]
    else
      msg_p1 = "No project dir specified in '#{Cukedep::YMLFilename}'"
      msg_p2 = ' nor via --project option.'
      raise StandardError, msg_p1 + msg_p2
    end
  else
    @proj_dir = config.proj_dir
  end

  feature_files = parse_features(config.feature_encoding)

  model = FeatureModel.new(feature_files)
  generate_files(model, config)

  return if options[:dryrun]

  rake_cmd = 'rake -f cukedep.rake'
  system(rake_cmd)
end

Protected Instance Methods

create_default_cfg() click to toggle source

Create a local copy of the .cukedep.yml file, then stop the application.

# File lib/cukedep/application.rb, line 54
def create_default_cfg
  if File.exist?(Cukedep::YMLFilename)
    puts "OK to overwrite file #{Cukedep::YMLFilename}."
    puts '(Y/N)?'
    answer = $stdin.gets
    exit if answer =~ /^\s*[Nn]\s*$/
  end
  Config.default.write(Cukedep::YMLFilename)

  exit
end
generate_files(aModel, aConfig) click to toggle source
# File lib/cukedep/application.rb, line 88
def generate_files(aModel, aConfig)
  # Sort the feature files by dependency order.
  aModel.sort_features_by_dep

  puts "\nGenerating:"

  # Generate CSV files detailing the feature to identifier mapping
  # and vise versa
  # TODO: replace hard-coded names by value from config
  feature2id_report = aConfig.feature2id.name
  id2feature_report = aConfig.id2feature.name
  aModel.mapping_reports(feature2id_report, id2feature_report, true)
  aModel.draw_dependency_graph(aConfig.graph_file.name, true)
  aModel.generate_rake_tasks(aConfig.rake_file, proj_dir)
end
options_from(theCmdLineArgs) click to toggle source

Retrieve the user-entered command-line options

# File lib/cukedep/application.rb, line 47
def options_from(theCmdLineArgs)
  cli = CLI::CmdLine.new
  cli.parse!(theCmdLineArgs.dup)
end
parse_features(external_encoding) click to toggle source

Parse the feature files (with the specified external encoding)

# File lib/cukedep/application.rb, line 76
def parse_features(external_encoding)
  # Create a Gherkin listener
  listener = Cukedep::GherkinListener.new

  # Parse the feature files in work directory
  is_verbose = true
  gherkin_facade = GherkinFacade.new(is_verbose, external_encoding)
  gherkin_facade.parse_features(listener, ['*.feature'])

  return listener.feature_files
end