Class: CaptainHoog::PreGit

Inherits:
Object
  • Object
show all
Defined in:
lib/captain_hoog/pre_git.rb

Overview

Public: Entry class for handling a Pre-Something with plugins.

Defined Under Namespace

Modules: PluginDirs

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugins_list = nil) ⇒ PreGit

Returns a new instance of PreGit.



51
52
53
54
55
# File 'lib/captain_hoog/pre_git.rb', line 51

def initialize(plugins_list = nil)
  @plugins      = []
  @plugins_list = plugins_list
  prepare_plugins
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Public: Configures the hook by calling the class’ accessors.

Returns nothing.

Yields:

  • (_self)

Yield Parameters:



41
42
43
# File 'lib/captain_hoog/pre_git.rb', line 41

def self.configure
  yield(self) if block_given?
end

.plugins_dir=(plugins_dir) ⇒ Object



45
46
47
48
49
# File 'lib/captain_hoog/pre_git.rb', line 45

def self.plugins_dir=(plugins_dir)
  @plugins_dir = []
  PluginDirs.collect(@plugins_dir)
  (@plugins_dir << plugins_dir).flatten!
end

.run(plugins_list: nil) ⇒ Object

Public: Runs the hook.

Inits a new instance of self and evaluates the plugins (if found some)

Returns an instance of self (CaptainHoog::PreGit)



32
33
34
35
36
# File 'lib/captain_hoog/pre_git.rb', line 32

def self.run(plugins_list: nil)
  pre_git = self.new(plugins_list)
  pre_git.plugins_eval
  pre_git
end

Instance Method Details

#plugins_evalObject

Public: Evaluates all plugins that are found in plugins_dir.

If any plugin contains a test that returns false (means it fails) it displays the plugins failure messages and exits with code 1



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/captain_hoog/pre_git.rb', line 62

def plugins_eval
  raw_results = available_plugins.inject([]) do |result, plugin|
    result << plugin.execute
  end
  @results = raw_results.select{ |result| result.is_a?(Hash) }
  tests    = @results.map{ |result| result[:result] }
  if tests.any?{ |test| not test }
    message_on_failure
    exit 1 unless ENV["PREGIT_ENV"] == "test"
  else
    message_on_success
    exit 0 unless ENV["PREGIT_ENV"] == "test"
  end
end