Class: Hiptest::DiffDisplayer

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

Instance Method Summary collapse

Constructor Details

#initialize(diff, cli_options, language_config, file_writer) ⇒ DiffDisplayer

Returns a new instance of DiffDisplayer.



3
4
5
6
7
8
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 3

def initialize(diff, cli_options, language_config, file_writer)
  @diff = diff
  @cli_options = cli_options
  @language_config = language_config
  @file_writer = file_writer
end

Instance Method Details

#as_apiObject



62
63
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
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 62

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

#displayObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 10

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_jsonObject



58
59
60
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 58

def display_as_json
  output(JSON.pretty_generate(as_api))
end

#display_createdObject



22
23
24
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 22

def display_created
  return display_skeletons(@diff[:created])
end

#display_definition_changedObject



38
39
40
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 38

def display_definition_changed
  display_skeletons(@diff[:definition_changed])
end

#display_deletedObject



42
43
44
45
46
47
48
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 42

def display_deleted
  return if @diff[:deleted].nil?

  output(@diff[:deleted].map {|deleted|
    @language_config.name_action_word(deleted[:name])
  })
end

#display_renamedObject



26
27
28
29
30
31
32
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 26

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_changedObject



34
35
36
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 34

def display_signature_changed
  display_skeletons(@diff[:signature_changed])
end

#display_summaryObject



105
106
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
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 105

def display_summary
  command_line = @cli_options.command_line_used(exclude: [:actionwords_diff])

  unless @diff[:deleted].nil?
    output([
      "#{pluralize(@diff[:deleted].length, "action word")} deleted,",
      "run '#{command_line} --show-actionwords-deleted' to list the #{pluralize_word(@diff[:deleted].length, "name")} in the code",
      displayable_list(@diff[:deleted])
    ])
  end

  unless @diff[:created].nil?
    output([
      "#{pluralize(@diff[:created].length, "action word")} created,",
      "run '#{command_line} --show-actionwords-created' to get the #{pluralize_word(@diff[:created].length, "definition")}",
      displayable_list(@diff[:created])
    ])
  end

  unless @diff[:renamed].nil?
    output([
      "#{pluralize(@diff[:renamed].length, "action word")} renamed,",
      "run '#{command_line} --show-actionwords-renamed' to get the new #{pluralize_word(@diff[:renamed].length, "name")}",
      displayable_list(@diff[:renamed])
    ])
  end

  unless @diff[:signature_changed].nil?
    output([
      "#{pluralize(@diff[:signature_changed].length, "action word")} which signature changed,",
      "run '#{command_line} --show-actionwords-signature-changed' to get the new #{pluralize_word(@diff[:signature_changed].length, "signature")}",
      displayable_list(@diff[:signature_changed])
    ])
  end

  unless @diff[:definition_changed].nil?
    output([
      "#{pluralize(@diff[:definition_changed].length, "action word")} which definition changed:",
      "run '#{command_line} --show-actionwords-definition-changed' to get the new #{pluralize_word(@diff[:definition_changed].length, "definition")}",
      displayable_list(@diff[:definition_changed])
    ])
  end

  if @diff.empty?
    output("No action words changed")
  end
end

#export_as_jsonObject



50
51
52
53
54
55
56
# File 'lib/hiptest-publisher/formatters/diff_displayer.rb', line 50

def export_as_json
  @file_writer.write_to_file(
    "#{@cli_options.output_directory}/actionwords-diff.json",
    "Exporting actionwords diff") {
    JSON.pretty_generate(as_api)
  }
end