Module: Spice::Connection::DataBags

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

Instance Method Summary collapse

Instance Method Details

#create_data_bag(name) ⇒ Object

def data_bag_item


36
37
38
39
# File 'lib/spice/connection/data_bags.rb', line 36

def create_data_bag(name)
  attributes = post("/data", :name => name)
  Spice::DataBag.get_or_new(:name => name, :items => [])
end

#create_data_bag_item(name, params = Mash.new) ⇒ Object

def create_data_bag


41
42
43
44
# File 'lib/spice/connection/data_bags.rb', line 41

def create_data_bag_item(name, params=Mash.new)
  attributes = post("/data/#{name}", params)
  Spice::DataBagItem.get_or_new(attributes)
end

#data_bag(name) ⇒ Spice::DataBag

Retrieve a single data bag and its items

Parameters:

  • name (String)

    The data bag name

Returns:

Raises:


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

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

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

Retrieve a single data bag item

Parameters:

  • name (String)

    The data bag name

  • id (String)

    The data bag item id

Returns:

Raises:


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

def data_bag_item(name, id)
  data_bag_item = get("/data/#{name}/#{id}")
  Spice::DataBagItem.get_or_new(data_bag_item)
end

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

Retrieve an array of all data bags

Examples:

Retrieve all data bags

Spice.data_bags

Returns:


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

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

#delete_data_bag_item(name, id) ⇒ Object

update_data_bag_item


52
53
54
55
# File 'lib/spice/connection/data_bags.rb', line 52

def delete_data_bag_item(name, id)
  delete("/data/#{name}/#{id}")
  nil
end

#update_data_bag_item(name, id, params = Mash.new) ⇒ Object

def create_data_bag_item


46
47
48
49
50
# File 'lib/spice/connection/data_bags.rb', line 46

def update_data_bag_item(name, id, params=Mash.new)
  params.merge!(:id => id)
  attributes = put("/data/#{name}/#{id}", params)
  Spice::DataBagItem.get_or_new(attributes)
end