Class: LanguageGroupConfig

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

Constant Summary collapse

@@MAX_FILE_SIZE =
255

Instance Method Summary collapse

Constructor Details

#initialize(user_params, language_group_params = nil) ⇒ LanguageGroupConfig

Returns a new instance of LanguageGroupConfig.



444
445
446
447
448
449
450
451
452
453
# File 'lib/hiptest-publisher/options_parser.rb', line 444

def initialize(user_params, language_group_params = nil)
  @output_directory = user_params.output_directory || ""
  @filename_pattern = user_params.filename_pattern
  @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



455
456
457
# File 'lib/hiptest-publisher/options_parser.rb', line 455

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

#build_node_rendering_context(node) ⇒ Object



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/hiptest-publisher/options_parser.rb', line 548

def build_node_rendering_context(node)
  relative_path = File.join(output_dirname(node), output_filename(node))
  relative_path = relative_path[1..-1] if relative_path[0] == '/'
  path = File.join(language_group_output_directory, relative_path)

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

  NodeRenderingContext.new(
    path: path,
    relative_path: relative_path,
    indentation: indentation,
    template_finder: template_finder,
    description: description,
    node: node,
    call_prefix: @language_group_params[:call_prefix],
    package: @language_group_params[:package],
    parameter_delimiter: @user_params[:parameter_delimiter],
    namespace: @language_group_params[:namespace],
    uids: @user_params[:uids],
    with_dataset_names: @user_params[:with_dataset_names],
    renderer_addons: @language_group_params[:renderer_addons]
  )
end

#can_name_files?Boolean

Returns:

  • (Boolean)


480
481
482
483
484
485
486
# File 'lib/hiptest-publisher/options_parser.rb', line 480

def can_name_files?
  if filename_pattern.nil?
    false
  else
    splitted_files? || with_folders?
  end
end

#each_node_rendering_context(project) ⇒ Object



537
538
539
540
541
542
# File 'lib/hiptest-publisher/options_parser.rb', line 537

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

#filename_patternObject



459
460
461
# File 'lib/hiptest-publisher/options_parser.rb', line 459

def filename_pattern
  @filename_pattern || self[:named_filename]
end

#forced_templatesObject



505
506
507
508
509
510
511
512
513
514
515
516
517
# File 'lib/hiptest-publisher/options_parser.rb', line 505

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



544
545
546
# File 'lib/hiptest-publisher/options_parser.rb', line 544

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

#language_group_output_directoryObject



576
577
578
# File 'lib/hiptest-publisher/options_parser.rb', line 576

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

#nodes(project) ⇒ Object



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/hiptest-publisher/options_parser.rb', line 488

def nodes(project)
  case node_name
  when :tests, :scenarios, :actionwords, :libraries
    if splitted_files?
      project.children[node_name].children[node_name]
    elsif with_folders?
      get_folder_nodes(project)
    else
      [project.children[node_name]]
    end
  when :library
    [project.children[:libraries]]
  when :folders
    get_folder_nodes(project)
  end
end

#output_dirname(node) ⇒ Object



580
581
582
583
584
585
586
587
588
589
# File 'lib/hiptest-publisher/options_parser.rb', line 580

def output_dirname(node)
  return "" unless with_folders?
  folder = node.folder
  hierarchy = []
  while folder && !folder.root?
    hierarchy << normalized_dirname(folder.children[:name])
    folder = folder.parent
  end
  File.join(*hierarchy.reverse)
end

#output_filename(node) ⇒ Object



591
592
593
594
595
596
597
598
# File 'lib/hiptest-publisher/options_parser.rb', line 591

def output_filename(node)
  if can_name_files?
    name = shorten_filename(normalized_filename(node.children[:name] || ''))
    filename = filename_pattern.gsub('%s', name)
  else
    self[:filename]
  end
end

#shorten_filename(name) ⇒ Object



600
601
602
603
604
605
606
607
# File 'lib/hiptest-publisher/options_parser.rb', line 600

def shorten_filename(name)
  mandatory_characters = filename_pattern.gsub('%s', '').length
  if name.length + mandatory_characters > @@MAX_FILE_SIZE
    "#{name[0, (@@MAX_FILE_SIZE - 32 - mandatory_characters)]}#{Digest::MD5.hexdigest(name)}"
  else
    name
  end
end

#splitted_files?Boolean

Returns:

  • (Boolean)


467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/hiptest-publisher/options_parser.rb', line 467

def splitted_files?
  if filename_pattern.nil?
    # if we can't give a different name for each file, we can't split them
    false
  elsif self[:filename].nil?
    # if we can't give a name to a single file, we must split them
    true
  else
    # both options are possible, do as user specified
    @split_scenarios
  end
end

#template_dirsObject



519
520
521
522
523
524
525
# File 'lib/hiptest-publisher/options_parser.rb', line 519

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

#template_finderObject



527
528
529
530
531
532
533
534
535
# File 'lib/hiptest-publisher/options_parser.rb', line 527

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)


463
464
465
# File 'lib/hiptest-publisher/options_parser.rb', line 463

def with_folders?
  @with_folders && (node_name == :scenarios || node_name == :folders)
end