Class: Heidi::Hook

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build, script) ⇒ Hook

Returns a new instance of Hook.



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

def initialize(build, script)
  @build  = build
  @script = script
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



5
6
7
# File 'lib/heidi/hook.rb', line 5

def build
  @build
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/heidi/hook.rb', line 54

def failed?
  @res.S?.to_i != 0
rescue
  false
end

#messageObject



38
39
40
41
42
43
44
# File 'lib/heidi/hook.rb', line 38

def message
  @res.err.empty? ?
    @res.out.empty? ?
      "No error message given" :
      @res.out :
  @res.err
end

#nameObject



60
61
62
# File 'lib/heidi/hook.rb', line 60

def name
  File.join(File.basename(File.dirname(@script)), File.basename(@script))
end

#outputObject



46
47
48
49
50
51
52
# File 'lib/heidi/hook.rb', line 46

def output
  @res.out.empty? ?
    @res.err.empty? ?
      "No output" :
      @res.err :
  @res.out
end

#perform(where = build.build_root) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/heidi/hook.rb', line 11

def perform(where=build.build_root)
  # before / failure hooks might like this
  if !File.exists?(where)
    where = build.root
  end

  start = Time.now
  env = {
    'HEIDI_DIR'          => build.project.root,
    'HEIDI_LOG_DIR'      => build.log_root,
    'HEIDI_BUILD_DIR'    => where,
    'HEIDI_BUILD_COMMIT' => build.commit,
    'HEIDI_BRANCH'       => build.project.branch,

    'RUBYOPT'         => nil,
    'BUNDLE_BIN_PATH' => nil,
    'BUNDLE_GEMFILE'  => nil,
    'GEM_HOME'        => nil,
    'GEM_PATH'        => nil,
  }

  shell = SimpleShell.new(where, env)
  @res = shell.do @script

  return @res
end