Class: Automan::Base

Inherits:
Object
  • Object
show all
Includes:
Mixins::AwsCaller
Defined in:
lib/automan/base.rb

Constant Summary

Constants included from Mixins::AwsCaller

Mixins::AwsCaller::S3_PROTO

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes included from Mixins::AwsCaller

#as, #cfn, #eb, #ec, #ec2, #elb, #r53, #rds, #s3

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::AwsCaller

#account, #configure_aws, #looks_like_s3_path?, #parse_s3_path, #s3_object_exists?, #s3_read

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/automan/base.rb', line 15

def initialize(options={})
  $stdout.sync = true
  @logger = Logger.new(STDOUT)

  if !options.nil?
    options.each_pair do |k,v|
      accessor = (k.to_s + '=').to_sym
      send(accessor, v) if respond_to? accessor
    end
  end

  aws_options = {}
  if options[:log_aws]
    aws_options[:logger] = @logger
  end
  configure_aws(aws_options)
end

Class Attribute Details

.option_namesObject

Returns the value of attribute option_names.



8
9
10
# File 'lib/automan/base.rb', line 8

def option_names
  @option_names
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



11
12
13
# File 'lib/automan/base.rb', line 11

def logger
  @logger
end

#waitObject

Returns the value of attribute wait.



11
12
13
# File 'lib/automan/base.rb', line 11

def wait
  @wait
end

Class Method Details

.add_option(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/automan/base.rb', line 33

def self.add_option(*args)
  args.each do |arg|
    self.class_eval("def #{arg};@#{arg};end")
    self.class_eval("def #{arg}=(val);@#{arg}=val;end")
    if self.option_names.nil?
      self.option_names = []
    end
    self.option_names << arg
  end
end

Instance Method Details

#log_optionsObject



44
45
46
47
48
49
50
51
52
# File 'lib/automan/base.rb', line 44

def log_options
  biggest_opt_name_length = self.class.option_names.max_by(&:length).length
  message = "called with:\n"
  self.class.option_names.each do |opt|
    opt_name = opt.to_s.concat(':').ljust(biggest_opt_name_length)
    message += "#{opt_name} #{send(opt)}\n"
  end
  logger.info message
end

#wait_until(raise_on_fail = nil, &block) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/automan/base.rb', line 54

def wait_until(raise_on_fail=nil, &block)
  begin
    wait.until do
      yield
    end
  rescue Wait::ResultInvalid => e
    if raise_on_fail.nil?
      raise e
    else
      raise raise_on_fail
    end
  end
end