Module: Hudkins::Command::Exec

Included in:
Hudkins::Command
Defined in:
lib/hudkins/command/exec.rb

Overview

Description

mixin for interacting with the lib

the bin is setup to run any command prefaced with ‘run_’ each command should return something to be puts or nil

Instance Method Summary collapse

Instance Method Details

#cmd_listObject



77
78
79
# File 'lib/hudkins/command/exec.rb', line 77

def cmd_list
  command_list.map {|m| m.gsub(/^run_/, '')}
end

#command_listObject



81
82
83
# File 'lib/hudkins/command/exec.rb', line 81

def command_list
  self.methods.select {|m| m =~ /^run_/}
end

#configObject



93
94
95
# File 'lib/hudkins/command/exec.rb', line 93

def config
  @config ||= load_rc
end

#hudObject

helper commands



55
56
57
# File 'lib/hudkins/command/exec.rb', line 55

def hud
  @hud
end

#hud_hostObject



89
90
91
# File 'lib/hudkins/command/exec.rb', line 89

def hud_host
  ENV["hudkins_host"] || config[:host] || raise_usage( "no hudkins_host defined." )
end

#hudkins_rcObject



105
106
107
108
109
110
# File 'lib/hudkins/command/exec.rb', line 105

def hudkins_rc
  [
    File.expand_path("~/.hudkinsrc"),
    File.join(Dir.pwd, ".hudkinsrc")
  ].select {|f| File.size? f} # exists and is non 0
end

#job(job_name = nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/hudkins/command/exec.rb', line 59

def job job_name = nil
  if job_name
    @job = hud.jobs.find_by_name job_name
  end
  @job
end

#load_rcObject



97
98
99
100
101
102
103
# File 'lib/hudkins/command/exec.rb', line 97

def load_rc
  hudkins_rc.inject({}) do |ret, rc|
    h = YAML.load_file( rc )
    ret.merge! h if h
    ret
  end
end

#names(name = "") ⇒ Object



85
86
87
# File 'lib/hudkins/command/exec.rb', line 85

def names name = ""
  hud.jobs.names name
end

#required_params(values) ⇒ Object

could probably be cleaned up



67
68
69
70
71
72
73
74
75
# File 'lib/hudkins/command/exec.rb', line 67

def required_params values
  e = Hudkins::ArgumentError.new ""
  raize = false
  values.each do |k,msg|
    e << msg unless k
    raize = true unless k
  end
  raise e if raize
end

#run_buildObject



14
15
16
# File 'lib/hudkins/command/exec.rb', line 14

def run_build
  "building!!!"
end

#run_config(job_name = @job_name) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/hudkins/command/exec.rb', line 18

def run_config job_name = @job_name
  required_params job_name => "job_name is required for this command."
  [
    job( job_name ).name,
    job( job_name ).config
  ]
end

#run_create(job_name = @job_name) ⇒ Object



26
27
28
29
# File 'lib/hudkins/command/exec.rb', line 26

def run_create job_name = @job_name
  required_params job_name => "job_name is required for this command."
  "creating!!!"
end

#run_defaultObject

default command. here as a place holder



11
12
# File 'lib/hudkins/command/exec.rb', line 11

def run_default
end

#run_hostObject



31
32
33
# File 'lib/hudkins/command/exec.rb', line 31

def run_host
  hud_host
end

#run_list(job_name = @job_name) ⇒ Object



35
36
37
# File 'lib/hudkins/command/exec.rb', line 35

def run_list job_name = @job_name
  names( job_name || "" )
end

#run_start_irbObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/hudkins/command/exec.rb', line 39

def run_start_irb
  puts <<-EOS

  ---
  Welcome to hudkins irb console.
  type hudkins for help.

  EOS
  require "hudkins/command/irb_start"
  # turn job names into methods
  extend Hudkins::Command::Irb
  IRB.start_session(nil, binding)
end