Class: LanguageConfigParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cli_options, language_config_path = nil) ⇒ LanguageConfigParser

Returns a new instance of LanguageConfigParser.



692
693
694
695
696
# File 'lib/hiptest-publisher/options_parser.rb', line 692

def initialize(cli_options, language_config_path = nil)
  @cli_options = cli_options
  language_config_path ||= LanguageConfigParser.config_path_for(cli_options)
  @config = ParseConfig.new(language_config_path)
end

Class Method Details

.config_path_for(cli_options) ⇒ Object



698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/hiptest-publisher/options_parser.rb', line 698

def self.config_path_for(cli_options)
  config_name = if cli_options.framework.empty?
                  "#{cli_options.language}.conf"
                else
                  "#{cli_options.language}-#{cli_options.framework}.conf"
                end
  config_path = "/lib/config/#{config_name.downcase}"
  config_prefix = if !cli_options.overriden_language_configs.to_s.empty?
                    # If the user has specified a overiden language config path, check it first. If the config
                    # exists there, return that, otherwise fall back to the default setup and look for a config there.
                    expanded = File.expand_path("#{cli_options.overriden_language_configs}/#{config_name.downcase}")

                    # If the file exists in the path the user specified, set the config path to blank so we will be
                    # looking in the exact path that the user requested.
                    if File.file?(expanded)
                      config_path = ''
                      expanded
                    end
                  end

  config_path = File.expand_path("#{config_prefix || hiptest_publisher_path}#{config_path}")

  if !File.file?(config_path)
    if cli_options.framework.to_s.empty?
      message = I18n.t('errors.invalid_config_file_no_framework', hiptest_publisher_path: hiptest_publisher_path, language: cli_options.language.inspect)
    else
      message = I18n.t('errors.invalid_config_file', hiptest_publisher_path: hiptest_publisher_path, language: cli_options.language.inspect, framework: cli_options.framework.inspect)
    end
    raise ArgumentError.new(message)
  end
  File.expand_path(config_path)
end

Instance Method Details

#filtered_group_namesObject



737
738
739
740
741
742
743
# File 'lib/hiptest-publisher/options_parser.rb', line 737

def filtered_group_names
  if @cli_options.groups_to_keep
    group_names.select {|group_name| @cli_options.groups_to_keep.include?(group_name)}
  else
    group_names
  end
end

#group_namesObject



731
732
733
734
735
# File 'lib/hiptest-publisher/options_parser.rb', line 731

def group_names
  @config.groups.reject {|group_name|
    group_name.start_with?('_')
  }
end

#include_group?(group_name) ⇒ Boolean

Returns:

  • (Boolean)


745
746
747
# File 'lib/hiptest-publisher/options_parser.rb', line 745

def include_group?(group_name)
  filtered_group_names.include?(group_name)
end

#language_group_configsObject



749
750
751
# File 'lib/hiptest-publisher/options_parser.rb', line 749

def language_group_configs
  filtered_group_names.map {|group_name| make_language_group_config(group_name)}
end

#metaObject



757
758
759
760
761
762
763
764
765
766
767
768
769
770
# File 'lib/hiptest-publisher/options_parser.rb', line 757

def meta
  treated = {}
  meta_opt = @cli_options.meta || ""

  meta_opt.split(',').each do |m|
    key, value = m.split(':')
    value = true if value == 'true'
    value = false if value == 'false'

    treated[key.strip] = value
  end

  treated
end

#name_action_word(name) ⇒ Object



753
754
755
# File 'lib/hiptest-publisher/options_parser.rb', line 753

def name_action_word(name)
  name.send(get_key_from_group('actionwords', 'naming_convention'))
end