Sha256: ff213757e20d37c616a1bd14f366a198cc7b06f9f44a4be043fbf9ab0324f209

Contents?: true

Size: 964 Bytes

Versions: 3

Compression:

Stored size: 964 Bytes

Contents

module Humidifier
  module Reservoir
    # A container class for the user-specified Reservoir configuration.
    class Config
      attr_reader :mappings, :stack_path
      attr_accessor :stack_prefix

      def initialize
        @mappings = {}
      end

      def files_for(name)
        raise Error, 'You must configure a stack path' if stack_path.nil?
        Dir["#{stack_path}/#{name}/*.yml"]
      end

      def map(type, opts = {}, &block)
        mappings[type.to_sym] = Mapping.new(opts, &block)
      end

      def mapping_for(type)
        mappings[type.to_sym]
      end

      def stack_path=(stack_path)
        unless File.exist?(stack_path)
          raise Error, "Invalid filepath: #{stack_path}"
        end
        @stack_path = stack_path
      end

      def stacks
        Dir["#{stack_path}/*"].each_with_object([]) do |name, names|
          names << File.basename(name) if File.directory?(name)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
humidifier-reservoir-0.4.0 lib/humidifier/reservoir/config.rb
humidifier-reservoir-0.3.0 lib/humidifier/reservoir/config.rb
humidifier-reservoir-0.2.3 lib/humidifier/reservoir/config.rb