Sha256: 0bbff1ddb474a7da1ffdbf2a23d15b7cc1ff03b441809c1f121a5ef314ffd99e

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module Ridley
  # @author Jamie Winsor <reset@riotgames.com>
  class EnvironmentResource < Ridley::Resource
    set_resource_path "environments"
    represented_by Ridley::EnvironmentObject

    # Used to return a hash of the cookbooks and cookbook versions (including all dependencies)
    # that are required by the run_list array.
    #
    # @param [String] environment
    #   name of the environment to run against
    # @param [Array] run_list
    #   an array of cookbooks to satisfy
    #
    # @raise [Errors::ResourceNotFound] if the given environment is not found
    #
    # @return [Hash]
    def cookbook_versions(environment, run_list = [])
      run_list = Array(run_list).flatten
      chef_id  = environment.respond_to?(:chef_id) ? environment.chef_id : environment
      request(:post, "#{self.class.resource_path}/#{chef_id}/cookbook_versions", MultiJson.encode(run_list: run_list))
    rescue AbortError => ex
      if ex.cause.is_a?(Errors::HTTPNotFound)
        abort Errors::ResourceNotFound.new(ex)
      end
      abort(ex.cause)
    end

    # Delete all of the environments on the client. The '_default' environment
    # will never be deleted.
    #
    # @return [Array<Ridley::EnvironmentObject>]
    def delete_all
      envs = all.reject { |env| env.name.to_s == '_default' }
      envs.collect { |resource| future(:delete, resource) }.map(&:value)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ridley-0.12.2 lib/ridley/resources/environment_resource.rb
ridley-0.12.1 lib/ridley/resources/environment_resource.rb
ridley-0.12.0 lib/ridley/resources/environment_resource.rb