Class: Navy::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/navy/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition) ⇒ Configuration

Returns a new instance of Configuration.



7
8
9
10
# File 'lib/navy/configuration.rb', line 7

def initialize(definition)
  @definition = definition
  @apps = parse_apps
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



5
6
7
# File 'lib/navy/configuration.rb', line 5

def definition
  @definition
end

#environmentObject (readonly)

Returns the value of attribute environment.



5
6
7
# File 'lib/navy/configuration.rb', line 5

def environment
  @environment
end

Class Method Details

.from_file(config_file) ⇒ Object



17
18
19
20
# File 'lib/navy/configuration.rb', line 17

def self.from_file(config_file)
  cfg = YAML.load_file(config_file)
  new(cfg)
end

.from_string(yaml_content) ⇒ Object



12
13
14
15
# File 'lib/navy/configuration.rb', line 12

def self.from_string(yaml_content)
  cfg = YAML.load(yaml_content)
  new(cfg)
end

Instance Method Details

#applicationsObject



44
45
46
# File 'lib/navy/configuration.rb', line 44

def applications
  @apps.map &:name
end

#appsObject



22
23
24
25
26
# File 'lib/navy/configuration.rb', line 22

def apps
  @apps.each do |app|
    yield app if block_given?
  end
end

#container_name(app, options = {}) ⇒ Object



37
38
39
40
41
42
# File 'lib/navy/configuration.rb', line 37

def container_name(app, options={})
  mode = options[:mode]
  convoy = options[:convoy]
  scale = options[:scale]
  [convoy, app, mode, scale].compact.join '_'
end

#dependenciesObject



52
53
54
55
56
# File 'lib/navy/configuration.rb', line 52

def dependencies
  @deps.each do |app|
    yield app if block_given?
  end
end

#docker_args(app) ⇒ Object



66
67
68
# File 'lib/navy/configuration.rb', line 66

def docker_args(app)
  @docker_args[app]
end

#find_app(name) ⇒ Object



48
49
50
# File 'lib/navy/configuration.rb', line 48

def find_app(name)
  @apps.detect {|a| a.name == name }
end

#post_tasks(app) ⇒ Object



62
63
64
# File 'lib/navy/configuration.rb', line 62

def post_tasks(app)
  @post[app] || []
end

#pre_tasks(app) ⇒ Object



58
59
60
# File 'lib/navy/configuration.rb', line 58

def pre_tasks(app)
  @pre[app] || []
end

#set_env(env) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/navy/configuration.rb', line 28

def set_env(env)
  @environment = env
  @env = environments[environment] || {}
  @deps = parse_deps
  @pre = parse_pre_tasks
  @post = parse_post_tasks
  @docker_args = parse_docker_args
end