Class: LanguageGroupConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/hiptest-publisher/options_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(user_params, language_group_params = nil) ⇒ LanguageGroupConfig

Returns a new instance of LanguageGroupConfig.



343
344
345
346
347
348
349
350
351
# File 'lib/hiptest-publisher/options_parser.rb', line 343

def initialize(user_params, language_group_params = nil)
  @output_directory = user_params.output_directory || ""
  @split_scenarios = user_params.split_scenarios
  @with_folders = user_params.with_folders
  @leafless_export = user_params.leafless_export
  @language_group_params = language_group_params || {}

  @user_params = user_params
end

Instance Method Details

#[](key) ⇒ Object



353
354
355
# File 'lib/hiptest-publisher/options_parser.rb', line 353

def [](key)
  @language_group_params[key]
end

#build_node_rendering_context(node) ⇒ Object



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
# File 'lib/hiptest-publisher/options_parser.rb', line 423

def build_node_rendering_context(node)
  path = File.join(language_group_output_directory, output_file(node))

  if splitted_files?
    description = "#{singularize(node_name)} \"#{node.children[:name]}\""
  else
    description = node_name.to_s
  end

  NodeRenderingContext.new(
    path: path,
    indentation: indentation,
    template_finder: template_finder,
    description: description,
    node: node,
    call_prefix: @language_group_params[:call_prefix],
    package: @language_group_params[:package],
    namespace: @language_group_params[:namespace]
  )
end

#each_node_rendering_context(project) ⇒ Object



412
413
414
415
416
417
# File 'lib/hiptest-publisher/options_parser.rb', line 412

def each_node_rendering_context(project)
  return to_enum(:each_node_rendering_context, project) unless block_given?
  nodes(project).each do |node|
    yield build_node_rendering_context(node)
  end
end

#forced_templatesObject



380
381
382
383
384
385
386
387
388
389
390
391
392
# File 'lib/hiptest-publisher/options_parser.rb', line 380

def forced_templates
  forced = {}
  if splitted_files?
    forced.merge!(
      "scenario" => "single_scenario",
      "test" => "single_test",
    )
  end
  if @language_group_params[:forced_templates]
    forced.merge!(@language_group_params[:forced_templates])
  end
  forced
end

#indentationObject



419
420
421
# File 'lib/hiptest-publisher/options_parser.rb', line 419

def indentation
  @language_group_params[:indentation] || '  '
end

#language_group_output_directoryObject



444
445
446
# File 'lib/hiptest-publisher/options_parser.rb', line 444

def language_group_output_directory
  @user_params["#{@language_group_params[:group_name]}_output_directory"] || @output_directory
end

#nodes(project) ⇒ Object



371
372
373
374
375
376
377
378
# File 'lib/hiptest-publisher/options_parser.rb', line 371

def nodes(project)
  case node_name
  when :tests, :scenarios, :actionwords
    get_children(project, node_name)
  when :folders
    project.children[:test_plan].children[:folders].select {|folder| folder.children[:scenarios].length > 0}
  end
end

#output_directory(node) ⇒ Object



448
449
450
451
452
453
454
455
456
# File 'lib/hiptest-publisher/options_parser.rb', line 448

def output_directory(node)
  folder = node.folder
  hierarchy = []
  while folder && !folder.root?
    hierarchy << normalized_filename(folder.children[:name])
    folder = folder.parent
  end
  File.join(*hierarchy.reverse)
end

#output_file(node) ⇒ Object



458
459
460
461
462
463
464
465
466
467
# File 'lib/hiptest-publisher/options_parser.rb', line 458

def output_file(node)
  if splitted_files?
    name = normalized_filename(node.children[:name])
    filename = self[:scenario_filename].gsub('%s', name)
    directory = with_folders? ? output_directory(node) : ""
    File.join(directory, filename)
  else
    self[:filename]
  end
end

#splitted_files?Boolean

Returns:

  • (Boolean)


361
362
363
364
365
366
367
368
369
# File 'lib/hiptest-publisher/options_parser.rb', line 361

def splitted_files?
  if self[:scenario_filename].nil?
    false
  elsif self[:filename].nil?
    true
  else
    @split_scenarios
  end
end

#template_dirsObject



394
395
396
397
398
399
400
# File 'lib/hiptest-publisher/options_parser.rb', line 394

def template_dirs
  if @language_group_params[:template_dirs]
    @language_group_params[:template_dirs].split(',').map(&:strip)
  else
    []
  end
end

#template_finderObject



402
403
404
405
406
407
408
409
410
# File 'lib/hiptest-publisher/options_parser.rb', line 402

def template_finder
  @template_finder ||= TemplateFinder.new(
    template_dirs: template_dirs,
    overriden_templates: @language_group_params[:overriden_templates],
    indentation: indentation,
    forced_templates: forced_templates,
    fallback_template: @language_group_params[:fallback_template],
  )
end

#with_folders?Boolean

Returns:

  • (Boolean)


357
358
359
# File 'lib/hiptest-publisher/options_parser.rb', line 357

def with_folders?
  @with_folders
end