Class: Ufo::Names

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Includes:
Config::CallableOption::Concern, TaskDefinition::Helpers::AwsHelper
Defined in:
lib/ufo/names.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Config::CallableOption::Concern

#callable_option

Methods included from TaskDefinition::Helpers::AwsHelper

#aws

Constructor Details

#initializeNames

Returns a new instance of Names.



8
9
10
# File 'lib/ufo/names.rb', line 8

def initialize
  @role = Ufo.role
end

Instance Attribute Details

#roleObject (readonly)

Returns the value of attribute role.



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

def role
  @role
end

Instance Method Details

#appObject



73
74
75
# File 'lib/ufo/names.rb', line 73

def app
  Ufo.app
end

#clusterObject



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

def cluster
  string = callable_option(
    config_name: "ecs.cluster", # Ufo.ecs.cluster => :ENV => dev
    passed_args: [self],
  )
  expansion(string) # IE: :ENV => dev
end

#envObject Also known as: ufo_env



77
78
79
# File 'lib/ufo/names.rb', line 77

def env
  Ufo.env
end

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



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ufo/names.rb', line 45

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", ":EXTRA"]
  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

#extraObject



82
83
84
# File 'lib/ufo/names.rb', line 82

def extra
  Ufo.extra
end

#stackObject

Examples: When UFO_EXTRA not set: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev When UFO_EXTRA=1: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev-2



24
25
26
27
28
29
30
# File 'lib/ufo/names.rb', line 24

def stack
  string = callable_option(
    config_name: "names.stack", # Ufo.config.names.stack => :APP-:ROLE-:ENV => demo-web-dev
    passed_args: [self],
  )
  expansion(string) # IE: :APP-:ROLE-:ENV => demo-web-dev
end

#strip(string) ⇒ Object



68
69
70
71
# File 'lib/ufo/names.rb', line 68

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

#task_definitionObject

Examples: When UFO_EXTRA not set: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev When UFO_EXTRA=1: :APP-:ROLE-:ENV-:EXTRA => demo-web-dev-2



36
37
38
39
40
41
42
# File 'lib/ufo/names.rb', line 36

def task_definition
  string = callable_option(
    config_name: "names.task_definition", # Ufo.config.names.task_definition => :APP-:ROLE-:ENV => demo-web-dev
    passed_args: [self],
  )
  expansion(string) # IE: :APP-:ROLE-:ENV => demo-web-dev
end

#var_value(unexpanded) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/ufo/names.rb', line 59

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