class GitHooks::Section

Attributes

benchmark[R]
hook[R]
name[R]
success[R]
success?[R]
title[R]

Public Class Methods

key_from_name(name) click to toggle source
# File lib/githooks/section.rb, line 30
def key_from_name(name)
  name.to_s.underscore.to_sym
end
new(name, hook, &block) click to toggle source
# File lib/githooks/section.rb, line 35
def initialize(name, hook, &block)
  @name      = name.to_s.titleize
  @success   = true
  @actions   = []
  @limiters  = {}
  @hook      = hook
  @benchmark = 0

  instance_eval(&block)

  waiting!
end

Public Instance Methods

<<(action) click to toggle source
# File lib/githooks/section.rb, line 59
def <<(action)
  @actions << action
end
__getobj__()
Alias for: actions
action(title, &block) click to toggle source
# File lib/githooks/section.rb, line 135
def action(title, &block)
  fail ArgumentError, 'expected block, received none' unless block_given?
  @actions << Action.new(title, self, &block)
  self
end
actions() click to toggle source

overrides previous action method to only return actions that have a non-empty manifest

# File lib/githooks/section.rb, line 54
def actions
  @actions.reject { |action| action.manifest.empty? }
end
Also aliased as: __getobj__
colored_name(phase = GitHooks::HOOK_NAME) click to toggle source
# File lib/githooks/section.rb, line 80
def colored_name(phase = GitHooks::HOOK_NAME)
  title = name(phase)
  return title.color_skipped! if @actions.all?(&:skipped?)
  return title.color_unknown! unless completed?
  return title.color_failure! unless success?
  title.color_success!
end
completed?() click to toggle source
# File lib/githooks/section.rb, line 68
def completed?
  finished? && @actions.all?(&:finished?)
end
config_file(*path_components) click to toggle source
# File lib/githooks/section.rb, line 116
def config_file(*path_components)
  config_path.join(*path_components)
end
config_path() click to toggle source

FIXME: these should be switched to behaviors that are included into this classs

# File lib/githooks/section.rb, line 112
def config_path
  GitHooks.hooks_root.join('configs')
end
key_name() click to toggle source
# File lib/githooks/section.rb, line 88
def key_name
  self.class.key_from_name(@name)
end
lib_file(*path_components) click to toggle source
# File lib/githooks/section.rb, line 124
def lib_file(*path_components)
  lib_path.join(*path_components)
end
lib_path() click to toggle source
# File lib/githooks/section.rb, line 120
def lib_path
  GitHooks.hooks_root.join('lib')
end
limit(type) click to toggle source
# File lib/githooks/section.rb, line 128
def limit(type)
  unless @limiters.include? type
    @limiters[type] ||= Repository::Limiter.new(type)
  end
  @limiters[type]
end
limiters() click to toggle source
# File lib/githooks/section.rb, line 48
def limiters
  hook.limiters.merge(@limiters)
end
run() click to toggle source
# File lib/githooks/section.rb, line 92
def run
  running!
  begin
    time_start = Time.now
    actions.collect { |action|
      @success &= action.run.tap { |r|
        STDERR.puts "#{action.title} -> #{r.inspect}" if GitHooks.debug?
      }
    }.all?
  ensure
    @benchmark = Time.now - time_start
    finished!
  end
end
wait_count() click to toggle source
# File lib/githooks/section.rb, line 72
def wait_count
  @actions.count(&:waiting?)
end