Class: Cupper::Collect

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

Constant Summary collapse

ADDITIONAL_OHAI_PLUGINS =
[
  'packages',
  'platform_family',
  'etc'
]

Instance Method Summary collapse

Constructor Details

#initializeCollect

Returns a new instance of Collect.



12
13
14
15
16
17
18
19
20
# File 'lib/cupper/collect.rb', line 12

def initialize
  @data_extraction = Hash.new('No data!')
  @ohai = Ohai::System.new
  @ohai_plugin = OhaiPlugin.new

  # TODO: Ohai::Config[:plugin_path] is decrepted
  @plugins_path = Cupper::OHAI_PLUGINS_PATH
  Ohai::Config[:plugin_path] << @plugins_path
end

Instance Method Details

#dataObject



47
48
49
# File 'lib/cupper/collect.rb', line 47

def data
  @data_extraction
end

#extract(attribute) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/cupper/collect.rb', line 22

def extract(attribute)
  begin
    object = 'Cupper::'.concat self.platform.capitalize
    platform = Object.const_get(object).new
    extract = platform.method attribute
    extract.call @data_extraction
  rescue NameError
    puts 'Not supported platform' # TODO: treat this better
  end
end

#platformObject



43
44
45
# File 'lib/cupper/collect.rb', line 43

def platform
  @data_extraction['platform_family']['platform_family']
end

#setupObject



33
34
35
36
37
38
39
40
41
# File 'lib/cupper/collect.rb', line 33

def setup
  plugins = @ohai_plugin.list
  plugins.concat ADDITIONAL_OHAI_PLUGINS
  plugins.each do |plugin|
    extract = @ohai.all_plugins(plugin)
    @data_extraction.update({ plugin => extract.first.data }) # Assuming that the first is the default plugin extractor
  end
  true
end