hoover 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ ## Version 0.0.1 - Oct 22, 2011
2
+
3
+ * Initial release
4
+ * Hoover.add functionality is the core
5
+ * Includes LogSubscribers based on Rails 3 internal LogSubscribers
6
+ * Tested against a large Rails 3.0.9 app
7
+ * Should be considered alpha quality
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "minitest"
7
+ gem "bundler"
8
+ gem "jeweler", "~> 1.6.4"
9
+ gem "mocha"
10
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Gabe da Silveira
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ Hoover
2
+ ======
3
+
4
+ [![Build Status](https://secure.travis-ci.org/dasil003/hoover.png)](http://travis-ci.org/dasil003/hoover)
5
+
6
+ Hoover is the name of [Loggly](http://loggly.com)'s lovable and profane [mascot](http://www.facebook.com/hooverloggly). It is also the name of this Ruby library.
7
+
8
+ The purpose of this gem is to take advantage of Loggly's awesome JSON logging (see the [blog post](http://loggly.com/blog/2011/06/on-the-way-to-impressive/)). Why so awesome? Because instead of just logging strings, now you can push JSON data, and that data is then exposed to advanced search operations in Loggly's console. If you've ever spent any time grepping over gigabytes of logfiles to debug some issue or another the benefit of this should be immediately obvious.
9
+
10
+ Of course, the existing gem [logglier](https://github.com/freeformz/logglier) already supports pushing to the JSON API, so what's Hoover all about?
11
+
12
+ The foundation of Hoover is a hook into the request lifecycle, so that at the beginning of each request, an empty hash
13
+ is created which you can you can easily push data into to be logged. This is managed by a Rack middleware, guaranteeing
14
+ availability throughout the request, and also supplementing with some standard information.
15
+
16
+ If you are using Rails 3, then there are prewritten log subscribers that pass most of the information that is written to
17
+ the normal rails log in a simplified and convenient JSON format.
18
+
19
+
20
+ ## Installation
21
+
22
+ You're using bundler right?
23
+
24
+ gem 'hoover'
25
+
26
+
27
+ ## Rails Setup
28
+
29
+ When using Rails 3, the Railtie automatically sets up the Rack middleware, and the log subscribers. All you need to do
30
+ in this case is provide the configured logglier object. Currently this is done with a class method in your controller:
31
+
32
+ class ApplicationController < ActionController::Base
33
+ set_hoover_logglier $loggly
34
+ end
35
+
36
+ Where `$loggly` is an instance of the `Logglier` class that was set up previously. Soon I hope to have configuration
37
+ options so you can set this in your application.rb.
38
+
39
+
40
+ ## General Setup
41
+
42
+ For other Rack frameworks, you need to add the `Hoover::RackLogger` middleware to your stack. There is no automated
43
+ logging for any framework other than Rails 3.
44
+
45
+
46
+ ## Usage
47
+
48
+ Anywhere in your request you can now call:
49
+
50
+ Hoover.add(:key => 'data that converts nicely to json')
51
+
52
+ If you add with the same key more than once, Hoover automatically rolls it up into an array so you don't lose anything.
53
+
54
+
55
+ ## Todo
56
+
57
+ * Write tests for Rails components
58
+ * Provide config option to set the logglier during initialization
59
+ * Provide config option to choose which log subscribers to enable
60
+
61
+
62
+ ## Contributing to Hoover
63
+
64
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
65
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
66
+ * Fork the project
67
+ * Start a feature/bugfix branch
68
+ * Commit and push until you are happy with your contribution
69
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
70
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise
71
+ necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
72
+
73
+
74
+ ## Copyright
75
+
76
+ Copyright (c) 2011 Gabe da Silveira. See LICENSE.txt for further details.
77
+
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ # encoding: utf-8
2
+
3
+ require 'bundler'
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+
13
+ require 'jeweler'
14
+ Jeweler::Tasks.new do |gem|
15
+ gem.name = "hoover"
16
+ gem.homepage = "http://github.com/dasil003/hoover"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Rack-based support for collecting a single hash per request to be sent to Loggly}
19
+ gem.description = %Q{Sets up a hash at the beginning of each request and flushes it to Loggly at the end of the request. Also comes with standard Rails 3 log subscribers.}
20
+ gem.email = "gabe@websaviour.com"
21
+ gem.authors = ["Gabe da Silveira"]
22
+
23
+ gem.add_dependency "logglier", "~> 0.2.6"
24
+ end
25
+ Jeweler::RubygemsDotOrgTasks.new
26
+
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new do |t|
30
+ t.libs << "spec"
31
+ t.pattern = "spec/*_spec.rb"
32
+ end
33
+
34
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
data/hoover.gemspec ADDED
@@ -0,0 +1,97 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{hoover}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = [%q{Gabe da Silveira}]
12
+ s.date = %q{2011-10-22}
13
+ s.description = %q{Sets up a hash at the beginning of each request and flushes it to Loggly at the end of the request. Also comes with standard Rails 3 log subscribers.}
14
+ s.email = %q{gabe@websaviour.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".travis.yml",
22
+ "CHANGELOG.md",
23
+ "Gemfile",
24
+ "LICENSE.txt",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "hoover.gemspec",
29
+ "lib/hoover.rb",
30
+ "lib/hoover/action_controller_methods.rb",
31
+ "lib/hoover/job.rb",
32
+ "lib/hoover/log_subscribers/action_controller_log_subscriber.rb",
33
+ "lib/hoover/log_subscribers/action_mailer_log_subscriber.rb",
34
+ "lib/hoover/log_subscribers/action_view_log_subscriber.rb",
35
+ "lib/hoover/log_subscribers/active_record_log_subscriber.rb",
36
+ "lib/hoover/log_subscribers/active_resource_log_subscriber.rb",
37
+ "lib/hoover/rack_logger.rb",
38
+ "lib/hoover/railtie.rb",
39
+ "spec/helper.rb",
40
+ "spec/hoover_spec.rb",
41
+ "spec/job_spec.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/dasil003/hoover}
44
+ s.licenses = [%q{MIT}]
45
+ s.require_paths = [%q{lib}]
46
+ s.rubygems_version = %q{1.8.6}
47
+ s.summary = %q{Rack-based support for collecting a single hash per request to be sent to Loggly}
48
+
49
+ if s.respond_to? :specification_version then
50
+ s.specification_version = 3
51
+
52
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
+ s.add_runtime_dependency(%q<hoover>, [">= 0"])
54
+ s.add_development_dependency(%q<minitest>, [">= 0"])
55
+ s.add_development_dependency(%q<bundler>, [">= 0"])
56
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
57
+ s.add_development_dependency(%q<minitest>, [">= 0"])
58
+ s.add_development_dependency(%q<bundler>, [">= 0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
60
+ s.add_development_dependency(%q<mocha>, [">= 0"])
61
+ s.add_development_dependency(%q<minitest>, [">= 0"])
62
+ s.add_development_dependency(%q<bundler>, [">= 0"])
63
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
64
+ s.add_development_dependency(%q<mocha>, [">= 0"])
65
+ s.add_runtime_dependency(%q<logglier>, ["~> 0.2.6"])
66
+ else
67
+ s.add_dependency(%q<hoover>, [">= 0"])
68
+ s.add_dependency(%q<minitest>, [">= 0"])
69
+ s.add_dependency(%q<bundler>, [">= 0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
71
+ s.add_dependency(%q<minitest>, [">= 0"])
72
+ s.add_dependency(%q<bundler>, [">= 0"])
73
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
74
+ s.add_dependency(%q<mocha>, [">= 0"])
75
+ s.add_dependency(%q<minitest>, [">= 0"])
76
+ s.add_dependency(%q<bundler>, [">= 0"])
77
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
78
+ s.add_dependency(%q<mocha>, [">= 0"])
79
+ s.add_dependency(%q<logglier>, ["~> 0.2.6"])
80
+ end
81
+ else
82
+ s.add_dependency(%q<hoover>, [">= 0"])
83
+ s.add_dependency(%q<minitest>, [">= 0"])
84
+ s.add_dependency(%q<bundler>, [">= 0"])
85
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
86
+ s.add_dependency(%q<minitest>, [">= 0"])
87
+ s.add_dependency(%q<bundler>, [">= 0"])
88
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
89
+ s.add_dependency(%q<mocha>, [">= 0"])
90
+ s.add_dependency(%q<minitest>, [">= 0"])
91
+ s.add_dependency(%q<bundler>, [">= 0"])
92
+ s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
93
+ s.add_dependency(%q<mocha>, [">= 0"])
94
+ s.add_dependency(%q<logglier>, ["~> 0.2.6"])
95
+ end
96
+ end
97
+
@@ -0,0 +1,9 @@
1
+ module Hoover
2
+ module ActionControllerMethods
3
+ def set_hoover_logglier(logglier)
4
+ before_filter { Hoover.logglier = logglier }
5
+ end
6
+ end
7
+ end
8
+
9
+ ActionController::Base.extend(Hoover::ActionControllerMethods)
data/lib/hoover/job.rb ADDED
@@ -0,0 +1,31 @@
1
+ module Hoover
2
+ class Job
3
+ attr_writer :logglier
4
+ attr_reader :hash
5
+
6
+ def initialize(logglier = nil)
7
+ @logglier = logglier
8
+ @hash = {}
9
+ end
10
+
11
+ def add(hash)
12
+ hash.each do |k,v|
13
+ if @hash.key?(k)
14
+ @hash[k] << v
15
+ else
16
+ @hash[k] = [v]
17
+ end
18
+ end
19
+ end
20
+
21
+ def ready_to_post?
22
+ ! @logglier.nil?
23
+ end
24
+
25
+ def post
26
+ raise "cannot post until logglier is set" unless ready_to_post?
27
+ @hash.each{ |k,v| @hash[k] = @hash[k].first if v.size == 1 }
28
+ @logglier.info(@hash)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,52 @@
1
+ module Hoover
2
+ class ActionControllerLogSubscriber < ActiveSupport::LogSubscriber
3
+ INTERNAL_PARAMS = %w(controller action format _method only_path)
4
+
5
+ def start_processing(event)
6
+ payload = event.payload
7
+ params = payload[:params].except(*INTERNAL_PARAMS)
8
+
9
+ Hoover.add(:controller => payload[:controller],
10
+ :action => payload[:action],
11
+ :params => params,
12
+ :format => payload[:formats].first.to_s.upcase)
13
+ end
14
+
15
+ def process_action(event)
16
+ payload = event.payload
17
+ additions = ActionController::Base.log_process_action(payload)
18
+
19
+ status = payload[:status]
20
+ if status.nil? && payload[:exception].present?
21
+ status = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[payload[:exception].first]) rescue nil
22
+ end
23
+
24
+ Hoover.add(:status => "#{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}",
25
+ :duration => "%.0f" % event.duration)
26
+ Hoover.add :additions => additions.join(" | ") unless additions.blank?
27
+ end
28
+
29
+ def send_file(event)
30
+ Hoover.add(:sent_file, "%s (%.1fms)" % [event.payload[:path], event.duration])
31
+ end
32
+
33
+ def redirect_to(event)
34
+ Hoover.add(:redirected_to, event.payload[:location])
35
+ end
36
+
37
+ def send_data(event)
38
+ Hoover.add(:sent_data, "%s (%.1fms)" % [event.payload[:filename], event.duration])
39
+ end
40
+
41
+ %w(write_fragment read_fragment exist_fragment?
42
+ expire_fragment expire_page write_page).each do |method|
43
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
44
+ def #{method}(event)
45
+ key_or_path = event.payload[:key] || event.payload[:path]
46
+ human_name = #{method.to_s.humanize.inspect}
47
+ Hoover.add(method.to_sym, "\#{key_or_path} (%.1fms)" % event.duration)
48
+ end
49
+ METHOD
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ module Hoover
2
+ class ActionMailerLogSubscriber < ActiveSupport::LogSubscriber
3
+ def deliver(event)
4
+ recipients = Array.wrap(event.payload[:to])
5
+ Hoover.add(:sent_mail_to, recipients)
6
+ Hoover.add(:sent_mail_duration, "%1.f" % event.duration)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ module Hoover
2
+ class ActionViewLogSubscriber < ActiveSupport::LogSubscriber
3
+ def render_template(event)
4
+ rendered = { :identifier => from_rails_root(event.payload[:identifier]),
5
+ :duration => event.duration }
6
+ rendered[:layout] = from_rails_root(event.payload[:layout]) if event.payload[:layout]
7
+
8
+ Hoover.add :rendered => rendered
9
+ end
10
+ alias :render_partial :render_template
11
+ alias :render_collection :render_template
12
+
13
+ protected
14
+
15
+ def from_rails_root(string)
16
+ string.sub("#{Rails.root}/", "").sub(/^app\/views\//, "")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Hoover
2
+ class ActiveRecordLogSubscriber < ActiveSupport::LogSubscriber
3
+ # I have no need to log this to Loggly, implementations welcome.
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ module Hoover
2
+ class ActiveResourceLogSubscriber < ActiveSupport::LogSubscriber
3
+ def request(event)
4
+ result = event.payload[:result]
5
+ request = { :method => event.payload[:method].to_s.upcase,
6
+ :request_uri => event.payload[:request_uri],
7
+ :result_code => result.code,
8
+ :result_message => result.message,
9
+ :result_length => result.body.to_s.length,
10
+ :duration => event.duration }
11
+ Hoover.add(:active_resource_request => request)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ module Hoover
2
+ class RackLogger
3
+ def initialize(app, logglier = nil)
4
+ @logglier = logglier
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ before_dispatch(env)
10
+ @app.call(env)
11
+ ensure
12
+ after_dispatch(env)
13
+ end
14
+
15
+ protected
16
+
17
+ def before_dispatch(env)
18
+ Hoover.init @logglier
19
+
20
+ if defined? ActionDispatch::Request
21
+ request = ActionDispatch::Request.new(env)
22
+ Hoover.add :method => request.request_method,
23
+ :path => request.filtered_path
24
+ else
25
+ Hoover.add env
26
+ end
27
+
28
+ Hoover.add :ip => request.ip,
29
+ :started_at => Time.now.utc
30
+ end
31
+
32
+ def after_dispatch(env)
33
+ Hoover.flush
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ module Hoover
2
+ autoload :ActionControllerLogSubscriber, 'hoover/log_subscribers/action_controller_log_subscriber'
3
+ autoload :ActionMailerLogSubscriber, 'hoover/log_subscribers/action_mailer_log_subscriber'
4
+ autoload :ActionViewLogSubscriber, 'hoover/log_subscribers/action_view_log_subscriber'
5
+ autoload :ActiveResourceLogSubscriber, 'hoover/log_subscribers/active_resource_log_subscriber'
6
+ autoload :ActiveRecordLogSubscriber, 'hoover/log_subscribers/active_record_log_subscriber'
7
+
8
+ class Railtie < Rails::Railtie
9
+ def self.all_rails_log_subscribers
10
+ [:action_controller, :action_mailer, :action_view, :active_resource, :active_record]
11
+ end
12
+
13
+ config.hoover = ActiveSupport::OrderedOptions.new
14
+ config.hoover.log_subscribers = all_rails_log_subscribers
15
+
16
+ initializer "hoover.add_rack_logger" do |app|
17
+ app.middleware.insert_after Rails::Rack::Logger, Hoover::RackLogger
18
+ end
19
+
20
+ initializer "hoover.attach_log_subscribers" do |app|
21
+ app.config.hoover.log_subscribers.each do |mod|
22
+ "Hoover::#{mod.to_s.camelize}LogSubscriber".constantize.attach_to mod
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ require 'hoover/action_controller_methods'
data/lib/hoover.rb ADDED
@@ -0,0 +1,42 @@
1
+ require 'hoover/rack_logger'
2
+ require 'hoover/job'
3
+ require 'hoover/railtie' if defined?(Rails)
4
+
5
+ module Hoover
6
+ class << self
7
+ def init(logglier = nil)
8
+ self.active_job = Job.new(logglier)
9
+ end
10
+
11
+ def reset!
12
+ self.active_job = nil
13
+ end
14
+
15
+ def add(*args)
16
+ raise "Must init Hoover before calling add" unless active_job
17
+ active_job.add(*args)
18
+ end
19
+
20
+ def logglier=(logglier)
21
+ raise "Must init Hoover before setting logglier" unless active_job
22
+ active_job.logglier = logglier
23
+ end
24
+
25
+ def flush
26
+ raise "Hoover.logglier must be set before calling flush" unless active_job.ready_to_post?
27
+
28
+ active_job.post
29
+ reset!
30
+ end
31
+
32
+ private
33
+
34
+ def active_job=(val)
35
+ Thread.current[:active_hoover_job] = val
36
+ end
37
+
38
+ def active_job
39
+ Thread.current[:active_hoover_job]
40
+ end
41
+ end
42
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'mocha'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ require 'hoover'
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ describe Hoover do
4
+ after { Hoover.reset! }
5
+
6
+ describe "unitialized" do
7
+ it "should not allow add" do
8
+ proc{ Hoover.add(:key => 'val') }.must_raise RuntimeError, "Must init Hoover before calling add"
9
+ end
10
+
11
+ it "should not allow setting logglier" do
12
+ proc{ Hoover.logglier = nil }.must_raise RuntimeError, "Must init Hoover before setting logglier"
13
+ end
14
+ end
15
+
16
+ describe "initialized wo logglier" do
17
+ before { Hoover.init }
18
+
19
+ it "should allow add" do
20
+ Hoover::Job.any_instance.expects(:add).with({})
21
+ Hoover.add({})
22
+ end
23
+
24
+ it "should allow setting logglier" do
25
+ logglier = Object.new
26
+ (Hoover.logglier = logglier).must_equal logglier
27
+ end
28
+
29
+ it "should not allow flushing" do
30
+ proc{ Hoover.flush }.must_raise RuntimeError, "Hoover.logglier must be set before calling flush"
31
+ end
32
+ end
33
+
34
+ describe "initialized with logglier" do
35
+ before do
36
+ @logglier = Object.new
37
+ Hoover.init(@logglier)
38
+ end
39
+
40
+ it "should allow add" do
41
+ Hoover::Job.any_instance.expects(:add).with({})
42
+ Hoover.add({})
43
+ end
44
+
45
+ it "should allow setting logglier" do
46
+ logglier = Object.new
47
+ (Hoover.logglier = logglier).must_equal logglier
48
+ end
49
+
50
+ it "should allow flush" do
51
+ Hoover::Job.any_instance.expects(:post)
52
+ Hoover.flush
53
+ end
54
+ end
55
+ end
data/spec/job_spec.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'helper'
2
+
3
+ describe Hoover::Job do
4
+ before do
5
+ @logglier = Object.new
6
+ @job = Hoover::Job.new(@logglier)
7
+ end
8
+
9
+ describe "adding one item" do
10
+ before { @job.add(:foo => 'bar') }
11
+
12
+ it "populates the hash" do
13
+ @job.hash.must_equal :foo => ['bar']
14
+ end
15
+
16
+ it "wraps the single item in an array" do
17
+ @job.hash[:foo].must_be_instance_of Array
18
+ end
19
+ end
20
+
21
+ describe "adding multiple keys" do
22
+ before do
23
+ @job.add(:foo => 'bar')
24
+ @job.add(:bar => 'baz')
25
+ end
26
+
27
+ it "saves both keys" do
28
+ @job.hash.must_equal :foo => ['bar'], :bar => ['baz']
29
+ end
30
+ end
31
+
32
+ describe "adding repeating keys" do
33
+ before do
34
+ @job.add(:foo => 'bar')
35
+ @job.add(:foo => 'baz')
36
+ end
37
+
38
+ it "appends to the array" do
39
+ @job.hash.must_equal :foo => ['bar', 'baz']
40
+ end
41
+ end
42
+
43
+ describe "adding an array" do
44
+ before do
45
+ @job.add(:foo => ['bar', 'baz'])
46
+ end
47
+
48
+ it "wraps with an outer array" do
49
+ @job.hash.must_equal :foo => [['bar', 'baz']]
50
+ end
51
+ end
52
+
53
+ describe "with singular and multiple keys" do
54
+ before do
55
+ @job.add(:string => 'string', :array => %w(a r r a y), :hash => {:foo => 'bar'},
56
+ :strings => 'string1', :arrays => %w(a ray), :hashes => {:bar => 'baz'})
57
+ @job.add(:strings => 'string2', :arrays => %w(another ray), :hashes => {:baz => 'boom'})
58
+ end
59
+
60
+ it "unwraps them before posting" do
61
+ expected = { :string => 'string',
62
+ :strings => ['string1', 'string2'],
63
+ :array => ['a', 'r', 'r', 'a', 'y'],
64
+ :arrays => [['a', 'ray'], ['another', 'ray']],
65
+ :hash => {:foo => 'bar'},
66
+ :hashes => [{:bar => 'baz'}, {:baz => 'boom'}] }
67
+ @logglier.expects(:info).with(expected)
68
+ @job.post
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoover
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gabe da Silveira
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-10-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hoover
16
+ requirement: &70125973944240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70125973944240
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
27
+ requirement: &70125973942960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70125973942960
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70125973941140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70125973941140
47
+ - !ruby/object:Gem::Dependency
48
+ name: jeweler
49
+ requirement: &70125973940420 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 1.6.4
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70125973940420
58
+ - !ruby/object:Gem::Dependency
59
+ name: minitest
60
+ requirement: &70125973937200 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70125973937200
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70125973935440 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70125973935440
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70125973934320 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.6.4
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70125973934320
91
+ - !ruby/object:Gem::Dependency
92
+ name: mocha
93
+ requirement: &70125973933000 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *70125973933000
102
+ - !ruby/object:Gem::Dependency
103
+ name: minitest
104
+ requirement: &70125973931780 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *70125973931780
113
+ - !ruby/object:Gem::Dependency
114
+ name: bundler
115
+ requirement: &70125973930200 !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ type: :development
122
+ prerelease: false
123
+ version_requirements: *70125973930200
124
+ - !ruby/object:Gem::Dependency
125
+ name: jeweler
126
+ requirement: &70125973929040 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ~>
130
+ - !ruby/object:Gem::Version
131
+ version: 1.6.4
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *70125973929040
135
+ - !ruby/object:Gem::Dependency
136
+ name: mocha
137
+ requirement: &70125973927380 !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ type: :development
144
+ prerelease: false
145
+ version_requirements: *70125973927380
146
+ - !ruby/object:Gem::Dependency
147
+ name: logglier
148
+ requirement: &70125973926280 !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ~>
152
+ - !ruby/object:Gem::Version
153
+ version: 0.2.6
154
+ type: :runtime
155
+ prerelease: false
156
+ version_requirements: *70125973926280
157
+ description: Sets up a hash at the beginning of each request and flushes it to Loggly
158
+ at the end of the request. Also comes with standard Rails 3 log subscribers.
159
+ email: gabe@websaviour.com
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files:
163
+ - LICENSE.txt
164
+ - README.md
165
+ files:
166
+ - .document
167
+ - .travis.yml
168
+ - CHANGELOG.md
169
+ - Gemfile
170
+ - LICENSE.txt
171
+ - README.md
172
+ - Rakefile
173
+ - VERSION
174
+ - hoover.gemspec
175
+ - lib/hoover.rb
176
+ - lib/hoover/action_controller_methods.rb
177
+ - lib/hoover/job.rb
178
+ - lib/hoover/log_subscribers/action_controller_log_subscriber.rb
179
+ - lib/hoover/log_subscribers/action_mailer_log_subscriber.rb
180
+ - lib/hoover/log_subscribers/action_view_log_subscriber.rb
181
+ - lib/hoover/log_subscribers/active_record_log_subscriber.rb
182
+ - lib/hoover/log_subscribers/active_resource_log_subscriber.rb
183
+ - lib/hoover/rack_logger.rb
184
+ - lib/hoover/railtie.rb
185
+ - spec/helper.rb
186
+ - spec/hoover_spec.rb
187
+ - spec/job_spec.rb
188
+ homepage: http://github.com/dasil003/hoover
189
+ licenses:
190
+ - MIT
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ none: false
197
+ requirements:
198
+ - - ! '>='
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ segments:
202
+ - 0
203
+ hash: -2345653166920222009
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ none: false
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 1.8.6
213
+ signing_key:
214
+ specification_version: 3
215
+ summary: Rack-based support for collecting a single hash per request to be sent to
216
+ Loggly
217
+ test_files: []