Class: Hiptest::Publisher
- Inherits:
-
Object
- Object
- Hiptest::Publisher
- Defined in:
- lib/hiptest-publisher.rb
Instance Attribute Summary collapse
-
#reporter ⇒ Object
readonly
Returns the value of attribute reporter.
Instance Method Summary collapse
- #add_listener(listener) ⇒ Object
- #export ⇒ Object
- #export_actionword_signature ⇒ Object
- #export_files ⇒ Object
- #fetch_xml_file ⇒ Object
- #get_project(xml) ⇒ Object
-
#initialize(args, listeners: nil, exit_on_bad_arguments: true) ⇒ Publisher
constructor
A new instance of Publisher.
- #mkdirs_for(path) ⇒ Object
- #post_results ⇒ Object
- #print_categories ⇒ Object
- #run ⇒ Object
- #show_actionwords_diff ⇒ Object
- #write_node_to_file(path, node, context, message) ⇒ Object
- #write_to_file(path, message) ⇒ Object
Constructor Details
#initialize(args, listeners: nil, exit_on_bad_arguments: true) ⇒ Publisher
Returns a new instance of Publisher.
20 21 22 23 24 25 |
# File 'lib/hiptest-publisher.rb', line 20 def initialize(args, listeners: nil, exit_on_bad_arguments: true) @reporter = Reporter.new(listeners) @cli_options = OptionsParser.parse(args, reporter) # pass false to prevent hiptest-publisher from exiting, useful when used embedded @exit_on_bad_arguments = exit_on_bad_arguments end |
Instance Attribute Details
#reporter ⇒ Object (readonly)
Returns the value of attribute reporter.
18 19 20 |
# File 'lib/hiptest-publisher.rb', line 18 def reporter @reporter end |
Instance Method Details
#add_listener(listener) ⇒ Object
104 105 106 |
# File 'lib/hiptest-publisher.rb', line 104 def add_listener(listener) reporter.add_listener(listener) end |
#export ⇒ Object
229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/hiptest-publisher.rb', line 229 def export return if @project.nil? "Analyzing data" do @language_config = LanguageConfigParser.new(@cli_options) Hiptest::Nodes::ParentAdder.add(@project) Hiptest::Nodes::ParameterTypeAdder.add(@project) Hiptest::DefaultArgumentAdder.add(@project) Hiptest::GherkinAdder.add(@project) end export_files export_actionword_signature if @language_config.include_group?("actionwords") end |
#export_actionword_signature ⇒ Object
127 128 129 130 131 132 |
# File 'lib/hiptest-publisher.rb', line 127 def export_actionword_signature write_to_file( "#{@cli_options.output_directory}/actionwords_signature.yaml", "Exporting actionword signature" ) { Hiptest::SignatureExporter.export_actionwords(@project).to_yaml } end |
#export_files ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/hiptest-publisher.rb', line 114 def export_files @language_config.language_group_configs.each do |language_group_config| language_group_config.each_node_rendering_context(@project) do |node_rendering_context| write_node_to_file( node_rendering_context.path, node_rendering_context.node, node_rendering_context, "Exporting #{node_rendering_context.description}", ) end end end |
#fetch_xml_file ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/hiptest-publisher.rb', line 69 def fetch_xml_file "Fetching data from Hiptest" do fetch_project_export(@cli_options) end rescue Exception => err puts "Unable to open the file, please check that the token is correct".red reporter.dump_error(err) end |
#get_project(xml) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/hiptest-publisher.rb', line 78 def get_project(xml) "Extracting data" do parser = Hiptest::XMLParser.new(xml, reporter) return parser.build_project end rescue Exception => err reporter.dump_error(err) end |
#mkdirs_for(path) ⇒ Object
98 99 100 101 102 |
# File 'lib/hiptest-publisher.rb', line 98 def mkdirs_for(path) unless Dir.exists?(File.dirname(path)) FileUtils.mkpath(File.dirname(path)) end end |
#post_results ⇒ Object
263 264 265 266 267 268 269 |
# File 'lib/hiptest-publisher.rb', line 263 def post_results "Posting #{@cli_options.push} to #{@cli_options.site}" do push_results(@cli_options) end rescue Exception => err reporter.dump_error(err) end |
#print_categories ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/hiptest-publisher.rb', line 244 def print_categories language_config = LanguageConfigParser.new(@cli_options) group_names = language_config.group_names puts "For language #{@cli_options.language}, available file groups are" group_names.each do |group_name| puts " - #{group_name}" end puts [ "", "Usage examples:", "", "To export only #{group_names.first} files:", " hiptest-publisher --language=#{@cli_options.language} --only=#{group_names.first}", "", "To export both #{group_names.first} and #{group_names[1]} files:", " hiptest-publisher --language=#{@cli_options.language} --only=#{group_names.take(2).join(",")}" ].join("\n") end |
#run ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hiptest-publisher.rb', line 27 def run puts "URL: #{make_url(@cli_options)}".white if @cli_options.verbose begin CliOptionsChecker.new(@cli_options, reporter).check! rescue CliOptionError => e puts e. exit 1 if @exit_on_bad_arguments raise end if @cli_options.only == 'list' print_categories return end if push?(@cli_options) post_results return end if @cli_options.xml_file xml = IO.read(@cli_options.xml_file) else xml = fetch_xml_file end return if xml.nil? @project = get_project(xml) if @cli_options.actionwords_signature export_actionword_signature return end if @cli_options.actionwords_diff? show_actionwords_diff return end export end |
#show_actionwords_diff ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/hiptest-publisher.rb', line 134 def show_actionwords_diff old = nil "Loading previous definition" do old = YAML.load_file("#{@cli_options.output_directory}/actionwords_signature.yaml") end @language_config = LanguageConfigParser.new(@cli_options) Hiptest::Nodes::ParentAdder.add(@project) Hiptest::Nodes::ParameterTypeAdder.add(@project) Hiptest::DefaultArgumentAdder.add(@project) Hiptest::GherkinAdder.add(@project) current = Hiptest::SignatureExporter.export_actionwords(@project, true) diff = Hiptest::SignatureDiffer.diff( old, current) if @cli_options.aw_deleted return if diff[:deleted].nil? diff[:deleted].map {|deleted| puts @language_config.name_action_word(deleted[:name]) } return end if @cli_options.aw_created return if diff[:created].nil? @language_config.language_group_configs.select { |language_group_config| language_group_config[:group_name] == "actionwords" }.each do |language_group_config| diff[:created].each do |created| node_rendering_context = language_group_config.build_node_rendering_context(created[:node]) puts node_rendering_context[:node].render(node_rendering_context) puts "" end end return end if @cli_options.aw_renamed return if diff[:renamed].nil? diff[:renamed].map {|renamed| puts "#{@language_config.name_action_word(renamed[:name])}\t#{@language_config.name_action_word(renamed[:new_name])}" } return end if @cli_options.aw_signature_changed return if diff[:signature_changed].nil? @language_config.language_group_configs.select { |language_group_config| language_group_config[:group_name] == "actionwords" }.each do |language_group_config| diff[:signature_changed].each do |signature_changed| node_rendering_context = language_group_config.build_node_rendering_context(signature_changed[:node]) puts signature_changed[:node].render(node_rendering_context) puts "" end end return end unless diff[:deleted].nil? puts "#{pluralize(diff[:deleted].length, "action word")} deleted:" puts diff[:deleted].map {|d| "- #{d[:name]}"}.join("\n") puts "" end unless diff[:created].nil? puts "#{pluralize(diff[:created].length, "action word")} created:" puts diff[:created].map {|c| "- #{c[:name]}"}.join("\n") puts "" end unless diff[:renamed].nil? puts "#{pluralize(diff[:renamed].length, "action word")} renamed:" puts diff[:renamed].map {|r| "- #{r[:name]} => #{r[:new_name]}"}.join("\n") puts "" end unless diff[:signature_changed].nil? puts "#{pluralize(diff[:signature_changed].length, "action word")} which signature changed:" puts diff[:signature_changed].map {|c| "- #{c[:name]}"}.join("\n") puts "" end if diff.empty? puts "No action words changed" puts "" end rescue Exception => err reporter.dump_error(err) end |
#write_node_to_file(path, node, context, message) ⇒ Object
108 109 110 111 112 |
# File 'lib/hiptest-publisher.rb', line 108 def write_node_to_file(path, node, context, ) write_to_file(path, ) do Hiptest::Renderer.render(node, context) end end |
#write_to_file(path, message) ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/hiptest-publisher.rb', line 87 def write_to_file(path, ) "#{}: #{path}" do mkdirs_for(path) File.open(path, 'w') do |file| file.write(yield) end end rescue Exception => err reporter.dump_error(err) end |