Sha256: 01b0814f3202f7432221ca2c0a20839c15f5412fd4ced1794ee7f24f06160805

Contents?: true

Size: 639 Bytes

Versions: 1

Compression:

Stored size: 639 Bytes

Contents

module Mina
  class Configuration
    include Singleton

    attr_reader :variables

    def initialize
      @variables ||= {}
    end

    def set(key, value = nil, &block)
      variables[key] = block || value
    end

    def fetch(key, default = nil)
      value = ENV[key.to_s] || variables.fetch(key, default)
      value.respond_to?(:call) ? value.call : value
    end

    def remove(key)
      variables.delete(key)
    end

    def set?(key)
      !variables.fetch(key, nil).nil?
    end

    def ensure!(key)
      fail "#{key} must be defined!" unless set?(key)
    end

    def reset!
      @variables = {}
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mina-1.0.0.beta1 lib/mina/configuration.rb