Class: Nagios::Base

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/puppet/external/nagios/base.rb

Overview

The base class for all of our Nagios object types. Everything else is mostly just data.

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mname, *args) ⇒ Object

Handle parameters like attributes.



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/puppet/external/nagios/base.rb', line 205

def method_missing(mname, *args)
  pname = mname.to_s
  pname.sub!(/=/, '')

  if self.class.parameter?(pname)
    if pname =~ /A-Z/
      pname = self.class.decamelcase(pname)
    end
    self.class.paramattr(pname)

    # Now access the parameters directly, to make it at least less
    # likely we'll end up in an infinite recursion.
    if mname.to_s =~ /=$/
      @parameters[pname] = args.first
    else
      return @parameters[mname]
    end
  else
    super
  end
end