Class: Orbit::Interceptors::List

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/orbit/interceptors/list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Singleton

included, #instantiate

Constructor Details

#initialize(interceptors = []) ⇒ List

Returns a new instance of List.



7
8
9
# File 'lib/orbit/interceptors/list.rb', line 7

def initialize(interceptors=[])
  @interceptors = interceptors
end

Instance Attribute Details

#interceptorsObject (readonly)

Returns the value of attribute interceptors.



5
6
7
# File 'lib/orbit/interceptors/list.rb', line 5

def interceptors
  @interceptors
end

Class Method Details

.add_interceptor(path, interceptor_class, excludes = []) ⇒ Object



11
12
13
14
15
# File 'lib/orbit/interceptors/list.rb', line 11

def self.add_interceptor(path, interceptor_class, excludes=[])
  interceptor = Item.new(path, interceptor_class, excludes)

  instance.interceptors.push(interceptor)
end

.intercept_path(request) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/orbit/interceptors/list.rb', line 29

def self.intercept_path(request)
  path = request.path_info

  instance.interceptors_for_path(path).each do |hash|
    result = hash.interceptor_class.execute(request)

    return result if result
  end

  nil
end

.interceptorsObject



17
18
19
# File 'lib/orbit/interceptors/list.rb', line 17

def self.interceptors
  instance.interceptors
end

Instance Method Details

#interceptors_for_path(path) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/orbit/interceptors/list.rb', line 21

def interceptors_for_path(path)
  return [] unless path

  interceptors.select do |item|
    item.match_path?(path)
  end
end