lib/builderator/util.rb in builderator-0.3.15 vs lib/builderator/util.rb in builderator-1.0.0.pre.rc.1

- old
+ new

@@ -1,18 +1,50 @@ require 'pathname' module Builderator + ## + # Shared helper methods + ## module Util + GEM_PATH = Pathname.new(__FILE__).join('../../..').expand_path + WORKSPACE = '.builderator'.freeze + VENDOR = 'vendor'.freeze + class << self + ## + # Transform helpers + ## def to_array(arg) arg.is_a?(Array) ? arg : [arg] end def from_tags(aws_tags) {}.tap { |tt| aws_tags.each { |t| tt[t.key.to_s] = t.value } } end + ## + # Relative path from working directory + ## + def relative_path(*relative) + Pathname.pwd.join(*(relative.flatten.map(&:to_s))).expand_path + end + + def workspace(*relative) + relative_path(WORKSPACE, relative) + end + + def vendor(*relative) + workspace(VENDOR, relative) + end + + def source_path(*relative) + GEM_PATH.join(*(relative.flatten.map(&:to_s))).expand_path + end + + ## + # Set-filter helpers + ## def filter(resources, filters = {}) resources.select do |_, r| _filter_reduce(r, filters) end end @@ -23,24 +55,18 @@ end resources end - def region(arg = nil) - return @region || 'us-east-1' if arg.nil? - @region = arg - end - + ## + # AWS Clients + ## def ec2 - @ec2 ||= Aws::EC2::Client.new(:region => region) + @ec2 ||= Aws::EC2::Client.new(:region => Config.aws.region) end def asg - @asg ||= Aws::AutoScaling::Client.new(:region => region) - end - - def working_dir(relative = '.') - Pathname.pwd.join(relative).expand_path + @asg ||= Aws::AutoScaling::Client.new(:region => Config.aws.region) end private def _filter_reduce(resource, filters)