fozzie_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ .rvmrc
20
+ log/*
data/.rvmrc.example ADDED
@@ -0,0 +1 @@
1
+ rvm use --create 1.9.3@fozzie_rails
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,8 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :cli => "--color" do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Marc Watts
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # fozzie_rails [![travis-ci](https://secure.travis-ci.org/lonelyplanet/fozzie_rails.png)](https://secure.travis-ci.org/lonelyplanet/fozzie_rails)
2
+
3
+ Rails middleware for timing controller actions.
4
+
5
+ See [Fozzie](http://github.com/lonelyplanet/fozzie) for full details on what Fozzie does and how.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'fozzie_rails'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fozzie_rails
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/fozzie/rails/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Marc Watts"]
6
+ gem.email = ["marc.watts@lonelyplanet.co.uk"]
7
+ gem.summary = %q{Ruby gem from Lonely Planet Online to register statistics in Rails}
8
+ gem.description = %q{Gem to make statistics sending from Rails applications simple and efficient as possible}
9
+ gem.homepage = "http://devops.lonelyplanet.com"
10
+ gem.files = `git ls-files`.split($\)
11
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
+ gem.test_files = gem.files.grep(%r{^(spec|features)/})
13
+ gem.name = "fozzie_rails"
14
+ gem.require_paths = ["lib"]
15
+ gem.version = Fozzie::Rails::VERSION
16
+
17
+ gem.rubyforge_project = "fozzie_rails"
18
+
19
+ gem.add_dependency 'fozzie'
20
+
21
+ gem.add_development_dependency 'rake'
22
+ gem.add_development_dependency 'rspec'
23
+ gem.add_development_dependency 'guard'
24
+ gem.add_development_dependency 'guard-rspec'
25
+ gem.add_development_dependency 'rb-fsevent'
26
+
27
+ gem.add_development_dependency 'activesupport'
28
+ gem.add_development_dependency 'actionpack'
29
+ gem.add_development_dependency 'railties'
30
+ gem.add_development_dependency 'tzinfo'
31
+ end
@@ -0,0 +1,37 @@
1
+ require 'fozzie_rails'
2
+ require 'fozzie/rack/middleware'
3
+
4
+ module Fozzie
5
+ module Rails
6
+ # Time and record each request through a given Rails app
7
+ # This middlewware times server processing for a resource, not view render.
8
+ class Middleware < Fozzie::Rack::Middleware
9
+
10
+ # Generates the statistics key for the current path
11
+ def generate_key(env)
12
+ path_str, request_method = env['PATH_INFO'], env['REQUEST_METHOD']
13
+
14
+ return nil unless path_str
15
+
16
+ begin
17
+ routing = routing_lookup
18
+ path = routing.recognize_path(path_str, :method => request_method)
19
+ stat = [path[:controller], path[:action], "render"].join('.')
20
+ stat
21
+ rescue => exc
22
+ S.increment "routing.error"
23
+ nil
24
+ end
25
+ end
26
+
27
+ def routing_lookup
28
+ (rails_version >= 3 ? ::Rails.application.routes : ::ActionController::Routing::Routes)
29
+ end
30
+
31
+ def rails_version
32
+ ::Rails.version.to_i
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ require 'fozzie/rails/middleware'
2
+
3
+ module Fozzie
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+
7
+ initializer "fozzie_railtie.configure_rails_initialization" do |app|
8
+ app.middleware.use Fozzie::Rails::Middleware
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Fozzie
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'fozzie'
2
+ require 'fozzie/rails/railtie' if defined?(::Rails)
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ # Mock this out for Rails 2
4
+ module ActionController::Routing
5
+ class Routes; end
6
+ end
7
+
8
+ module Fozzie::Rails
9
+ describe Middleware do
10
+ subject { Middleware.new({}) }
11
+
12
+ describe "#rails_version" do
13
+
14
+ it "returns the major version from Rails.version" do
15
+ subject.rails_version.should be_kind_of(Integer)
16
+ end
17
+ end
18
+
19
+ describe "#routing_lookup" do
20
+
21
+ it "returns ::ActionDispatch::Routing::RouteSet instance for Rails 3 and up" do
22
+ subject.routing_lookup.should be_kind_of(::ActionDispatch::Routing::RouteSet)
23
+ end
24
+
25
+ it "returns ActionController::Routing::Routes instance for Rails 2" do
26
+ ::Rails.should_receive(:version).and_return(2)
27
+ subject.routing_lookup.should eq ::ActionController::Routing::Routes
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "#generate_key" do
33
+ let(:env) { mock "env" }
34
+ let(:path) { mock "path" }
35
+ let(:routes) { mock 'routes' }
36
+ subject { Middleware.new({}) }
37
+
38
+ it "gets the path_info and request method from env parameter" do
39
+ env.should_receive(:[]).with("PATH_INFO")
40
+ env.should_receive(:[]).with("REQUEST_METHOD")
41
+
42
+ subject.generate_key(env)
43
+ end
44
+
45
+ context "when path_info is nil" do
46
+ let(:env) { { "PATH_INFO" => nil } }
47
+
48
+ it "does not lookup routing" do
49
+ subject.should_receive(:routing_lookup).never
50
+
51
+ subject.generate_key(env)
52
+ end
53
+
54
+ it "does not register any stats" do
55
+ S.should_receive(:increment).never
56
+ end
57
+
58
+ it "returns nil" do
59
+ subject.generate_key(env).should be_nil
60
+ end
61
+ end
62
+
63
+ context "when path info is not nil" do
64
+ let(:env) { { "PATH_INFO" => path, "REQUEST_METHOD" => 'generate_key' } }
65
+
66
+ before do
67
+ subject.stub(:routing_lookup => routes)
68
+ routes.stub(:recognize_path => {:controller => "controller",:action => "action" })
69
+ end
70
+
71
+ it "looks up controller and action for the path and request method" do
72
+ subject.should_receive(:routing_lookup).and_return(routes)
73
+ routes.should_receive(:recognize_path).with(path, :method => 'generate_key')
74
+
75
+ subject.generate_key(env)
76
+ end
77
+
78
+ it "returns a bucket generated from the controller, action, and 'render'" do
79
+ subject.generate_key(env).should eq "controller.action.render"
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ module Fozzie::Rails
4
+ describe Railtie do
5
+
6
+ it "is loaded when Rails exists" do
7
+ Application.middleware.middlewares.should include(Fozzie::Rails::Middleware)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift File.expand_path('lib')
2
+
3
+ require 'rails/all'
4
+
5
+ module Fozzie
6
+ module Rails
7
+ class Application < ::Rails::Application; end
8
+ end
9
+ end
10
+
11
+ Fozzie::Rails::Application.configure do
12
+ config.active_support.deprecation = :log
13
+ end
14
+
15
+ require 'fozzie_rails'
16
+
17
+ RSpec.configure do |config|
18
+ config.order = :random
19
+ config.before(:suite) { Fozzie::Rails::Application.initialize! }
20
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fozzie_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marc Watts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: fozzie
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: guard-rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rb-fsevent
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: activesupport
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: actionpack
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: railties
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: tzinfo
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ description: Gem to make statistics sending from Rails applications simple and efficient
175
+ as possible
176
+ email:
177
+ - marc.watts@lonelyplanet.co.uk
178
+ executables: []
179
+ extensions: []
180
+ extra_rdoc_files: []
181
+ files:
182
+ - .gitignore
183
+ - .rvmrc.example
184
+ - .travis.yml
185
+ - Gemfile
186
+ - Guardfile
187
+ - LICENSE
188
+ - README.md
189
+ - Rakefile
190
+ - fozzie_rails.gemspec
191
+ - lib/fozzie/rails/middleware.rb
192
+ - lib/fozzie/rails/railtie.rb
193
+ - lib/fozzie/rails/version.rb
194
+ - lib/fozzie_rails.rb
195
+ - spec/lib/fozzie/rails/middleware_spec.rb
196
+ - spec/lib/fozzie/rails/railtie_spec.rb
197
+ - spec/spec_helper.rb
198
+ homepage: http://devops.lonelyplanet.com
199
+ licenses: []
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ none: false
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ segments:
211
+ - 0
212
+ hash: 1083775784506401853
213
+ required_rubygems_version: !ruby/object:Gem::Requirement
214
+ none: false
215
+ requirements:
216
+ - - ! '>='
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ segments:
220
+ - 0
221
+ hash: 1083775784506401853
222
+ requirements: []
223
+ rubyforge_project: fozzie_rails
224
+ rubygems_version: 1.8.24
225
+ signing_key:
226
+ specification_version: 3
227
+ summary: Ruby gem from Lonely Planet Online to register statistics in Rails
228
+ test_files:
229
+ - spec/lib/fozzie/rails/middleware_spec.rb
230
+ - spec/lib/fozzie/rails/railtie_spec.rb
231
+ - spec/spec_helper.rb