lib/sinatra/toadhopper.rb in toadhopper-sinatra-1.0.3 vs lib/sinatra/toadhopper.rb in toadhopper-sinatra-1.0.4
- old
+ new
@@ -1,35 +1,53 @@
require 'sinatra/base'
require 'toadhopper'
+require 'sinatra/toadhopper/version'
module Sinatra
- # The Toadhopper helper methods
module Toadhopper
- VERSION = "1.0.3"
- # Reports the current sinatra error to Hoptoad
- def post_error_to_hoptoad!
- unless options.toadhopper && options.toadhopper[:api_key]
- STDERR.puts "Toadhopper api key not set, e.g. set :toadhopper, :api_key => 'my api key'"
- return
+
+ module Helpers
+ # Reports the current sinatra error to Hoptoad
+ def post_error_to_hoptoad!
+ unless toadhopper_api_key
+ STDERR.puts "Toadhopper api key not set, e.g. set :toadhopper, :api_key => 'my api key'"
+ return
+ end
+ toadhopper = ::Toadhopper.new(toadhopper_api_key, toadhopper_options)
+ toadhopper.filters = toadhopper_filters if toadhopper_filters
+ toadhopper.post!(
+ env['sinatra.error'],
+ {
+ :url => request.url,
+ :params => request.params,
+ :session => session.to_hash,
+ :environment => ENV.to_hash,
+ :framework_env => options.environment.to_s,
+ :project_root => options.root,
+ :notifier_name => (notifier_name = "toadhopper-sinatra"),
+ :notifier_version => VERSION,
+ :notifier_url => 'http://github.com/toolmantim/toadhopper-sinatra'
+ },
+ {'X-Hoptoad-Client-Name' => notifier_name}
+ )
end
- filters = options.toadhopper.delete(:filters)
- toadhopper = ::Toadhopper.new(options.toadhopper.delete(:api_key), options.toadhopper)
- toadhopper.filters = filters if filters
- toadhopper.post!(
- env['sinatra.error'],
- {
- :url => request.url,
- :params => request.params,
- :session => session.to_hash,
- :environment => ENV.to_hash,
- :framework_env => options.environment.to_s,
- :project_root => options.root,
- :notifier_name => (notifier_name = "toadhopper-sinatra"),
- :notifier_version => VERSION,
- :notifier_url => 'http://github.com/toolmantim/toadhopper-sinatra'
- },
- {'X-Hoptoad-Client-Name' => notifier_name}
- )
+ private
+ def toadhopper_filters
+ settings.toadhopper[:filters]
+ end
+ def toadhopper_api_key
+ settings.toadhopper[:api_key]
+ end
+ def toadhopper_options
+ settings.toadhopper.reject {|k,_| [:api_key, :filters].include?(k)}
+ end
end
+
+ def self.registered(app)
+ app.helpers Toadhopper::Helpers
+ app.set :toadhopper, {}
+ end
+
end
- helpers Toadhopper
-end
+
+ register Toadhopper
+end
\ No newline at end of file