Class: Placer

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Placer

Returns a new instance of Placer.



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

def initialize(args)
  @args, @params = parse_options(args)
  @logger = @params[:log] ? MyLogger.new : MyLogger.new(:all)
end

Instance Method Details

#parse_options(args) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/placer.rb', line 28

def parse_options(args)
  opts = OptionParser.new
  params = {}

  banner = <<BANNER
placer - a simpler deployment
deployment back to the basics

If you have no config, just start off by the example in the repo/placer.yaml.
In case you are wondering, public/private key auth is the only way.
We don't support manual solutions. This tool is thought for automated use.

Usage: placer [options]
BANNER

  opts.banner = banner

  params[:log] = true
  opts.on('-q', '--[no-]log', 'toggle logging') do |val|
    params[:log] = val
  end

  params[:config_path] = 'placer.rb'
  opts.on('-c', '--config FILE', 'path to config FILE to use default: ' << params[:config_path]) do |file|
    params[:config_path] = file
  end

  params[:debug] = false
  opts.on('--debug', 'enable debugging') do
    params[:debug] = true
  end

  opts.on_tail('-h', '--help', 'shows this message') do
    puts opts
    exit
  end

  args = opts.parse(args)

  [args, params]
end

#runObject



24
25
26
# File 'lib/placer.rb', line 24

def run
  PlacerDSL.new(File.read(@params[:config_path]), @logger)
end

#startObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/placer.rb', line 11

def start
  @logger.log(:info, "Loading config file #{@params[:config_path]}")
  if @params[:debug]
    run
  else
    begin
      run
    rescue => e
      @logger.log(:error, e)
    end
  end
end