Class: Kondate::HostPlugin::File

Inherits:
Base
  • Object
show all
Defined in:
lib/kondate/host_plugin/file.rb

Overview

YAML format

host1: [role1, role2] host2: [role1, role2]

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ File

Returns a new instance of File.

Parameters:

  • config (HashWithIndifferentAccess)

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kondate/host_plugin/file.rb', line 11

def initialize(config)
  super
  raise ConfigError.new('file: path is not configured') unless config.path
  @path = config.path

  @roles_of_host = YAML.load_file(@path)
  @hosts_of_role = {}
  @roles_of_host.each do |host, roles|
    roles.each do |role|
      @hosts_of_role[role] ||= []
      @hosts_of_role[role] << host
    end
  end
end

Instance Method Details

#get_environment(host) ⇒ String

Returns environment name.

Parameters:

  • host (String)

    hostname

Returns:

  • (String)

    environment name



28
29
30
# File 'lib/kondate/host_plugin/file.rb', line 28

def get_environment(host)
  ENV['ENVIRONMENT'] || 'development'
end

#get_hosts(role) ⇒ Array

Available from kondate >= 0.3.0

Parameters:

  • role (String)

    role

Returns:

  • (Array)

    array of hosts



42
43
44
# File 'lib/kondate/host_plugin/file.rb', line 42

def get_hosts(role)
  @hosts_of_role[role]
end

#get_roles(host) ⇒ Array

Returns array of roles.

Parameters:

  • host (String)

    hostname

Returns:

  • (Array)

    array of roles



34
35
36
# File 'lib/kondate/host_plugin/file.rb', line 34

def get_roles(host)
  @roles_of_host[host]
end