Class: OperationsMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/operations_middleware.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) {|_self| ... } ⇒ OperationsMiddleware

Returns a new instance of OperationsMiddleware.

Yields:

  • (_self)

Yield Parameters:



5
6
7
8
9
# File 'lib/operations_middleware.rb', line 5

def initialize(app)
  @app = app
  @heartbeat = {}
  yield self if block_given?
end

Instance Attribute Details

#app_name=(value) ⇒ Object

Sets the attribute app_name

Parameters:

  • value

    the value to set the attribute app_name to.



2
3
4
# File 'lib/operations_middleware.rb', line 2

def app_name=(value)
  @app_name = value
end

#file_rootObject

Returns the value of attribute file_root.



3
4
5
# File 'lib/operations_middleware.rb', line 3

def file_root
  @file_root
end

#heartbeatObject

Returns the value of attribute heartbeat.



3
4
5
# File 'lib/operations_middleware.rb', line 3

def heartbeat
  @heartbeat
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/operations_middleware.rb', line 11

def call(env)
  return @app.call(env) unless env['PATH_INFO'] =~ %r{^/ops/(heartbeat|version)(?:/(\w+))?/?$}
      
  @request_headers = env

  @status = 200
  @headers = {}
  
  if $1 == 'heartbeat'
    if $2
      check_heartbeat($2)
    else
      @body = "#{app_name} is OK"
    end
  else
    @body = version_template
  end
  
  @headers['Content-Type'] = "text/html"
  @headers['Content-Length'] = @body.length.to_s
  

  [@status, @headers, @body]
end