Sha256: ece82bb83b80e3081cc4172f3cd638abb82879eeaa6072491e439762a4a4c94d

Contents?: true

Size: 967 Bytes

Versions: 4

Compression:

Stored size: 967 Bytes

Contents

require 'ridley/resources/data_bag_item_resource'

module Ridley
  # @author Jamie Winsor <reset@riotgames.com>
  class DataBagResource < Ridley::Resource
    set_resource_path "data"
    represented_by Ridley::DataBagObject

    attr_reader :item_resource

    finalizer do
      item_resource.terminate if item_resource && item_resource.alive?
    end

    # @param [Celluloid::Registry] connection_registry
    # @param [String] data_bag_secret
    def initialize(connection_registry, data_bag_secret)
      super(connection_registry)
      @item_resource = DataBagItemResource.new_link(connection_registry, data_bag_secret)
    end

    # @param [String, #chef_id] object
    #
    # @return [nil, Ridley::DataBagResource]
    def find(object)
      chef_id = object.respond_to?(:chef_id) ? object.chef_id : object
      connection.get("#{self.class.resource_path}/#{chef_id}")
      new(name: chef_id)
    rescue Errors::HTTPNotFound
      nil
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ridley-0.11.2 lib/ridley/resources/data_bag_resource.rb
ridley-0.12.0.rc1 lib/ridley/resources/data_bag_resource.rb
ridley-0.11.1 lib/ridley/resources/data_bag_resource.rb
ridley-0.11.0.rc1 lib/ridley/resources/data_bag_resource.rb