Skip to content

Commit

Permalink
actually filter environmental variables again
Browse files Browse the repository at this point in the history
HoptoadNotifier -> Merb::HoptoadNotifier
version bump to 1.1.0 since the constants changed
cleanup misc cruft
  • Loading branch information
atmos committed Dec 25, 2009
1 parent 0c1f525 commit 46059f0
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ only :test do
gem 'rcov'
gem 'rr'
gem 'ruby-debug'
gem 'bundler'
gem 'bundler', '~>0.7.2'
end
15 changes: 8 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rubygems/specification'
require 'date'
require 'merb-core/version'
require 'spec/rake/spectask'
require 'bundler'

install_home = ENV['GEM_HOME'] ? "-i #{ENV['GEM_HOME']}" : ""
Bundler.require_env

require 'lib/merb_hoptoad_notifier'

NAME = "merb_hoptoad_notifier"
GEM_VERSION = "1.0.12"
GEM_VERSION = Merb::HoptoadNotifier::VERSION
AUTHOR = "Corey Donohoe"
EMAIL = '[email protected]'
HOMEPAGE = "http://github.com/atmos/merb_hoptoad_notifier"
Expand All @@ -28,14 +29,14 @@ spec = Gem::Specification.new do |s|
s.email = EMAIL
s.homepage = HOMEPAGE

manifest = Bundler::Environment.load(File.dirname(__FILE__) + '/Gemfile')
manifest = Bundler::Dsl.load_gemfile(File.dirname(__FILE__) + '/Gemfile')
manifest.dependencies.each do |d|
next unless d.only && d.only.include?('release')
s.add_dependency(d.name, d.version)
end

s.require_path = 'lib'
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib}/**/*")
end

Rake::GemPackageTask.new(spec) do |pkg|
Expand All @@ -50,11 +51,11 @@ task :make_spec do
end

Spec::Rake::SpecTask.new(:default) do |t|
t.spec_opts << %w(-fs --color) << %w(-O spec/spec.opts)
t.spec_opts << %w(-fs --color)
t.spec_opts << '--loadby' << 'random'
t.spec_files = Dir["spec/*_spec.rb"]
t.rcov = ENV.has_key?('NO_RCOV') ? ENV['NO_RCOV'] != 'true' : true
t.rcov_opts << '--exclude' << '.gem/'
t.rcov_opts << '--exclude' << 'vendor'

t.rcov_opts << '--text-summary'
t.rcov_opts << '--sort' << 'coverage' << '--sort-reverse'
Expand Down
10 changes: 5 additions & 5 deletions lib/merb_hoptoad_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
if defined?(Merb::Plugins)
libdir = File.join(File.dirname(__FILE__), 'merb_hoptoad_notifier')
require 'toadhopper'
require File.join(libdir, 'hoptoad_notifier')
require 'toadhopper'
libdir = File.join(File.dirname(__FILE__), 'merb_hoptoad_notifier')
require File.join(libdir, 'hoptoad_notifier')

if defined?(Merb::BootLoader)
Merb::BootLoader.after_app_loads do
HoptoadNotifier.configure
Merb::HoptoadNotifier.configure
end
end
74 changes: 43 additions & 31 deletions lib/merb_hoptoad_notifier/hoptoad_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
module HoptoadNotifier
class << self
attr_accessor :api_key, :logger
end
module Merb
module HoptoadNotifier
VERSION = '1.1.0'
class << self
attr_accessor :api_key, :logger, :environment_filters
end

def self.configure
key = YAML.load_file(Merb.root / 'config' / 'hoptoad.yml')
def self.configure
key = YAML.load_file(Merb.root / 'config' / 'hoptoad.yml')

if key
env = key[Merb.env.to_sym]
env ? @api_key = env[:api_key] : raise(ArgumentError, "No hoptoad key for Merb environment #{Merb.env}")
if key
env = key[Merb.env.to_sym]
env ? @api_key = env[:api_key] : raise(ArgumentError, "No hoptoad key for Merb environment #{Merb.env}")
end
end
end

def self.logger
@logger || Merb.logger
end
def self.environment_filters
@environment_filters ||= [ ]
end

def self.notify_hoptoad(request, session)
request.exceptions.each do |exception|
options = {
:api_key => HoptoadNotifier.api_key,
:url => "#{request.protocol}://#{request.host}#{request.path}",
:component => request.params['controller'],
:action => request.params['action'],
:request => request,
:framework_env => Merb.env,
:notifier_name => 'Merb::HoptoadNotifier',
:notifier_version => '1.0.10',
:session => session.to_hash
}
dispatcher.post!(exception, options, {'X-Hoptoad-Client-Name' => 'Merb::HoptoadNotifier'})
def self.environment_filters=(filters)
@environment_filters << filters
end
true
end

def self.dispatcher
@dispatcher ||= ToadHopper.new(api_key)
def self.logger
@logger || Merb.logger
end

def self.notify_hoptoad(request, session)
request.exceptions.each do |exception|
options = {
:api_key => HoptoadNotifier.api_key,
:url => "#{request.protocol}://#{request.host}#{request.path}",
:component => request.params['controller'],
:action => request.params['action'],
:request => request,
:framework_env => Merb.env,
:notifier_name => 'Merb::HoptoadNotifier',
:notifier_version => Merb::HoptoadNotifier::VERSION,
:session => session.to_hash
}
dispatcher.filters = environment_filters.flatten
dispatcher.post!(exception, options, {'X-Hoptoad-Client-Name' => 'Merb::HoptoadNotifier'})
end
true
end

def self.dispatcher
@dispatcher ||= ToadHopper.new(api_key)
end
end
end
4 changes: 2 additions & 2 deletions spec/merb_hoptoad_notifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
config = { :development => { :api_key=> ENV['MY_HOPTOAD_API_KEY'] || 'blah' } }
mock(YAML).load_file(File.join(Merb.root / 'config' / 'hoptoad.yml')) { config }

HoptoadNotifier.configure
Merb::HoptoadNotifier.configure
end
describe "notification" do
it "posts to hoptoad" do
HoptoadNotifier.notify_hoptoad(fake_request_with_exceptions, { :user_id => 42 })
Merb::HoptoadNotifier.notify_hoptoad(fake_request_with_exceptions, { :user_id => 42 })
end
end
end
Empty file removed spec/spec.opts
Empty file.

0 comments on commit 46059f0

Please sign in to comment.