Sha256: b4467715e5de40a84d9589f316c7771728aad7832fa74f16dbed9c058d8dc579

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

module Elasticonf
  class Config
    def reset_config!
      %w(
        env
        config_root
        config_file
        const_name
        raise_if_already_initialized_constant
      ).each do |v|
        instance_variable_set "@#{v}", nil
      end
    end

    def env
      @env ||= 'development'
    end

    def env=(value)
      unless [String, Symbol].include?(value.class)
        raise ArgumentError, "String or Symbol expected #{value.class} given"
      end
      @env = value.to_s
    end

    def config_root
      @config_root ||= raise(ArgumentError, 'You must specify config_root option first')
    end

    def config_root=(value)
      unless [String, Symbol, Pathname].include?(value.class)
        raise ArgumentError, "String or Symbol or Pathname expected #{value.class} given"
      end
      @config_root = value.is_a?(Pathname) ? value : Pathname.new(value.to_s)
    end

    def config_file
      @config_file ||= 'settings'
    end

    def config_file=(value)
      unless [String, Symbol].include?(value.class)
        raise ArgumentError, "String or Symbol expected #{value.class} given"
      end
      @config_file = value.to_s
    end

    def const_name
      @const_name ||= 'Settings'
    end

    def const_name=(value)
      unless [String, Symbol].include?(value.class)
        raise ArgumentError, "String or Symbol expected #{value.class} given"
      end
      @const_name = value.to_s
    end

    def raise_if_already_initialized_constant
      @raise_if_already_initialized_constant.nil? ? true : @raise_if_already_initialized_constant
    end

    def raise_if_already_initialized_constant=(value)
      unless [TrueClass, FalseClass].include?(value.class)
        raise ArgumentError, "TrueClass or FalseClass expected #{value.class} given"
      end
      @raise_if_already_initialized_constant = value
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
elasticonf-1.1.5 lib/elasticonf/config.rb
elasticonf-1.1.4 lib/elasticonf/config.rb