class Ridley::DataBagItemResource

Attributes

encrypted_data_bag_secret[R]

Public Class Methods

new(connection_registry, encrypted_data_bag_secret) click to toggle source

@param [Celluloid::Registry] connection_registry @param [String] encrypted_data_bag_secret

Calls superclass method Ridley::Resource::new
# 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

Public Instance Methods

all(data_bag) click to toggle source

@param [Ridley::DataBagObject] data_bag

@return [Array<Object>]

# 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
create(data_bag, object) click to toggle source

@param [Ridley::DataBagObject] data_bag @param [#to_hash] object

@return [Ridley::DataBagItemObject, nil]

# 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
delete(data_bag, object) click to toggle source

@param [Ridley::DataBagObject] data_bag @param [String, chef_id] object

@return [Ridley::DataBagItemObject, nil]

# 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
delete_all(data_bag) click to toggle source

@param [Ridley::DataBagObject] data_bag

@return [Array<Ridley::DataBagItemObject>]

# 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
find(data_bag, object) click to toggle source

@param [Ridley::DataBagObject] data_bag @param [String, chef_id] object

@return [Ridley::DataBagItemObject, nil]

# 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
update(data_bag, object) click to toggle source

@param [Ridley::DataBagObject] data_bag @param [#to_hash] object

@return [Ridley::DataBagItemObject, nil]

# 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