module Perkins class Application attr_accessor :host , :port, :working_dir, :redis, :database attr_reader :server attr_accessor :github_client_id, :github_client_secret def initialize(opts={}) host = opts[:host] unless opts[:host].blank? post = opts[:port] unless opts[:port].blank? github_client_id = opts[:github_client_id] unless opts[:github_client_id].blank? github_client_server = opts[:github_client_secret] unless opts[:github_client_secret].blank? working_dir = opts[:working_dir] unless opts[:working_dir].blank? end def database=(file) dbconfig = YAML::load(File.open(file)) @db = ActiveRecord::Base.establish_connection(dbconfig[ENV['RACK_ENV']]) end def database @db end def redis=(opts={}) namespace = opts.delete(:namespace) || :perkins redis_connection = Redis.new(opts) $redis = Redis::Namespace.new(namespace, :redis => redis_connection) end def as_json(options = {}) data = {} fields = [:host, :port, :github_client_id, :github_client_secret, :working_dir] fields.each { |k| data[k] = send(k) } data end end end