Class: Assh::Provider

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

Direct Known Subclasses

AwsProvider, FileProvider, RandomProvider

Constant Summary collapse

@@verbose =
false

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Provider

Returns a new instance of Provider.



9
10
11
# File 'lib/provider.rb', line 9

def initialize(configuration)
  @configuration = configuration
end

Class Method Details

.load_configuration!(configuration, file) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/provider.rb', line 13

def self.load_configuration!(configuration, file)
  status "Loading: #{file}"

  config = YAML::load_file(File.expand_path(file, Assh::ROOT))

  includes = config.delete(Assh::FileProvider::INCLUDES_KEY) || []

  provider_name = (config.delete('Provider') || 'file').downcase
  provider_class = @@providers[provider_name]
  raise "Provider not found: #{provider_name}" unless provider_class

  provider = provider_class.new(configuration)
  provider.parse_config!(config)

  includes.each do |inc|
    Provider.load_configuration!(configuration, File.expand_path(inc, ROOT))
  end

  provider
end

.register_provider!(name, clazz) ⇒ Object



55
56
57
# File 'lib/provider.rb', line 55

def self.register_provider!(name, clazz)
  @@providers[name] = clazz
end

.status(message = "", inline = false) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/provider.rb', line 42

def self.status(message = "", inline = false)
  return unless @@verbose
  if inline
    print message
  else
    puts message
  end
end

.verbose!Object



51
52
53
# File 'lib/provider.rb', line 51

def self.verbose!
  @@verbose = true
end

Instance Method Details

#add_host(group_name, host_name, host) ⇒ Object



38
39
40
# File 'lib/provider.rb', line 38

def add_host(group_name, host_name, host)
  @configuration.add_host(group_name, host_name, host)
end

#parse_config!(config) ⇒ Object



34
35
36
# File 'lib/provider.rb', line 34

def parse_config!(config)
  raise 'parse_config! must be overridden'
end