Class: Rack::DomainFilter

Inherits:
Object
  • Object
show all
Includes:
AfterRequestHandler, ExceptionHandler, Matcher
Defined in:
lib/rack/domain_filter.rb,
lib/rack/domain_filter/version.rb,
lib/rack/domain_filter/ext/matcher.rb,
lib/rack/domain_filter/ext/configuration.rb,
lib/rack/domain_filter/ext/exception_handler.rb,
lib/rack/domain_filter/ext/after_request_handler.rb

Defined Under Namespace

Modules: AfterRequestHandler, ConfigurationDSL, ExceptionHandler, Matcher Classes: Configuration

Constant Summary collapse

VERSION =
'1.0.3'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Matcher

#can_respond_no_match?, #can_skip_path?, #match_regex, #match_string, #match_uri, #skip_regex?, #skip_string?, #trigger_no_match

Methods included from AfterRequestHandler

#run_after_request

Methods included from ExceptionHandler

#catch_exception

Constructor Details

#initialize(app, options = {}) ⇒ DomainFilter

Returns a new instance of DomainFilter.



7
8
9
10
11
# File 'lib/rack/domain_filter.rb', line 7

def initialize(app, options={})
  @app = app
  @config = options[:config] || DomainFilter.global_configuration
  @match_found = false
end

Class Method Details

.clear_configuration!Object



50
51
52
# File 'lib/rack/domain_filter.rb', line 50

def self.clear_configuration!
  @global_configuration = nil
end

.configure {|@global_configuration| ... } ⇒ Object



44
45
46
47
48
# File 'lib/rack/domain_filter.rb', line 44

def self.configure
  @global_configuration ||= Configuration.new

  yield @global_configuration
end

.global_configurationObject



54
55
56
# File 'lib/rack/domain_filter.rb', line 54

def self.global_configuration
  @global_configuration
end

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rack/domain_filter.rb', line 21

def call(env)
  if can_skip_path?(env)
    return wrap_call { @app.call(env) }
  end

  match_uri(env)

  if !@match_found && can_respond_no_match?
    return wrap_call { trigger_no_match(env) }
  end

  wrap_call { @app.call(env) }
rescue => e
  result = catch_exception(e)
  run_after_request

  result
end

#configObject



58
59
60
# File 'lib/rack/domain_filter.rb', line 58

def config
  @config
end

#verify_configuration!Object



61
62
63
# File 'lib/rack/domain_filter.rb', line 61

def verify_configuration!

end

#wrap_callObject



13
14
15
16
17
18
19
# File 'lib/rack/domain_filter.rb', line 13

def wrap_call
  result = yield

  run_after_request

  result
end