Class: Zabbirc::Zabbix::Resource::Base
- Inherits:
-
Object
- Object
- Zabbirc::Zabbix::Resource::Base
show all
- Extended by:
- Associations, Finders
- Defined in:
- lib/zabbirc/zabbix/resource/base.rb
Class Method Summary
collapse
Instance Method Summary
collapse
has_many, has_one
Methods included from Finders
find, get
Constructor Details
#initialize(attrs) ⇒ Base
Returns a new instance of Base.
29
30
31
32
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 29
def initialize attrs
@attrs = ActiveSupport::HashWithIndifferentAccess.new attrs
raise ArgumentError, "attribute `#{self.class.model_name}id` not found, probably not an Event" unless @attrs.key? :"#{self.class.model_name}id"
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 42
def method_missing method, *args, &block
if args.length == 0 and not block_given? and @attrs.key? method
@attrs[method]
else
super
end
end
|
Class Method Details
.api ⇒ Object
21
22
23
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 21
def self.api
Connection.get_connection.client
end
|
.model_name ⇒ Object
17
18
19
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 17
def self.model_name
@model_name ||= name.split(/::/).last.underscore
end
|
.set_model_name(model_name) ⇒ Object
13
14
15
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 13
def self.set_model_name model_name
@model_name = model_name
end
|
Instance Method Details
#[](attr) ⇒ Object
38
39
40
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 38
def [] attr
@attrs[attr]
end
|
#api ⇒ Object
25
26
27
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 25
def api
Connection.get_connection.client
end
|
#id ⇒ Object
34
35
36
|
# File 'lib/zabbirc/zabbix/resource/base.rb', line 34
def id
@attrs["#{self.class.model_name}id"]
end
|