Class: Gitdocs::GitNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/gitdocs/git_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, show_notifications) ⇒ GitNotifier

Returns a new instance of GitNotifier.

Parameters:

  • root (String)
  • show_notifications (Boolean)


8
9
10
11
# File 'lib/gitdocs/git_notifier.rb', line 8

def initialize(root, show_notifications)
  @root               = root
  @show_notifications = show_notifications
end

Instance Method Details

#for_merge(result) ⇒ void

This method returns an undefined value.

Parameters:

  • result (nil, Symbol, Array<String>, Hash<String => Integer>, #to_s)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gitdocs/git_notifier.rb', line 16

def for_merge(result)
  return if result.nil?
  return if result == :no_remote
  return if result == :ok
  return if result == {}

  if result.is_a?(Array)
    Notifier.warn(
      'There were some conflicts',
      result.map { |f| "* #{f}" }.join("\n"),
      @show_notifications
    )
  elsif result.is_a?(Hash)
    Notifier.info(
      "Updated with #{change_to_s(result)}",
      "In #{@root}:\n#{author_list(result)}",
      @show_notifications
    )
  else
    Notifier.error(
      'There was a problem synchronizing this gitdoc',
      "A problem occurred in #{@root}:\n#{result}",
      @show_notifications
    )
  end
  nil
end

#for_push(result) ⇒ void

This method returns an undefined value.

Parameters:

  • result (nil, Symbol, Hash<String => Integer>, #to_s)

    of push



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/gitdocs/git_notifier.rb', line 47

def for_push(result)
  return if result.nil?
  return if result == :no_remote
  return if result == :nothing

  if result == :conflict
    Notifier.warn(
      "There was a conflict in #{@root}, retrying",
      '',
      @show_notifications
    )
  elsif result.is_a?(Hash)
    Notifier.info(
      "Pushed #{change_to_s(result)}",
      "#{@root} has been pushed",
      @show_notifications
    )
  else
    Notifier.error(
      "BAD Could not push changes in #{@root}",
      result.to_s,
      @show_notifications
    )
  end
  nil
end

#on_error(exception) ⇒ void

This method returns an undefined value.

Parameters:

  • exception (Exception)


77
78
79
80
81
82
83
84
# File 'lib/gitdocs/git_notifier.rb', line 77

def on_error(exception)
  Notifier.error(
    "Unexpected error when fetching/pushing in #{@root}",
    exception.to_s,
    @show_notifications
  )
  nil
end