5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/zabbirc/zabbix/resource/associations.rb', line 5
def has_many name
define_method name do
@associations ||= ActiveSupport::HashWithIndifferentAccess.new
@associations[name] ||= begin
assoc_class = Zabbix.const_get(name.to_s.singularize.camelize)
hash_data = @attrs[name]
if hash_data.blank?
this = self.class.find id, :"select#{name.to_s.camelize}" => :extend
raise StandardError, "zabbix response does not contain #{name}" if this[name].blank?
hash_data = this[name]
end
hash_data.collect do |obj|
assoc_class.new obj
end
end
end
end
|