Class: Ufo::Names

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/ufo/names.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNames

Returns a new instance of Names.



6
7
8
# File 'lib/ufo/names.rb', line 6

def initialize
  @role = Ufo.role
end

Instance Attribute Details

#roleObject (readonly)

Returns the value of attribute role.



5
6
7
# File 'lib/ufo/names.rb', line 5

def role
  @role
end

Instance Method Details

#appObject



54
55
56
# File 'lib/ufo/names.rb', line 54

def app
  Ufo.app
end

#awsObject



64
65
66
# File 'lib/ufo/names.rb', line 64

def aws
  AwsData.new
end

#clusterObject



10
11
12
# File 'lib/ufo/names.rb', line 10

def cluster
  expansion(Ufo.config.ecs.cluster) # IE: :ENV => dev
end

#envObject Also known as: ufo_env



58
59
60
# File 'lib/ufo/names.rb', line 58

def env
  Ufo.env
end

#expansion(string, options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ufo/names.rb', line 26

def expansion(string, options={})
  return string unless string.is_a?(String) # in case of nil

  string = string.dup
  vars = string.scan(/:\w+/) # => [":APP", ":ROLE", :ENV"]
  vars.each do |var|
    string.gsub!(var, var_value(var))
  end
  string = strip(string)
  dashes = options[:dasherize].nil? ? true : options[:dasherize]
  string = string.dasherize if dashes
  string
end

#stackObject



15
16
17
18
# File 'lib/ufo/names.rb', line 15

def stack
  name = expansion(Ufo.config.names.stack) # IE: :APP-:ROLE-:ENV => demo-web-dev
  [name, Ufo.extra].compact.join('-')
end

#strip(string) ⇒ Object



49
50
51
52
# File 'lib/ufo/names.rb', line 49

def strip(string)
  string.sub(/^-+/,'').sub(/-+$/,'') # remove leading and trailing -
        .gsub(%r{-+},'-') # remove double dashes are more. IE: -- => -
end

#task_definitionObject



21
22
23
# File 'lib/ufo/names.rb', line 21

def task_definition
  expansion(Ufo.config.names.task_definition) # IE: :APP-:ROLE-:ENV => demo-web-dev
end

#var_value(unexpanded) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/ufo/names.rb', line 40

def var_value(unexpanded)
  name = unexpanded.sub(':','').downcase
  if respond_to?(name)
    send(name).to_s # pass value straight through
  else
    unexpanded
  end
end