Class: ChefAPI::Resource::DataBagItemCollectionProxy

Inherits:
CollectionProxy show all
Defined in:
lib/chef-api/resources/data_bag.rb

Overview

The mutable collection is a special kind of collection proxy that permits Rails-like attribtue creation, like:

DataBag.first.items.create(id: 'me', thing: 'bar', zip: 'zap')

Instance Method Summary collapse

Methods inherited from CollectionProxy

#all, #count, #each, #exists?, #fetch, #inspect, #reload!, #to_s

Constructor Details

#initialize(bag) ⇒ DataBagItemCollectionProxy

Returns a new instance of DataBagItemCollectionProxy.



88
89
90
91
# File 'lib/chef-api/resources/data_bag.rb', line 88

def initialize(bag)
  # Delegate to the superclass
  super(bag, Resource::DataBagItem, nil, bag: bag.name)
end

Instance Method Details

#build(data = {}) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.build


113
114
115
# File 'lib/chef-api/resources/data_bag.rb', line 113

def build(data = {})
  klass.build(data, prefix)
end

#create(data = {}) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.create


118
119
120
121
122
# File 'lib/chef-api/resources/data_bag.rb', line 118

def create(data = {})
  klass.create(data, prefix)
ensure
  reload!
end

#create!(data = {}) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.create!


125
126
127
128
129
# File 'lib/chef-api/resources/data_bag.rb', line 125

def create!(data = {})
  klass.create!(data, prefix)
ensure
  reload!
end

#destroy(id) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.destroy


99
100
101
102
103
# File 'lib/chef-api/resources/data_bag.rb', line 99

def destroy(id)
  klass.destroy(id, prefix)
ensure
  reload!
end

#destroy_allObject

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.destroy_all


106
107
108
109
110
# File 'lib/chef-api/resources/data_bag.rb', line 106

def destroy_all
  klass.destroy_all(prefix)
ensure
  reload!
end

#new(data = {}) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.new


94
95
96
# File 'lib/chef-api/resources/data_bag.rb', line 94

def new(data = {})
  klass.new(data, prefix, parent)
end

#update(id, data = {}) ⇒ Object

See Also:

  • ChefAPI::Resource::DataBagItemCollectionProxy.klassklass.update


132
133
134
# File 'lib/chef-api/resources/data_bag.rb', line 132

def update(id, data = {})
  klass.update(id, data, prefix)
end