Class: Hiptest::DiffDisplayer
- Inherits:
-
Object
- Object
- Hiptest::DiffDisplayer
- Defined in:
- lib/hiptest-publisher/formatters/diff_displayer.rb
Instance Method Summary collapse
- #as_api ⇒ Object
- #display ⇒ Object
- #display_as_json ⇒ Object
- #display_created ⇒ Object
- #display_definition_changed ⇒ Object
- #display_deleted ⇒ Object
- #display_renamed ⇒ Object
- #display_signature_changed ⇒ Object
- #display_summary ⇒ Object
- #export_as_json ⇒ Object
-
#initialize(diff, cli_options, language_config, file_writer) ⇒ DiffDisplayer
constructor
A new instance of DiffDisplayer.
Constructor Details
#initialize(diff, cli_options, language_config, file_writer) ⇒ DiffDisplayer
Returns a new instance of DiffDisplayer.
5 6 7 8 9 10 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 5 def initialize(diff, , language_config, file_writer) @diff = diff @cli_options = @language_config = language_config @file_writer = file_writer end |
Instance Method Details
#as_api ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 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 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 64 def as_api data = {} data[:deleted] = @diff[:deleted].map {|aw| { name: aw[:name], name_in_code: @language_config.name_action_word(aw[:name]) } } unless @diff[:deleted].nil? data[:created] = @diff[:created].map {|aw| { name: aw[:name], skeleton: actionword_skeleton(aw) } } unless @diff[:created].nil? data[:renamed] = @diff[:renamed].map {|aw| { name: aw[:name], old_name: @language_config.name_action_word(aw[:name]), new_name: @language_config.name_action_word(aw[:new_name]) } } unless @diff[:renamed].nil? data[:signature_changed] = @diff[:signature_changed].map {|aw| { name: aw[:name], skeleton: actionword_skeleton(aw) } } unless @diff[:signature_changed].nil? data[:definition_changed] = @diff[:definition_changed].map {|aw| { name: aw[:name], skeleton: actionword_skeleton(aw) } } unless @diff[:definition_changed].nil? return data end |
#display ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 12 def display return export_as_json if @cli_options.actionwords_diff_json && @cli_options.output_directory return display_as_json if @cli_options.actionwords_diff_json return display_deleted if @cli_options.aw_deleted return display_created if @cli_options.aw_created return display_renamed if @cli_options.aw_renamed return display_signature_changed if @cli_options.aw_signature_changed return display_definition_changed if @cli_options.aw_definition_changed display_summary end |
#display_as_json ⇒ Object
60 61 62 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 60 def display_as_json output(JSON.pretty_generate(as_api)) end |
#display_created ⇒ Object
24 25 26 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 24 def display_created return display_skeletons(@diff[:created]) end |
#display_definition_changed ⇒ Object
40 41 42 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 40 def display_definition_changed display_skeletons(@diff[:definition_changed]) end |
#display_deleted ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 44 def display_deleted return if @diff[:deleted].nil? output(@diff[:deleted].map {|deleted| @language_config.name_action_word(deleted[:name]) }) end |
#display_renamed ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 28 def display_renamed return if @diff[:renamed].nil? output(@diff[:renamed].map {|renamed| "#{@language_config.name_action_word(renamed[:name])}\t#{@language_config.name_action_word(renamed[:new_name])}" }) end |
#display_signature_changed ⇒ Object
36 37 38 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 36 def display_signature_changed display_skeletons(@diff[:signature_changed]) end |
#display_summary ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 107 def display_summary command_line = @cli_options.command_line_used(exclude: [:actionwords_diff]) unless @diff[:deleted].nil? puts I18n.t('actionwords_diff.summary.deleted', count: @diff[:deleted].length, command_line: command_line, list: displayable_list(@diff[:deleted])) puts "" end unless @diff[:created].nil? puts I18n.t('actionwords_diff.summary.created', count: @diff[:created].length, command_line: command_line, list: displayable_list(@diff[:created])) puts "" end unless @diff[:renamed].nil? puts I18n.t('actionwords_diff.summary.renamed', count: @diff[:renamed].length, command_line: command_line, list: displayable_list(@diff[:renamed])) puts "" end unless @diff[:signature_changed].nil? puts I18n.t('actionwords_diff.summary.signature_changed', count: @diff[:signature_changed].length, command_line: command_line, list: displayable_list(@diff[:signature_changed])) puts "" end unless @diff[:definition_changed].nil? puts I18n.t('actionwords_diff.summary.definition_changed', count: @diff[:definition_changed].length, command_line: command_line, list: displayable_list(@diff[:definition_changed])) puts "" end if @diff.empty? puts I18n.t('actionwords_diff.summary.empty') puts "" end end |
#export_as_json ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 52 def export_as_json @file_writer.write_to_file( "#{@cli_options.output_directory}/actionwords-diff.json", I18n.t('actionwords_diff.exporting_diff_title')) { JSON.pretty_generate(as_api) } end |