Class: Bringit::Hook

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

Constant Summary collapse

GL_PROTOCOL =
'web'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, repo_path) ⇒ Hook

Returns a new instance of Hook.



8
9
10
11
12
# File 'lib/bringit/hook.rb', line 8

def initialize(name, repo_path)
  @name = name
  @repo_path = repo_path
  @path = File.join(repo_path.strip, 'hooks', name)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/bringit/hook.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/bringit/hook.rb', line 6

def path
  @path
end

#repo_pathObject (readonly)

Returns the value of attribute repo_path.



6
7
8
# File 'lib/bringit/hook.rb', line 6

def repo_path
  @repo_path
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/bringit/hook.rb', line 14

def exists?
  File.exist?(path)
end

#trigger(user_id, oldrev, newrev, ref) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bringit/hook.rb', line 18

def trigger(user_id, oldrev, newrev, ref)
  return [true, nil] unless exists?

  Bundler.with_clean_env do
    case name
    when "pre-receive", "post-receive"
      call_receive_hook(user_id, oldrev, newrev, ref)
    when "update"
      call_update_hook(user_id, oldrev, newrev, ref)
    end
  end
end