Module: Builderator::Util

Defined in:
lib/builderator/util.rb,
lib/builderator/util/aws_exception.rb,
lib/builderator/util/task_exception.rb,
lib/builderator/util/limit_exception.rb

Overview

Shared helper methods

Defined Under Namespace

Classes: AwsException, LimitException, TaskException

Constant Summary collapse

GEM_PATH =
Pathname.new(__FILE__).join('../../..').expand_path
WORKSPACE =
'.builderator'.freeze
VENDOR =
'vendor'.freeze

Class Method Summary collapse

Class Method Details

.asg(region = Config.aws.region) ⇒ Object



67
68
69
# File 'lib/builderator/util.rb', line 67

def asg(region = Config.aws.region)
  clients["asg-#{region}"] ||= Aws::AutoScaling::Client.new(:region => region)
end

.ec2(region = Config.aws.region) ⇒ Object

AWS Clients



63
64
65
# File 'lib/builderator/util.rb', line 63

def ec2(region = Config.aws.region)
  clients["ec2-#{region}"] ||= Aws::EC2::Client.new(:region => region)
end

.filter(resources, filters = {}) ⇒ Object

Set-filter helpers



46
47
48
49
50
# File 'lib/builderator/util.rb', line 46

def filter(resources, filters = {})
  resources.select do |_, r|
    _filter_reduce(r, filters)
  end
end

.filter!(resources, filters = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/builderator/util.rb', line 52

def filter!(resources, filters = {})
  resources.select! do |_, r|
    _filter_reduce(r, filters)
  end

  resources
end

.from_tags(aws_tags) ⇒ Object



20
21
22
# File 'lib/builderator/util.rb', line 20

def from_tags(aws_tags)
  {}.tap { |tt| aws_tags.each { |t| tt[t.key.to_s] = t.value } }
end

.relative_path(*relative) ⇒ Object

Relative path from working directory



27
28
29
# File 'lib/builderator/util.rb', line 27

def relative_path(*relative)
  Pathname.pwd.join(*(relative.flatten.map(&:to_s))).expand_path
end

.source_path(*relative) ⇒ Object



39
40
41
# File 'lib/builderator/util.rb', line 39

def source_path(*relative)
  GEM_PATH.join(*(relative.flatten.map(&:to_s))).expand_path
end

.to_array(arg) ⇒ Object

Transform helpers



16
17
18
# File 'lib/builderator/util.rb', line 16

def to_array(arg)
  arg.is_a?(Array) ? arg : [arg]
end

.vendor(*relative) ⇒ Object



35
36
37
# File 'lib/builderator/util.rb', line 35

def vendor(*relative)
  workspace(VENDOR, relative)
end

.workspace(*relative) ⇒ Object



31
32
33
# File 'lib/builderator/util.rb', line 31

def workspace(*relative)
  relative_path(WORKSPACE, relative)
end