Class: LanguageGroupConfig
- Inherits:
-
Object
- Object
- LanguageGroupConfig
- Defined in:
- lib/hiptest-publisher/options_parser.rb
Constant Summary collapse
- @@MAX_FILE_SIZE =
255
Instance Method Summary collapse
- #[](key) ⇒ Object
- #build_node_rendering_context(node) ⇒ Object
- #can_name_files? ⇒ Boolean
- #each_node_rendering_context(project) ⇒ Object
- #filename_pattern ⇒ Object
- #forced_templates ⇒ Object
- #indentation ⇒ Object
-
#initialize(user_params, language_group_params = nil) ⇒ LanguageGroupConfig
constructor
A new instance of LanguageGroupConfig.
- #language_group_output_directory ⇒ Object
- #nodes(project) ⇒ Object
- #output_dirname(node) ⇒ Object
- #output_filename(node) ⇒ Object
- #shorten_filename(name) ⇒ Object
- #splitted_files? ⇒ Boolean
- #template_dirs ⇒ Object
- #template_finder ⇒ Object
- #with_folders? ⇒ Boolean
Constructor Details
#initialize(user_params, language_group_params = nil) ⇒ LanguageGroupConfig
Returns a new instance of LanguageGroupConfig.
481 482 483 484 485 486 487 488 489 490 |
# File 'lib/hiptest-publisher/options_parser.rb', line 481 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
492 493 494 |
# File 'lib/hiptest-publisher/options_parser.rb', line 492 def [](key) @language_group_params[key] end |
#build_node_rendering_context(node) ⇒ Object
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 613 614 |
# File 'lib/hiptest-publisher/options_parser.rb', line 586 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
517 518 519 520 521 522 523 |
# File 'lib/hiptest-publisher/options_parser.rb', line 517 def can_name_files? if filename_pattern.nil? false else splitted_files? || with_folders? end end |
#each_node_rendering_context(project) ⇒ Object
574 575 576 577 578 579 |
# File 'lib/hiptest-publisher/options_parser.rb', line 574 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_pattern ⇒ Object
496 497 498 |
# File 'lib/hiptest-publisher/options_parser.rb', line 496 def filename_pattern @filename_pattern || self[:named_filename] end |
#forced_templates ⇒ Object
542 543 544 545 546 547 548 549 550 551 552 553 554 |
# File 'lib/hiptest-publisher/options_parser.rb', line 542 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 |
#indentation ⇒ Object
581 582 583 584 |
# File 'lib/hiptest-publisher/options_parser.rb', line 581 def indentation return @user_params[:indent] unless @user_params[:indent].nil? @language_group_params[:indentation] || ' ' end |
#language_group_output_directory ⇒ Object
616 617 618 |
# File 'lib/hiptest-publisher/options_parser.rb', line 616 def language_group_output_directory @user_params["#{@language_group_params[:group_name]}_output_directory"] || @output_directory end |
#nodes(project) ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/hiptest-publisher/options_parser.rb', line 525 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
620 621 622 623 624 625 626 627 628 629 |
# File 'lib/hiptest-publisher/options_parser.rb', line 620 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
631 632 633 634 635 636 637 638 |
# File 'lib/hiptest-publisher/options_parser.rb', line 631 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
640 641 642 643 644 645 646 647 |
# File 'lib/hiptest-publisher/options_parser.rb', line 640 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
504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/hiptest-publisher/options_parser.rb', line 504 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_dirs ⇒ Object
556 557 558 559 560 561 562 |
# File 'lib/hiptest-publisher/options_parser.rb', line 556 def template_dirs if @language_group_params[:template_dirs] @language_group_params[:template_dirs].split(',').map(&:strip) else [] end end |
#template_finder ⇒ Object
564 565 566 567 568 569 570 571 572 |
# File 'lib/hiptest-publisher/options_parser.rb', line 564 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
500 501 502 |
# File 'lib/hiptest-publisher/options_parser.rb', line 500 def with_folders? @with_folders && (node_name == :scenarios || node_name == :folders) end |