Class: Infoblox::Resource
- Inherits:
-
Object
- Object
- Infoblox::Resource
- Defined in:
- lib/infoblox/resource.rb
Instance Attribute Summary collapse
-
#_ref ⇒ Object
Returns the value of attribute _ref.
Class Method Summary collapse
- .all ⇒ Object
- .connection ⇒ Object
- .connection=(con) ⇒ Object
- .find(params) ⇒ Object
- .remote_attr_accessor(*args) ⇒ Object
- .remote_attrs ⇒ Object
- .resource_uri ⇒ Object
- .wapi_object(obj = nil) ⇒ Object
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
- #get ⇒ Object
-
#initialize(attrs = {}) ⇒ Resource
constructor
A new instance of Resource.
- #remote_attribute_hash ⇒ Object
- #resource_uri ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Resource
Returns a new instance of Resource.
44 45 46 47 48 |
# File 'lib/infoblox/resource.rb', line 44 def initialize(attrs={}) attrs.each do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#_ref ⇒ Object
Returns the value of attribute _ref.
3 4 5 |
# File 'lib/infoblox/resource.rb', line 3 def _ref @_ref end |
Class Method Details
.all ⇒ Object
20 21 22 23 24 |
# File 'lib/infoblox/resource.rb', line 20 def self.all JSON.parse(connection.get(resource_uri).body).map do |item| new(item) end end |
.connection ⇒ Object
32 33 34 |
# File 'lib/infoblox/resource.rb', line 32 def self.connection @@connection end |
.connection=(con) ⇒ Object
36 37 38 |
# File 'lib/infoblox/resource.rb', line 36 def self.connection=(con) @@connection = con end |
.find(params) ⇒ Object
26 27 28 29 30 |
# File 'lib/infoblox/resource.rb', line 26 def self.find(params) JSON.parse(connection.get(resource_uri, params).body).map do |item| new(item) end end |
.remote_attr_accessor(*args) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/infoblox/resource.rb', line 9 def self.remote_attr_accessor(*args) args.each do |a| attr_accessor a remote_attrs << a end end |
.remote_attrs ⇒ Object
16 17 18 |
# File 'lib/infoblox/resource.rb', line 16 def self.remote_attrs @remote_attrs ||= [] end |
.resource_uri ⇒ Object
40 41 42 |
# File 'lib/infoblox/resource.rb', line 40 def self.resource_uri BASE_PATH + self.wapi_object end |
.wapi_object(obj = nil) ⇒ Object
5 6 7 |
# File 'lib/infoblox/resource.rb', line 5 def self.wapi_object(obj=nil) obj.nil? ? @wapi_object : @wapi_object = obj end |
Instance Method Details
#create ⇒ Object
50 51 52 53 |
# File 'lib/infoblox/resource.rb', line 50 def create self._ref = connection.post(resource_uri, remote_attribute_hash).body true end |
#delete ⇒ Object
55 56 57 |
# File 'lib/infoblox/resource.rb', line 55 def delete connection.delete(resource_uri).status == 200 end |
#get ⇒ Object
59 60 61 |
# File 'lib/infoblox/resource.rb', line 59 def get connection.get(resource_uri) end |
#remote_attribute_hash ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/infoblox/resource.rb', line 67 def remote_attribute_hash {}.tap do |hsh| self.class.remote_attrs.each do |k| hsh[k] = self.send(k) end end end |
#resource_uri ⇒ Object
63 64 65 |
# File 'lib/infoblox/resource.rb', line 63 def resource_uri self._ref.nil? ? self.class.resource_uri : (BASE_PATH + self._ref) end |