Module: Spice::Connection::DataBags

Included in:
Spice, Spice::Connection
Defined in:
lib/spice/connection/data_bags.rb

Instance Method Summary collapse

Instance Method Details

#data_bag(name) ⇒ Spice::DataBag

Retrieve a single data bag and its items

Raises:



21
22
23
24
# File 'lib/spice/connection/data_bags.rb', line 21

def data_bag(name)
  items = connection.search(name)
  Spice::DataBag.new(:name => name, :items => items)
end

#data_bag_item(name, id) ⇒ Spice::DataBagItem

Retrieve a single data bag item

Raises:



31
32
33
34
35
# File 'lib/spice/connection/data_bags.rb', line 31

def data_bag_item(name, id)
  data = connection.get("/data/#{name}/#{id}")
  data.delete('id')
  Spice::DataBagItem.new(:_id => id, :data => data, :name => name)
end

#data_bagsArray<Spice::DataBag> Also known as: data

Retrieve an array of all data bags

Examples:

Retrieve all data bags

Spice.data_bags


8
9
10
11
12
13
# File 'lib/spice/connection/data_bags.rb', line 8

def data_bags
  connection.get("/data").body.keys.map do |data_bag|
    items = connection.search(data_bag)
    Spice::DataBag.new(:name => data_bag, :items => items)
  end
end