Module: Naplug::InstanceMethods

Defined in:
lib/naplug.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



142
143
144
145
146
147
148
149
150
# File 'lib/naplug.rb', line 142

def method_missing(method, *args, &block)
  message = "undefined instance variable or method #{method}"
  case @_runinng
    when nil?
      begin; raise Naplug::Error, message; rescue => e; eject! e ; end
    else
      raise Naplug::Error, message
  end
end

Instance Attribute Details

#pluginsObject (readonly)

Returns the value of attribute plugins.



35
36
37
# File 'lib/naplug.rb', line 35

def plugins
  @plugins
end

Instance Method Details

#argsObject



45
46
47
# File 'lib/naplug.rb', line 45

def args
  @_args
end

#args!(args) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/naplug.rb', line 49

def args!(args)
  @_args.merge! args
  @plugins.each do |tag,plugin|
    plugin_args = args.key?(tag) ? args[tag] : {}
    shared_args = args.select { |t,a| not @plugins.keys.include? t }
    plugin.args! shared_args.merge! plugin_args
  end
end

#eject!(payload = nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/naplug.rb', line 78

def eject!(payload = nil)
  o = case payload
        when String then payload
        when Exception then "#{payload.backtrace[1][/.+:\d+/]}: #{payload.message}"
        else nil
          caller[0][/.+:\d+/]
      end
  print "UNKNOWN: plugin eject! in %s\n" % [o]
  Kernel::exit 3
end

#eval(tag = default_plugin.tag) ⇒ Object



74
75
76
# File 'lib/naplug.rb', line 74

def eval(tag = default_plugin.tag)
  @plugins[tag].eval
end

#exec(tag = default_plugin.tag) ⇒ Object



70
71
72
# File 'lib/naplug.rb', line 70

def exec(tag = default_plugin.tag)
  rexec @plugins[tag]
end

#exec!(tag = default_plugin.tag) ⇒ Object



64
65
66
67
68
# File 'lib/naplug.rb', line 64

def exec!(tag = default_plugin.tag)
  exec tag
  eval tag
  exit tag
end

#initialize(args = {}) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/naplug.rb', line 37

def initialize(args = {})
  @plugins = Hash.new
  plugins!

  @_args = Hash.new
  args! args
end

#to_str(tag = default_plugin.tag) ⇒ Object



58
59
60
61
62
# File 'lib/naplug.rb', line 58

def to_str(tag = default_plugin.tag)
  s_format = perfdata(tag) ? '%s: %s | %s' : '%s: %s'
  s_array = perfdata(tag) ? [@plugins[tag].status,@plugins[tag].output,perfdata(tag)] : [@plugins[tag].status,@plugins[tag].output]
  s_format % s_array
end