jerk 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jerk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Corey Ward
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,26 @@
1
+ # Jerk
2
+
3
+ Jerk is insensitive, particularly about URL casing. It is middleware that prevents any uppercase
4
+ URLs from making it through in the path of a URL. The default mode is to issue 301 redirects to
5
+ a lowercase-normalized version of the requested URL. Query strings are left alone.
6
+
7
+ ## Installation & Usage
8
+
9
+ # Gemfile
10
+ gem 'jerk'
11
+
12
+ # Shell
13
+ $ bundle
14
+
15
+ On Rails? You're done. Not on Rails? Just add the middleware wherever you like:
16
+
17
+ use Jerk::Redirect
18
+ # or Jerk::Ignore if you don't want redirects
19
+
20
+ ## Contributing
21
+
22
+ 1. [Pork it](http://hotdogscoldbeer.com/austin/eats/)
23
+ 2. Create your feature branch (`git checkout -b say-do-you-want-to-catch-a-moooovie`)
24
+ 3. Commit your changes (`git commit -am 'Mah spoon is too big'`)
25
+ 4. Push to the branch (`git push origin i-am-a-banana`)
26
+ 5. Create new Pull-My-Finger Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/jerk.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jerk/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "jerk"
8
+ gem.version = Jerk::VERSION
9
+ gem.authors = ["Corey Ward"]
10
+ gem.email = ["corey.atx@gmail.com"]
11
+ gem.description = %q{Jerk is insensitive, particularly about URL casing.}
12
+ gem.summary = %q{Jerk is middleware that prevents any uppercase URLs from making it through in the path of a URL.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'rack'
21
+ end
@@ -0,0 +1,7 @@
1
+ module Jerk
2
+ class Railtie < Rails::Railtie
3
+ initializer "jerk.insert_middleware" do |app|
4
+ app.middleware.use "Jerk::Redirect"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Jerk
2
+ VERSION = "0.0.2"
3
+ end
data/lib/jerk.rb ADDED
@@ -0,0 +1,44 @@
1
+ require "jerk/version"
2
+
3
+ require 'jerk/railtie' if defined?(Rails)
4
+
5
+ module Jerk
6
+ module Base
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ @app.call(env)
13
+ end
14
+
15
+ def each(&block); end
16
+ end
17
+
18
+ ### DEFAULT
19
+ # Jerk::Redirect — issue a 301 redirect to the downcased version
20
+ class Redirect
21
+ include Base
22
+
23
+ def call(env)
24
+ path, query_string = env['PATH_INFO'].split('?')
25
+ if path[/[A-Z]/]
26
+ [301, { Location: [path.downcase, query_string].compact.join('?') }, self]
27
+ else
28
+ super
29
+ end
30
+ end
31
+ end
32
+
33
+ # Jerk::Ignore — Just downcase the URL for Rails without redirecting the user
34
+ class Ignore
35
+ include Base
36
+
37
+ def call(env)
38
+ env['PATH_INFO'].downcase!
39
+ super
40
+ end
41
+ end
42
+ end
43
+
44
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jerk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Corey Ward
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
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
+ description: Jerk is insensitive, particularly about URL casing.
31
+ email:
32
+ - corey.atx@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - LICENSE.txt
40
+ - README.md
41
+ - Rakefile
42
+ - jerk.gemspec
43
+ - lib/jerk.rb
44
+ - lib/jerk/railtie.rb
45
+ - lib/jerk/version.rb
46
+ homepage: ''
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.24
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Jerk is middleware that prevents any uppercase URLs from making it through
70
+ in the path of a URL.
71
+ test_files: []