Module: NginxTail::Status

Defined in:
lib/ntail/status.rb

Constant Summary collapse

NGINX_MAGIC_STATUS =

ex-standard HTTP response code specific to nginx, in addition to www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

'499'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ntail/status.rb', line 6

def self.included(base) # :nodoc:
  base.class_eval do

    # Informational 1xx
    def self.information_status?(status)
      # (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_TO_OBJ[status.to_s] <= Net::HTTPInformation
      (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_CLASS_TO_OBJ[(status.to_i / 100).to_s] == Net::HTTPInformation
    end

    # Successful 2xx
    def self.success_status?(status)
      # (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_TO_OBJ[status.to_s] <= Net::HTTPSuccess
      (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_CLASS_TO_OBJ[(status.to_i / 100).to_s] == Net::HTTPSuccess
    end

    # Redirection 3xx
    def self.redirect_status?(status)
      # (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_TO_OBJ[status.to_s] <= Net::HTTPRedirection
      (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_CLASS_TO_OBJ[(status.to_i / 100).to_s] == Net::HTTPRedirection
    end

    # Client Error 4xx
    def self.client_error_status?(status)
      # (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_TO_OBJ[status.to_s] <= Net::HTTPClientError
      (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_CLASS_TO_OBJ[(status.to_i / 100).to_s] == Net::HTTPClientError
    end

    # Internal Server Error 5xx
    def self.server_error_status?(status)
      # (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_TO_OBJ[status.to_s] <= Net::HTTPServerError
      (status.to_s != NGINX_MAGIC_STATUS) and Net::HTTPResponse::CODE_CLASS_TO_OBJ[(status.to_i / 100).to_s] == Net::HTTPServerError
    end

    # this ensures the below module methods actually make sense...
    raise "Class #{base.name} should implement instance method 'status'" unless base.instance_methods.map(&:to_s).include? 'status'

  end
end

Instance Method Details

#client_error_status?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/ntail/status.rb', line 57

def client_error_status?
  self.class.client_error_status?(self.status)
end

#information_status?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/ntail/status.rb', line 45

def information_status?
  self.class.information_status?(self.status)
end

#redirect_status?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ntail/status.rb', line 53

def redirect_status?
  self.class.redirect_status?(self.status)
end

#server_error_status?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ntail/status.rb', line 61

def server_error_status?
  self.class.server_error_status?(self.status)
end

#success_status?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/ntail/status.rb', line 49

def success_status?
  self.class.success_status?(self.status)
end