Class: OmniHooks::Builder

Inherits:
Rack::Builder
  • Object
show all
Defined in:
lib/omnihooks/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(app = nil, &block) ⇒ Builder

Returns a new instance of Builder.



6
7
8
9
10
11
12
13
14
# File 'lib/omnihooks/builder.rb', line 6

def initialize(app = nil, &block)
  @options = nil
  if rack14?
    super
  else
    @app = app
    super(app, &block)
  end
end

Instance Method Details

#call(env) ⇒ Object



43
44
45
# File 'lib/omnihooks/builder.rb', line 43

def call(env)
  to_app.call(env)
end

#on_failure(&block) ⇒ Object



20
21
22
# File 'lib/omnihooks/builder.rb', line 20

def on_failure(&block)
  OmniHooks.config.on_failure = block
end

#options(options = false) ⇒ Object



24
25
26
27
# File 'lib/omnihooks/builder.rb', line 24

def options(options = false)
  return @options || {} if options == false
  @options = options
end

#provider(klass, *args, &block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/omnihooks/builder.rb', line 29

def provider(klass, *args, &block)
  if klass.is_a?(Class)
    middleware = klass
  else
    begin
      middleware = OmniHooks::Strategies.const_get(klass.to_s.camelize)
    rescue NameError
      raise(LoadError.new("Could not find matching strategy for #{klass.inspect}. You may need to install an additional gem (such as omnihooks-#{klass})."))
    end
  end
  args.last.is_a?(Hash) ? args.push(options.merge(args.pop)) : args.push(options)
  use middleware, *args, &block
end

#rack14?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/omnihooks/builder.rb', line 16

def rack14?
  Rack.release.split('.')[0].to_i == 1 && Rack.release.split('.')[1].to_i >= 4
end