Sha256: 7720a9aed8793ed40cf4935d212f3c6024c7211bfd7d982d03ca5e8bafbee673

Contents?: true

Size: 926 Bytes

Versions: 2

Compression:

Stored size: 926 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 = {})
        mappings[type.to_sym] = Mapping.new(opts)
      end

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

      def stack_path=(stack_path)
        raise Error, "Invalid filepath: #{stack_path}" unless File.exist?(stack_path)
        @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

2 entries across 2 versions & 1 rubygems

Version Path
humidifier-reservoir-0.1.0 lib/humidifier/reservoir/config.rb
humidifier-reservoir-0.0.1 lib/humidifier/reservoir/config.rb