Class: CliOptions

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

Instance Method Summary collapse

Constructor Details

#initialize(hash = nil) ⇒ CliOptions

Returns a new instance of CliOptions.



58
59
60
61
62
63
# File 'lib/hiptest-publisher/options_parser.rb', line 58

def initialize(hash=nil)
  hash ||= {}
  hash[:language] ||= ""
  hash[:framework] ||= ""
  super(__cli_args: Set.new, __config_args: Set.new, **hash)
end

Instance Method Details

#actionwords_diff?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/hiptest-publisher/options_parser.rb', line 65

def actionwords_diff?
  actionwords_diff || aw_deleted || aw_created || aw_renamed || aw_signature_changed
end

#groups_to_keepObject



77
78
79
# File 'lib/hiptest-publisher/options_parser.rb', line 77

def groups_to_keep
  only.split(",") if only
end

#language_frameworkObject



69
70
71
72
73
74
75
# File 'lib/hiptest-publisher/options_parser.rb', line 69

def language_framework
  if framework.empty?
    language
  else
    "#{language}-#{framework}"
  end
end

#normalize!(reporter = nil) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/hiptest-publisher/options_parser.rb', line 81

def normalize!(reporter = nil)
  modified_options = self.clone
  if actionwords_only
    modified_options.only = 'actionwords'
  elsif tests_only
    modified_options.only = 'tests'
  end

  if language.include?('-')
    modified_options.language, modified_options.framework = language.split("-", 2)
  elsif framework.empty?
    # pick first framework for the language
    _, frameworks = OptionsParser.languages.find do |language, frameworks|
      language.downcase.gsub(' ', '') == self.language.downcase.gsub(' ', '')
    end
    if frameworks
      modified_options.framework = frameworks.first.downcase
    end
  end

  if self != modified_options
    delta = modified_options.table.select do |key, value|
      modified_options[key] != self[key]
    end
    marshal_load(modified_options.marshal_dump)
    if reporter
      reporter.show_options(delta, 'Options have been normalized. Values updated:')
    end
    return delta
  end
end