rack_upstream_identification 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rob Ares
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.rdoc ADDED
@@ -0,0 +1,50 @@
1
+ = rack_upstream_identification
2
+
3
+ acts_as_filterable is an ActiveRecord plugin that was hacked together (originally a monkey patch) to avoid repeating the same text filtering logic that was re-implemented all over the place in a legacy domain model.
4
+
5
+ == Current filters in place:
6
+
7
+ * filter_for_digits: leaves only numeric values
8
+ * filter_for_uppercase: uppercase all alpha characters
9
+ * filter_for_lowercase: lowercase all alpha characters
10
+ * filter_for_whitespace: strips and non-essential whitespace out of a string (leaving only single whitespace characters).
11
+
12
+ Features I'd like to add in the future:
13
+ * User-defined custom filters configured via DSL.
14
+ * Additional macros that filter decimal values, etc.
15
+ * Allow the developer to opt-in models for filtering and not include
16
+ the plugin in ActiveRecord::Base
17
+
18
+ = Runtime Dependencies
19
+
20
+ * Rack 1.0.0+
21
+ * Tested against Ruby 1.8.6, 1.8.7, 1.9.1
22
+
23
+ = Install
24
+
25
+ == Rails
26
+
27
+ config.gem "acts_as_filterable", :source => "http://gemcutter.org"
28
+
29
+ == Bundler
30
+
31
+ source "http://gemcutter.org"
32
+ gem "acts_as_filterable", "0.2.0"
33
+
34
+ == RubyGems
35
+
36
+ gem install acts_as_filterable --source http://gemcutter.org
37
+
38
+ = Usage
39
+
40
+ class MyModel < ActiveRecord::Base
41
+ filter_for_digits :phone_number, :fax_number
42
+ end
43
+
44
+ = Contributing
45
+
46
+ If something is broken or you need a feature; you know the deal. Don't be part of the problem. Patches or pull requests are welcome.
47
+
48
+ == Copyright
49
+
50
+ Copyright (c) 2009 Rob Ares. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rake'
2
+
3
+ begin
4
+ require 'jeweler'
5
+ Jeweler::Tasks.new do |gem|
6
+ gem.name = "rack_upstream_identification"
7
+ gem.summary = %Q{Middleware that injects upstream server info into the response}
8
+ gem.description = %Q{Middleware that injects upstream server info into the response}
9
+ gem.email = "rob.ares@gmail.com"
10
+ gem.homepage = "http://github.com/rares/rack_upstream_identification"
11
+ gem.authors = ["Rob Ares"]
12
+ gem.add_runtime_dependency "rack", ">= 1.0"
13
+ gem.add_development_dependency "shoulda", ">= 2.10.2"
14
+ gem.add_development_dependency "rack-test", ">= 0.5.2"
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.options = "-v"
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = false
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "rack_upstream_identification #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
54
+
55
+ desc 'Removes trailing whitespace'
56
+ task :whitespace do
57
+ sh %{find . -name '*.rb' -exec sed -i '' 's/ *$//g' {} \\;}
58
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,56 @@
1
+ require "socket"
2
+
3
+ module Rack
4
+
5
+ # A middleware for injecting upstream host info into a response header.
6
+ class UpstreamIdentification
7
+
8
+ attr_reader :transform, :header_name
9
+
10
+ # Creates the middleware with the following configuration options:
11
+ #
12
+ # [\+header+] The name of the header that is sent to the client.
13
+ # Defaults to "X-Upstream-Identification"
14
+ #
15
+ # [\+blk+] The optional block used to transform a header. If
16
+ # a block is passed, the following applies:
17
+ # * The machine's hostname is passed to the block.
18
+ # This gives the block the opportunity to change
19
+ # how the hostname is rendered (obfuscate, mangle,
20
+ # whatever).
21
+ # * The block should return a string value that will
22
+ # be set as the configured header value.
23
+ #
24
+ # If no block is passed during configuration, just send
25
+ # the hostname as a default.
26
+ #
27
+ def initialize(app, header = "X-Upstream-Identification", &blk)
28
+ @app = app
29
+ @header_name = header
30
+ @transform = blk if block_given?
31
+ end
32
+
33
+ def call(env)
34
+ push_header @app.call(env)
35
+ end
36
+
37
+ private
38
+
39
+ # Push the configured header down to the client
40
+ def push_header(response)
41
+ response[1][header_name] = if transform
42
+ transform.call(host_name).to_s
43
+ else
44
+ host_name
45
+ end
46
+ response
47
+ end
48
+
49
+ # Get the hostname for the current machine
50
+ def host_name
51
+ @host_name ||= Socket.gethostname
52
+ end
53
+
54
+ end
55
+
56
+ end
@@ -0,0 +1,60 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rack_upstream_identification}
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 = ["Rob Ares"]
12
+ s.date = %q{2009-11-21}
13
+ s.description = %q{Middleware that injects upstream server info into the response}
14
+ s.email = %q{rob.ares@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "lib/rack/upstream_identification.rb",
27
+ "rack_upstream_identification.gemspec",
28
+ "test/helper.rb",
29
+ "test/test_rack_upstream_identification.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/rares/rack_upstream_identification}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.5}
35
+ s.summary = %q{Middleware that injects upstream server info into the response}
36
+ s.test_files = [
37
+ "test/helper.rb",
38
+ "test/test_rack_upstream_identification.rb"
39
+ ]
40
+
41
+ if s.respond_to? :specification_version then
42
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
+ s.add_runtime_dependency(%q<rack>, [">= 1.0"])
47
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.2"])
48
+ s.add_development_dependency(%q<rack-test>, [">= 0.5.2"])
49
+ else
50
+ s.add_dependency(%q<rack>, [">= 1.0"])
51
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
52
+ s.add_dependency(%q<rack-test>, [">= 0.5.2"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<rack>, [">= 1.0"])
56
+ s.add_dependency(%q<shoulda>, [">= 2.10.2"])
57
+ s.add_dependency(%q<rack-test>, [">= 0.5.2"])
58
+ end
59
+ end
60
+
data/test/helper.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "test/unit"
2
+ require "shoulda"
3
+
4
+ require "rack/test"
5
+
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
+ require "rack/upstream_identification"
9
+
10
+ class Test::Unit::TestCase
11
+ end
@@ -0,0 +1,115 @@
1
+ require "helper"
2
+ require "socket"
3
+ require "zlib"
4
+
5
+ class TestRackUpstreamIdentification < Test::Unit::TestCase
6
+ include Rack::Test::Methods
7
+
8
+ def app
9
+ handler = lambda { |env| [200, {"Content-Type" => "text/plain"}, ["OK"]] }
10
+ Rack::Builder.new do
11
+ map "/default" do
12
+ use Rack::UpstreamIdentification
13
+ run handler
14
+ end
15
+
16
+ map "/override_host" do
17
+ use Rack::UpstreamIdentification, "server_header"
18
+ run handler
19
+ end
20
+
21
+ map "/transform_block" do
22
+ use Rack::UpstreamIdentification do |host|
23
+ host.upcase
24
+ end
25
+ run handler
26
+ end
27
+
28
+ map "/both_options" do
29
+ use Rack::UpstreamIdentification, "crypted_header" do |host|
30
+ Zlib.crc32(host)
31
+ end
32
+ run handler
33
+ end
34
+ end.to_app
35
+ end
36
+
37
+ def assert_header_present(header)
38
+ assert last_response.headers.include? header
39
+ end
40
+
41
+ def assert_header_value(header, value)
42
+ assert_equal value, last_response.headers[header]
43
+ end
44
+
45
+ context "using the upstream identification handler" do
46
+
47
+ should "allow requests to flow through without issue" do
48
+ get "/default"
49
+ assert last_response.ok?
50
+ end
51
+
52
+ context "with the default configuration" do
53
+ setup do
54
+ get "/default"
55
+ end
56
+
57
+ should "push the header down using the default name" do
58
+ assert_header_present "X-Upstream-Identification"
59
+ end
60
+
61
+ should "push the header down using the machine's hostname" do
62
+ assert_header_value "X-Upstream-Identification", Socket.gethostname
63
+ end
64
+
65
+ end
66
+
67
+ context "with an overriding the header name" do
68
+ setup do
69
+ get "/override_host"
70
+ end
71
+
72
+ should "push the header down with the overriden name" do
73
+ assert_header_present "server_header"
74
+ end
75
+
76
+ should "push the header down using the machine's hostname" do
77
+ assert_header_value "server_header", Socket.gethostname
78
+ end
79
+
80
+ end
81
+
82
+ context "with a block to provide custom processing" do
83
+ setup do
84
+ get "/transform_block"
85
+ end
86
+
87
+ should "push the header down with the default header name" do
88
+ assert_header_present "X-Upstream-Identification"
89
+ end
90
+
91
+ should "push the header down using the transformed value" do
92
+ assert_header_value "X-Upstream-Identification", `hostname`.chomp.upcase
93
+ end
94
+
95
+ end
96
+
97
+ context "with the headername and transform block passed" do
98
+ setup do
99
+ get "/both_options"
100
+ end
101
+
102
+ should "push the header down with the overridden header name" do
103
+ assert_header_present "crypted_header"
104
+ end
105
+
106
+ should "push the header down using the crypted header value" do
107
+ assert_header_value "crypted_header", Zlib.crc32(Socket.gethostname).to_s
108
+ end
109
+
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_upstream_identification
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rob Ares
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-21 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: shoulda
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.10.2
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rack-test
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.5.2
44
+ version:
45
+ description: Middleware that injects upstream server info into the response
46
+ email: rob.ares@gmail.com
47
+ executables: []
48
+
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - LICENSE
53
+ - README.rdoc
54
+ files:
55
+ - .document
56
+ - .gitignore
57
+ - LICENSE
58
+ - README.rdoc
59
+ - Rakefile
60
+ - VERSION
61
+ - lib/rack/upstream_identification.rb
62
+ - rack_upstream_identification.gemspec
63
+ - test/helper.rb
64
+ - test/test_rack_upstream_identification.rb
65
+ has_rdoc: true
66
+ homepage: http://github.com/rares/rack_upstream_identification
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --charset=UTF-8
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: "0"
85
+ version:
86
+ requirements: []
87
+
88
+ rubyforge_project:
89
+ rubygems_version: 1.3.5
90
+ signing_key:
91
+ specification_version: 3
92
+ summary: Middleware that injects upstream server info into the response
93
+ test_files:
94
+ - test/helper.rb
95
+ - test/test_rack_upstream_identification.rb