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.



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

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



490
491
492
# File 'lib/hiptest-publisher/options_parser.rb', line 490

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

#build_node_rendering_context(node) ⇒ Object



584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
# File 'lib/hiptest-publisher/options_parser.rb', line 584

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],
    meta: @language_group_params[:meta],
    parameter_delimiter: @user_params[:parameter_delimiter],
    namespace: @language_group_params[:namespace],
    uids: @user_params[:uids],
    parent_folder_tags: @user_params[:parent_folder_tags],
    with_dataset_names: @user_params[:with_dataset_names],
    renderer_addons: @language_group_params[:renderer_addons]
  )
end

#can_name_files?Boolean

Returns:

  • (Boolean)


515
516
517
518
519
520
521
# File 'lib/hiptest-publisher/options_parser.rb', line 515

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

#each_node_rendering_context(project) ⇒ Object



572
573
574
575
576
577
# File 'lib/hiptest-publisher/options_parser.rb', line 572

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



494
495
496
# File 'lib/hiptest-publisher/options_parser.rb', line 494

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

#forced_templatesObject



540
541
542
543
544
545
546
547
548
549
550
551
552
# File 'lib/hiptest-publisher/options_parser.rb', line 540

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



579
580
581
582
# File 'lib/hiptest-publisher/options_parser.rb', line 579

def indentation
  return @user_params[:indent] unless @user_params[:indent].nil?
  @language_group_params[:indentation] || '  '
end

#language_group_output_directoryObject



614
615
616
# File 'lib/hiptest-publisher/options_parser.rb', line 614

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

#nodes(project) ⇒ Object



523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/hiptest-publisher/options_parser.rb', line 523

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



618
619
620
621
622
623
624
625
626
627
# File 'lib/hiptest-publisher/options_parser.rb', line 618

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



629
630
631
632
633
634
635
636
# File 'lib/hiptest-publisher/options_parser.rb', line 629

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



638
639
640
641
642
643
644
645
# File 'lib/hiptest-publisher/options_parser.rb', line 638

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)


502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/hiptest-publisher/options_parser.rb', line 502

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



554
555
556
557
558
559
560
# File 'lib/hiptest-publisher/options_parser.rb', line 554

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

#template_finderObject



562
563
564
565
566
567
568
569
570
# File 'lib/hiptest-publisher/options_parser.rb', line 562

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)


498
499
500
# File 'lib/hiptest-publisher/options_parser.rb', line 498

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