lib/rackamole/mole.rb in rackamole-0.1.1 vs lib/rackamole/mole.rb in rackamole-0.2.0
- old
+ new
@@ -1,10 +1,10 @@
require 'hitimes'
require 'json'
require 'mongo'
+require 'yaml'
-# BOZO !! - Need args validator or use dsl as the args are out of control...
module Rack
class Mole
# Initialize The Mole rack component. It is recommended that you specify at a minimum a user_key to track
# interactions on a per user basis. If you wish to use the mole for the same application in different
@@ -14,10 +14,15 @@
# logs. This is the default setting. Alternatively you can store mole information in a mongo database by
# specifying a different store option.
#
# === Options
#
+ # :config_file :: This option will load rackamole options from a file versus individual options.
+ # You can leverage yaml and erb with the current rackamole context to specify each of
+ # the following options but within a yaml file. This gives more flexibility to customize
+ # the rack component for specific environment. You can specify the :environment option or
+ # the default will be development.
# :app_name :: The name of the application (Default: Moled App)
# :log_level :: Rackamole logger level. (Default: info )
# :environment :: The environment for the application ie :environment => RAILS_ENV
# :perf_threshold :: Any request taking longer than this value will get moled. Default: 10secs
# :moleable :: Enable/Disable the MOle (Default:true)
@@ -90,20 +95,29 @@
attr_reader :options, :logger, :stash #:nodoc:
# Load up configuration options
def init_options( opts )
- @options = default_options.merge( opts )
+ if opts[:config_file] && (env = opts[:environment] || "development")
+ raise "Unable to find rackamole config file #{opts[:config_file]}" unless ::File.exists?( opts[:config_file] )
+ begin
+ opts = YAML.load( ERB.new( IO.read( opts[:config_file] ) ).result( binding ) )[env]
+ opts[:environment] = env
+ rescue => boom
+ raise "Unable to parse Rackamole config file #{boom}"
+ end
+ end
+ @options = default_options.merge( opts )
end
# Mole default options
def default_options
{
:moleable => true,
:log_level => :info,
:expiration => 60*60, # 1 hour
:app_name => "Moled App",
- :environment => 'test',
+ :environment => 'development',
:excluded_paths => [/.?\.ico/, /.?\.png/],
:perf_threshold => 10.0,
:store => Rackamole::Store::Log.new
}
end
\ No newline at end of file