Sha256: e5b6a7bb4859d96fb9bfe45d1e5503b117118464b24f7744908112bb84845bc2

Contents?: true

Size: 875 Bytes

Versions: 4

Compression:

Stored size: 875 Bytes

Contents

module SmartQue
  class Config
    # Configurations
    # allowed configurations
    CONFIGURATION = %w(host port queues env username password logfile logger)

    # Initialize
    def initialize
      @config = {}
      load_configuration_from_yml
    end

    def method_missing(name, *args)
      setter = false

      name = name.to_s

      if name =~ /=$/
        name = name.to_s.chop
        setter = true
      end

      super(name, args) unless CONFIGURATION.include?(name)

      if setter
        set(name, args.first)
      else
        get(name)
      end
    end

    private

    def load_configuration_from_yml
      if File.exist? 'config/smart_que.yml'
        @config = YAML.load(File.read('config/smart_que.yml')) || @config
      end
    end

    def set(key, val)
      @config[key] = val
    end

    def get(key)
      @config[key]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
smart-que-0.2.0 lib/smart_que/config.rb
smart-que-0.1.2 lib/smart_que/config.rb
smart-que-0.1.1 lib/smart_que/config.rb
smart-que-0.1.0 lib/smart_que/config.rb