rackif 0.0.1 → 0.0.2

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.
Files changed (6) hide show
  1. data/README +9 -1
  2. data/Rakefile +1 -1
  3. data/config.ru +1 -1
  4. data/lib/if.rb +22 -3
  5. data/rackif.gemspec +2 -2
  6. metadata +2 -2
data/README CHANGED
@@ -1,12 +1,20 @@
1
1
  Use or don't use rack apps based on a variety of environment variables.
2
2
 
3
+ gem install rackif --source http://gemcutter.org
4
+
3
5
  Example:
4
- use Rack::If, :path => '/protected', :method => /get/i do
6
+
7
+ require 'rackif'
8
+ use Rack::If, {:path => /\A\/protected.*/, :method => 'POST'}, :any do
5
9
  use Rack::Auth::Basic, "Rack::If Example" do |username, password|
6
10
  'secret' == password
7
11
  end
8
12
  end
9
13
 
14
+ The third argument (:all or :any) is optional, defaults to :all.
15
+
16
+ With :all, all options must match for the block to get run. In the above example, the path would need to start with /protected AND the method would need to be POST. With :any, if ANY of the criteria match (either POST or the path), the block is run.
17
+
10
18
  Options available are: path, method, user_agent, host, port, query_string, http_accept, and http_accept_encoding.
11
19
 
12
20
  Values given can be strings or regex (=== used for comparison).
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
3
3
  require 'rake'
4
4
  require 'echoe'
5
5
 
6
- Echoe.new('rackif', '0.0.1') do |p|
6
+ Echoe.new('rackif', '0.0.2') do |p|
7
7
  p.summary = "Conditional use of rack apps"
8
8
  p.description = "Use or don't use Rack apps based on a variety of environment factors."
9
9
  # p.url = "http://samsm.com/"
data/config.ru CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rack'
3
3
  require 'lib/rackif'
4
4
 
5
- use Rack::If, :path => '/protected', :method => 'GET' do
5
+ use Rack::If, {:path => '/protected', :method => 'POST'}, :any do
6
6
  use Rack::Auth::Basic, "Rack::If Example" do |username, password|
7
7
  'secret' == password
8
8
  end
data/lib/if.rb CHANGED
@@ -2,15 +2,34 @@ class Rack::If
2
2
 
3
3
  attr_reader :app
4
4
 
5
- def initialize(app, options={}, &block)
6
- @options = options
7
- @app = app
5
+ def initialize(app, options={}, all_or_any = :all, &block)
6
+ @methodology = all_or_any
7
+ @options = options
8
+ @app = app
8
9
 
9
10
  @middleware = []
10
11
  instance_eval(&block)
11
12
  end
12
13
 
13
14
  def match?(env)
15
+ case @methodology.to_s
16
+ when 'all'
17
+ match_all?(env)
18
+ when 'any'
19
+ match_any?(env)
20
+ end
21
+ end
22
+
23
+ def match_any?(env)
24
+ @options.inject(false) do |memo,pair|
25
+ if_key = pair[0]
26
+ rack_key = comparison_table[if_key]
27
+ if_value = pair[1]
28
+ memo || if_value === env[rack_key]
29
+ end
30
+ end
31
+
32
+ def match_all?(env)
14
33
  @options.inject(true) do |memo, pair|
15
34
  if_key = pair[0]
16
35
  rack_key = comparison_table[if_key]
data/rackif.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{rackif}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = [""]
9
- s.date = %q{2009-11-13}
9
+ s.date = %q{2009-11-18}
10
10
  s.description = %q{Use or don't use Rack apps based on a variety of environment factors.}
11
11
  s.email = %q{}
12
12
  s.extra_rdoc_files = ["README", "lib/if.rb", "lib/rackif.rb"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackif
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ""
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 -05:00
12
+ date: 2009-11-18 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency