Sha256: 363e8d9b5cfb61a1e5bfdacb6a6531bfa0213fdfd9ca349b1210288074c0fbd1

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

require 'erb'
require 'singleton'

module Tekeya
  # Parses the configuration file and holds important configuration attributes  
  class Configuration
    include Singleton
    
    attr_reader :redis, :rebat
    attr_accessor :redis_host, :redis_port, :rebatdb_host, :rebatdb_port, :feed_storage_orm
    
    # @private
    # Initializes a new configuration object
    def initialize
      parse_config_file "#{Rails.root}/config/tekeya.yml"
      
      # Setup defaults
      @redis_host       ||= "localhost"
      @redis_port       ||= "6379"
      @rebatdb_host     ||= "localhost"
      @rebatdb_port     ||= "2011"
      @feed_storage_orm ||= :active_record
    end

    def setup_databases
      # Setup redis
      @redis = Redis.new host: @redis_host, port: @redis_port.to_i

      # Setup resque
      Resque.redis = @redis

      # Setup rebatdb
      @rebat = Rebat.new "#{@rebatdb_host}", "#{@rebatdb_port}", { tracks: 1, joins: 2, blocks: 3 }
    end    

    # Loads the configuration file
    # @return [nil]
    def parse_config_file(path)
      return unless File.exists?(path)
      
      conf = YAML::load(ERB.new(IO.read(path)).result)[Rails.env]
      
      conf.each do |key,value|
        self.send("#{key}=", value) if self.respond_to?("#{key}=")
      end unless conf.nil?
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
tekeya-0.0.10 lib/tekeya/configuration.rb
tekeya-0.0.9 lib/tekeya/configuration.rb
tekeya-0.0.7 lib/tekeya/configuration.rb
tekeya-0.0.6 lib/tekeya/configuration.rb
tekeya-0.0.5 lib/tekeya/configuration.rb
tekeya-0.0.4 lib/tekeya/configuration.rb
tekeya-0.0.3 lib/tekeya/configuration.rb
tekeya-0.0.2 lib/tekeya/configuration.rb
tekeya-0.0.1 lib/tekeya/configuration.rb