Sha256: 969f894a4af34d9826a426b389ed25b980d881ec7c31358f4f5fac2fdbfcffb6
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module Infoblox class Resource attr_accessor :_ref def self.wapi_object(obj=nil) obj.nil? ? @wapi_object : @wapi_object = obj end def self.remote_attr_accessor(*args) args.each do |a| attr_accessor a remote_attrs << a end end def self.remote_attrs @remote_attrs ||= [] end def self.all JSON.parse(connection.get(resource_uri).body).map do |item| new(item) end end def self.find(params) JSON.parse(connection.get(resource_uri, params).body).map do |item| new(item) end end def self.connection @@connection end def self.connection=(con) @@connection = con end def self.resource_uri BASE_PATH + self.wapi_object end def initialize(attrs={}) attrs.each do |k,v| self.send("#{k}=", v) end end def create self._ref = connection.post(resource_uri, remote_attribute_hash).body true end def delete connection.delete(resource_uri).status == 200 end def resource_uri self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref) end private def remote_attribute_hash {}.tap do |hsh| self.class.remote_attrs.each do |k| hsh[k] = self.send(k) end end end def connection self.class.connection end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
infoblox-0.0.2 | lib/infoblox/resource.rb |
infoblox-0.0.1 | lib/infoblox/resource.rb |