Class: Ridley::DataBagItemResource
- Inherits:
-
Resource
- Object
- Resource
- Ridley::DataBagItemResource
show all
- Defined in:
- lib/ridley/resources/data_bag_item_resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Resource
#connection, #new, representation, represented_by, resource_path, set_resource_path
Constructor Details
#initialize(connection_registry, encrypted_data_bag_secret) ⇒ DataBagItemResource
Returns a new instance of DataBagItemResource.
9
10
11
12
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 9
def initialize(connection_registry, encrypted_data_bag_secret)
super(connection_registry)
@encrypted_data_bag_secret = encrypted_data_bag_secret
end
|
Instance Attribute Details
#encrypted_data_bag_secret ⇒ Object
Returns the value of attribute encrypted_data_bag_secret.
5
6
7
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 5
def encrypted_data_bag_secret
@encrypted_data_bag_secret
end
|
Instance Method Details
#all(data_bag) ⇒ Array<Object>
17
18
19
20
21
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 17
def all(data_bag)
request(:get, "#{DataBagResource.resource_path}/#{data_bag.name}").collect do |id, location|
new(data_bag, id: id)
end
end
|
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 39
def create(data_bag, object)
resource = new(data_bag, object.to_hash)
unless resource.valid?
abort Errors::InvalidResource.new(resource.errors)
end
new_attributes = request(:post, "#{DataBagResource.resource_path}/#{data_bag.name}", resource.to_json)
resource.mass_assign(new_attributes)
resource
end
|
54
55
56
57
58
59
60
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 54
def delete(data_bag, object)
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
new(data_bag).from_hash(request(:delete, "#{DataBagResource.resource_path}/#{data_bag.name}/#{chef_id}"))
rescue AbortError => ex
return nil if ex.cause.is_a?(Errors::HTTPNotFound)
abort(ex.cause)
end
|
65
66
67
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 65
def delete_all(data_bag)
all(data_bag).collect { |resource| future(:delete, data_bag, resource) }.map(&:value)
end
|
27
28
29
30
31
32
33
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 27
def find(data_bag, object)
chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
new(data_bag).from_hash(request(:get, "#{DataBagResource.resource_path}/#{data_bag.name}/#{chef_id}"))
rescue AbortError => ex
return nil if ex.cause.is_a?(Errors::HTTPNotFound)
abort(ex.cause)
end
|
73
74
75
76
77
78
79
80
81
|
# File 'lib/ridley/resources/data_bag_item_resource.rb', line 73
def update(data_bag, object)
resource = new(data_bag, object.to_hash)
new(data_bag).from_hash(
request(:put, "#{DataBagResource.resource_path}/#{data_bag.name}/#{resource.chef_id}", resource.to_json)
)
rescue AbortError => ex
return nil if ex.cause.is_a?(Errors::HTTPConflict)
abort(ex.cause)
end
|