class Nagios::API::Resource

Attributes

api_client[R]
attributes[RW]

Public Class Methods

new(args = {}) click to toggle source
# File lib/nagios/api/resource.rb, line 6
def initialize(args = {})
  @api_client = args.delete(:api_client)
  @attributes = {}
  self.attributes = args
end

Public Instance Methods

attributes=(args = {}) click to toggle source
# File lib/nagios/api/resource.rb, line 12
def attributes=(args = {})
  args ||= {}
  args.each do |key, value|
    self.send(:"#{key}=", value)
  end
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/nagios/api/resource.rb, line 19
def method_missing(meth, *args, &block)
  if meth.to_s =~ /^(.+)=$/
    @attributes[$1.to_sym] = args[0]
  elsif @attributes.has_key?(meth)
    @attributes[meth]
  else
    super # You *must* call super if you don't handle the
          # method, otherwise you'll mess up Ruby's method
          # lookup.
  end
end
to_hash(options = {}) click to toggle source
# File lib/nagios/api/resource.rb, line 31
def to_hash(options = {})
  hash = attributes
  hash.reject! { |key, value| options[:except].include?(key.to_sym) || options[:except].include?(key.to_s) } if options[:except]
  hash.reject! { |key, value| !options[:only].include?(key.to_sym) && !options[:only].include?(key.to_s) } if options[:only]
  hash
end