Sha256: 5637418d8879bbc8d42f1f9c2bb23468073cf8aff1e6d68d31de61e8659ffa1a

Contents?: true

Size: 1.02 KB

Versions: 37

Compression:

Stored size: 1.02 KB

Contents

module Ridley
  class DataBagResource < Ridley::Resource
    require_relative 'data_bag_item_resource'

    set_resource_path "data"
    represented_by Ridley::DataBagObject

    attr_reader :item_resource

    finalizer :finalize_callback

    # @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
      request(:get, "#{self.class.resource_path}/#{chef_id}")
      new(name: chef_id)
    rescue AbortError => ex
      return nil if ex.cause.is_a?(Errors::HTTPNotFound)
      abort(ex.cause)
    end

    private

      def finalize_callback
        item_resource.terminate if item_resource && item_resource.alive?
      end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
ridley-2.5.1 lib/ridley/resources/data_bag_resource.rb
ridley-2.5.0 lib/ridley/resources/data_bag_resource.rb
ridley-2.4.4 lib/ridley/resources/data_bag_resource.rb
ridley-2.4.3 lib/ridley/resources/data_bag_resource.rb
ridley-2.4.2 lib/ridley/resources/data_bag_resource.rb
ridley-2.4.1 lib/ridley/resources/data_bag_resource.rb
ridley-2.4.0 lib/ridley/resources/data_bag_resource.rb
ridley-2.3.0 lib/ridley/resources/data_bag_resource.rb
ridley-2.2.0 lib/ridley/resources/data_bag_resource.rb
ridley-2.1.0 lib/ridley/resources/data_bag_resource.rb
ridley-2.0.0 lib/ridley/resources/data_bag_resource.rb
ridley-1.7.1 lib/ridley/resources/data_bag_resource.rb
ridley-1.7.0 lib/ridley/resources/data_bag_resource.rb
ridley-1.6.0 lib/ridley/resources/data_bag_resource.rb
ridley-1.5.3 lib/ridley/resources/data_bag_resource.rb
ridley-1.2.6 lib/ridley/resources/data_bag_resource.rb
ridley-1.5.2 lib/ridley/resources/data_bag_resource.rb
ridley-1.5.1 lib/ridley/resources/data_bag_resource.rb
ridley-1.5.0 lib/ridley/resources/data_bag_resource.rb
ridley-1.2.5 lib/ridley/resources/data_bag_resource.rb