Module: Rack::Block::DSL::Matchers

Included in:
Rack::Block
Defined in:
lib/rack/block/dsl/matchers.rb,
lib/rack/block/dsl/builtin_bot_pattern.rb

Constant Summary collapse

BUILTIN_BOT_PATTERN =
/#{
  ["Googlebot",
   "MSNBot",
   "Bing",
   "Inktomi Slurp",
   "Yahoo",
   "AskJeeves",
   "FastCrawler",
   "InfoSeek Robot 1.0",
   "Baiduspider",
   "Lycos"].join("|")
}/i

Instance Method Summary collapse

Instance Method Details

#bot_access(&block) ⇒ Object



5
6
7
# File 'lib/rack/block/dsl/matchers.rb', line 5

def bot_access(&block)
  ua_pattern BUILTIN_BOT_PATTERN, &block      
end

#ip_pattern(pattern, &block) ⇒ Object Also known as: block_ip



19
20
21
22
23
24
25
26
# File 'lib/rack/block/dsl/matchers.rb', line 19

def ip_pattern(pattern, &block)
  @_current_matching_type, orig = :by_IP, @_current_matching_type
  @_current_matching_ip_pattern, orig_ptn = ip_to_pattern(pattern), @_current_matching_ip_pattern
  yield
ensure
  @_current_matching_ip_pattern = orig_ptn
  @_current_matching_type = orig
end

#path(pattern, &block) ⇒ Object



31
32
33
34
35
36
# File 'lib/rack/block/dsl/matchers.rb', line 31

def path(pattern, &block)
  @_current_matching_path, orig = pattern, @_current_matching_path
  yield
ensure
  @_current_matching_path = orig
end

#ua_pattern(pattern, &block) ⇒ Object Also known as: block_ua

TODO it’s NO DRY



10
11
12
13
14
15
16
17
# File 'lib/rack/block/dsl/matchers.rb', line 10

def ua_pattern(pattern, &block)
  @_current_matching_type, orig = :by_UA, @_current_matching_type
  @_current_matching_ua_pattern, orig_ptn = pattern, @_current_matching_ua_pattern
  yield
ensure
  @_current_matching_ua_pattern = orig_ptn
  @_current_matching_type = orig
end