Module: Zabby::ZClass::ClassMethods

Defined in:
lib/zabby/zclass.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

Simulate methods on the object and call the Zabbix Web Service (“host.get”, “item.create”, etc.). See www.zabbix.com/documentation/1.8/api for the API documentation.

Parameters:

  • zmethod (String)

    Name of the Web Service methods

  • args (Array)

    Method arguments

  • block (Proc)

    Unused

Raises:

  • (NoMethodError)

    Raised on invalid method names.



71
72
73
74
75
76
77
# File 'lib/zabby/zclass.rb', line 71

def method_missing(zmethod, *args, &block)
  if @zmethods.include? zmethod
    Zabby::Runner.instance.connection.perform_request(class_name, zmethod, args.first)
  else
    super
  end
end

Instance Attribute Details

#idObject (readonly)

The id field name for the model (“actionid”, “hostid”, etc.)



28
29
30
# File 'lib/zabby/zclass.rb', line 28

def id
  @id
end

#zmethodsObject (readonly)

List of valid Web Service methods for the current Zabbix Object



26
27
28
# File 'lib/zabby/zclass.rb', line 26

def zmethods
  @zmethods
end

Instance Method Details

#class_nameString

Name of the current class without the namespace

Examples:

Zabby::Host.object_name => "Host"

Returns:

  • (String)


34
35
36
# File 'lib/zabby/zclass.rb', line 34

def class_name
  @class_name ||= self.name.split(/::/).last.downcase
end

#inspectString

Human representation of the Zabbix Class

Examples:

Host.inspect => "<Zabby::Host methods=(create, delete, exists, get, update)>"

Returns:

  • (String)

    Class representation



42
43
44
# File 'lib/zabby/zclass.rb', line 42

def inspect
  "<#{name} methods=(#{@zmethods.join(', ')})>"
end