Class: Spice::DataBagItem
- Inherits:
-
Object
- Object
- Spice::DataBagItem
- Extended by:
- Persistence
- Includes:
- Persistence, Toy::Store
- Defined in:
- lib/spice/data_bag_item.rb
Instance Attribute Summary (collapse)
-
- (String) _id
The _id attribute is used as the "id" field in the data bag item.
-
- (Hash) data
The data attribute.
-
- (String) name
The name attribute.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) do_delete
- - (Object) do_post
- - (Object) do_put
-
- (Boolean) new_record?
Check if the data bag item exists on the Chef server.
Methods included from Persistence
all, connection, endpoint, get, included
Instance Attribute Details
- (String) _id
The _id attribute is used as the "id" field in the data bag item. "id" is an attribute reserved by ToyStore, the attribute system used by Spice.
13 |
# File 'lib/spice/data_bag_item.rb', line 13 attribute :_id, String |
- (Hash) data
The data attribute
17 |
# File 'lib/spice/data_bag_item.rb', line 17 attribute :data, Hash, :default => {} |
- (String) name
The name attribute
18 |
# File 'lib/spice/data_bag_item.rb', line 18 attribute :name, String |
Class Method Details
+ (Object) get(name, id)
22 23 24 |
# File 'lib/spice/data_bag_item.rb', line 22 def self.get(name, id) connection.data_bag_item(name, id) end |
Instance Method Details
- (Object) do_delete
38 39 40 |
# File 'lib/spice/data_bag_item.rb', line 38 def do_delete connection.delete("/data/#{name}/#{_id}") end |
- (Object) do_post
26 27 28 29 30 |
# File 'lib/spice/data_bag_item.rb', line 26 def do_post attrs = data.dup attrs['id'] = attributes['_id'] connection.post("/data/#{name}", attrs) end |
- (Object) do_put
32 33 34 35 36 |
# File 'lib/spice/data_bag_item.rb', line 32 def do_put attrs = data.dup attrs['id'] = attributes['_id'] connection.put("/data/#{name}/#{_id}", attrs) end |
- (Boolean) new_record?
Check if the data bag item exists on the Chef server
43 44 45 46 47 48 49 50 |
# File 'lib/spice/data_bag_item.rb', line 43 def new_record? begin connection.get("/data/#{name}/#{_id}") return false rescue Spice::Error::NotFound return true end end |