Class: ES::Diag::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/es-diag/context.rb

Instance Method Summary collapse

Constructor Details

#initialize(ui) ⇒ Context

Returns a new instance of Context.



7
8
9
# File 'lib/es-diag/context.rb', line 7

def initialize(ui)
  @ui=ui
end

Instance Method Details

#all_contextsObject



41
42
43
44
45
# File 'lib/es-diag/context.rb', line 41

def all_contexts
  Dir[File.expand_path('../contexts/*.rb', File.dirname(__FILE__))].each do |fcheck|
    run_context(fcheck)
  end
end

#context(k, v) ⇒ Object



23
24
25
# File 'lib/es-diag/context.rb', line 23

def context(k,v)
  @run_context[:context] = {:key => k, :val => v} 
end

#dataObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/es-diag/context.rb', line 27

def data
  unless @ohai
    @ui.info("Collecting system information...")
    Ohai::Config[:plugin_path] << File.expand_path('../ohai_plugins', File.dirname(__FILE__))
    @ohai = Ohai::System.new
    @ohai.all_plugins

    #enrich base data
    @ui.info("Collecting extra information...")
    all_contexts
  end
  @ohai
end

#error(text) ⇒ Object



15
16
17
# File 'lib/es-diag/context.rb', line 15

def error(text)
  @ui.warn "[#{@run_context[:title]}] #{text}"
end

#run_context(filename) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/es-diag/context.rb', line 47

def run_context(filename)
  @run_context = {}
  self.instance_eval(IO.read(filename), filename, 1)
  if @run_context[:context]
    data[@run_context[:context][:key]] = Hashie::Mash.new @run_context[:context][:val]
  else
    warn "No real data fetched. Watch output for errors."
  end
end

#title(text) ⇒ Object



19
20
21
# File 'lib/es-diag/context.rb', line 19

def title(text)
  @run_context[:title] = text
end

#warn(text) ⇒ Object



11
12
13
# File 'lib/es-diag/context.rb', line 11

def warn(text)
  @ui.warn "[#{@run_context[:title]}] #{text}"
end