Module: Rack::Block::DSL::Responses

Included in:
Rack::Block
Defined in:
lib/rack/block/dsl/responses.rb

Instance Method Summary collapse

Instance Method Details

#detect_matching_patternObject



3
4
5
6
7
8
9
# File 'lib/rack/block/dsl/responses.rb', line 3

def detect_matching_pattern
  if in_ua_block?
    ua_matchers[@_current_matching_ua_pattern] ||= {}
  elsif in_ip_block?
    ip_matchers[@_current_matching_ip_pattern] ||= {}
  end
end

#dummy_app(opts = {}, &app_proc) ⇒ Object Also known as: double



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rack/block/dsl/responses.rb', line 36

def dummy_app(opts={}, &app_proc)
  if @_current_matching_path
    path = Regexp.compile("^" + @_current_matching_path.gsub(/\./, '\\.').gsub(/\*/, '.*'))
    current_matchers = detect_matching_pattern
    current_matchers[path] = [:do_dummy_app, app_proc, opts]
  else
    path '*' do
      dummy_app opts, &app_proc
    end
  end
end

#halt(code, opts = {}) ⇒ Object

TODO non DRY on handling ‘@_current_matching_path’ !!!! it is terrible!!



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rack/block/dsl/responses.rb', line 12

def halt(code, opts={})
  if @_current_matching_path
    path = Regexp.compile("^" + @_current_matching_path.gsub(/\./, '\\.').gsub(/\*/, '.*'))
    current_matchers = detect_matching_pattern
    current_matchers[path] = [:do_halt, code, opts]
  else
    path '*' do
      halt code, opts
    end
  end
end

#redirect(dest_path, opts = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rack/block/dsl/responses.rb', line 24

def redirect(dest_path, opts={})
  if @_current_matching_path
    path = Regexp.compile("^" + @_current_matching_path.gsub(/\./, '\\.').gsub(/\*/, '.*'))
    current_matchers = detect_matching_pattern
    current_matchers[path] = [:do_redirect, dest_path, opts]
  else
    path '*' do
      redirect dest_path, opts
    end
  end
end