Class: GitHook::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/git_hook/hook.rb

Direct Known Subclasses

GitHook::Hooks::RubySyntaxCheck

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, timing, options) ⇒ Hook

Returns a new instance of Hook.



38
39
40
41
42
# File 'lib/git_hook/hook.rb', line 38

def initialize(repo, timing, options)
  @git = repo
  @timing = timing
  @options = Hashr.new(options).freeze
end

Class Method Details

.class_name(name) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/git_hook/hook.rb', line 17

def self.class_name(name)
  name.sub(/^[a-z]/) { | match |
    match.upcase
  }.gsub(/\-([a-z])/) { | match |
    "::#{$1.to_s.upcase}"
  }.gsub(/_([a-z])/) { | match |
    $1.to_s.upcase
  }
end

.gem_name(name) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/git_hook/hook.rb', line 7

def self.gem_name(name)
  name.sub(/^[A-Z]/) { | match |
    match.downcase
  }.gsub(/::([A-Z])/) { | match |
    "-#{$1.to_s.downcase}"
  }.gsub(/[A-Z]/) { | match |
    "_#{match.downcase}"
  }
end

.resolve(name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/git_hook/hook.rb', line 27

def self.resolve(name)
  name = name.to_s
  if name =~ /^[a-z]/
    { class: class_name(name),
      require: name }
  else
    { class: name,
      require: gem_name(name) }
  end
end

Instance Method Details

#error(msg) ⇒ Object



63
# File 'lib/git_hook/hook.rb', line 63

def error(msg); GitHook.io.error(msg); end

#gitObject



44
45
46
# File 'lib/git_hook/hook.rb', line 44

def git
  @git
end

#info(msg) ⇒ Object



61
# File 'lib/git_hook/hook.rb', line 61

def info(msg); GitHook.io.info(msg); end

#invokeObject



56
57
58
59
# File 'lib/git_hook/hook.rb', line 56

def invoke
  error("This Hook is abstruct class. please override your Hook")
  true
end

#optionsObject



52
53
54
# File 'lib/git_hook/hook.rb', line 52

def options
  @options
end

#timingObject



48
49
50
# File 'lib/git_hook/hook.rb', line 48

def timing
  @timing
end

#warn(msg) ⇒ Object



62
# File 'lib/git_hook/hook.rb', line 62

def warn(msg); GitHook.io.warn(msg); end