rackif 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/Manifest +6 -0
- data/README +12 -0
- data/Rakefile +16 -0
- data/config.ru +11 -0
- data/lib/if.rb +51 -0
- data/lib/rackif.rb +1 -0
- data/rackif.gemspec +33 -0
- metadata +77 -0
data/Manifest
ADDED
data/README
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Use or don't use rack apps based on a variety of environment variables.
|
2
|
+
|
3
|
+
Example:
|
4
|
+
use Rack::If, :path => '/protected', :method => /get/i do
|
5
|
+
use Rack::Auth::Basic, "Rack::If Example" do |username, password|
|
6
|
+
'secret' == password
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
Options available are: path, method, user_agent, host, port, query_string, http_accept, and http_accept_encoding.
|
11
|
+
|
12
|
+
Values given can be strings or regex (=== used for comparison).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
|
6
|
+
Echoe.new('rackif', '0.0.1') do |p|
|
7
|
+
p.summary = "Conditional use of rack apps"
|
8
|
+
p.description = "Use or don't use Rack apps based on a variety of environment factors."
|
9
|
+
# p.url = "http://samsm.com/"
|
10
|
+
# p.author = "Sam Schenkman-Moore"
|
11
|
+
# p.email = "samsm@samsm.com"
|
12
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
13
|
+
p.runtime_dependencies = ['rack']
|
14
|
+
end
|
15
|
+
|
16
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
data/config.ru
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack'
|
3
|
+
require 'lib/rackif'
|
4
|
+
|
5
|
+
use Rack::If, :path => '/protected', :method => 'GET' do
|
6
|
+
use Rack::Auth::Basic, "Rack::If Example" do |username, password|
|
7
|
+
'secret' == password
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
run lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'Hi'] }
|
data/lib/if.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
class Rack::If
|
2
|
+
|
3
|
+
attr_reader :app
|
4
|
+
|
5
|
+
def initialize(app, options={}, &block)
|
6
|
+
@options = options
|
7
|
+
@app = app
|
8
|
+
|
9
|
+
@middleware = []
|
10
|
+
instance_eval(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def match?(env)
|
14
|
+
@options.inject(true) do |memo, pair|
|
15
|
+
if_key = pair[0]
|
16
|
+
rack_key = comparison_table[if_key]
|
17
|
+
if_value = pair[1]
|
18
|
+
memo && if_value === env[rack_key]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def comparison_table
|
23
|
+
{
|
24
|
+
:path => "PATH_INFO",
|
25
|
+
:method => "REQUEST_METHOD",
|
26
|
+
:user_agent => "HTTP_USER_AGENT",
|
27
|
+
:host => "HTTP_HOST",
|
28
|
+
:port => "SERVER_PORT",
|
29
|
+
:query_string => "QUERY_STRING",
|
30
|
+
:http_accept => "HTTP_ACCEPT",
|
31
|
+
:http_accept_encoding => "HTTP_ACCEPT_ENCODING"
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def call(env)
|
36
|
+
if match?(env)
|
37
|
+
stack.call(env)
|
38
|
+
else
|
39
|
+
app.call(env)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def stack
|
44
|
+
@middleware.reverse.inject(app) { |app, mid| mid.call(app) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def use(middleware, *args, &block)
|
48
|
+
@middleware << lambda { |app| middleware.new(app, *args, &block) }
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
data/lib/rackif.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/if'
|
data/rackif.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{rackif}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = [""]
|
9
|
+
s.date = %q{2009-11-13}
|
10
|
+
s.description = %q{Use or don't use Rack apps based on a variety of environment factors.}
|
11
|
+
s.email = %q{}
|
12
|
+
s.extra_rdoc_files = ["README", "lib/if.rb", "lib/rackif.rb"]
|
13
|
+
s.files = ["Manifest", "README", "Rakefile", "config.ru", "lib/if.rb", "lib/rackif.rb", "rackif.gemspec"]
|
14
|
+
s.homepage = %q{}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Rackif", "--main", "README"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{rackif}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Conditional use of rack apps}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<rack>, [">= 0"])
|
27
|
+
else
|
28
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
29
|
+
end
|
30
|
+
else
|
31
|
+
s.add_dependency(%q<rack>, [">= 0"])
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rackif
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ""
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-13 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: "0"
|
24
|
+
version:
|
25
|
+
description: Use or don't use Rack apps based on a variety of environment factors.
|
26
|
+
email: ""
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- lib/if.rb
|
34
|
+
- lib/rackif.rb
|
35
|
+
files:
|
36
|
+
- Manifest
|
37
|
+
- README
|
38
|
+
- Rakefile
|
39
|
+
- config.ru
|
40
|
+
- lib/if.rb
|
41
|
+
- lib/rackif.rb
|
42
|
+
- rackif.gemspec
|
43
|
+
has_rdoc: true
|
44
|
+
homepage: ""
|
45
|
+
licenses: []
|
46
|
+
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options:
|
49
|
+
- --line-numbers
|
50
|
+
- --inline-source
|
51
|
+
- --title
|
52
|
+
- Rackif
|
53
|
+
- --main
|
54
|
+
- README
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
version:
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "1.2"
|
68
|
+
version:
|
69
|
+
requirements: []
|
70
|
+
|
71
|
+
rubyforge_project: rackif
|
72
|
+
rubygems_version: 1.3.5
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Conditional use of rack apps
|
76
|
+
test_files: []
|
77
|
+
|