Class: Clownfish::StatusGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/clownfish/helpers/status_group.rb

Overview

One or more response status codes. StatusGroups are filled with status specifiers to determine what is in the group.

Status specifiers can be Integer status codes like 200, Integer Ranges like 400..404 or any of the following Symbols:

:all          - any status code
:success      - 2xx
:redirect     - 3xx
:non_error    - 2xx through 3xx
:client_error - 4xx
:server_error - 5xx
:error        - 4xx through 5xx

Constant Summary collapse

ALIASES =
{
  :all          => 200..599,
  :success      => 200..299,
  :redirect     => 300..399,
  :non_error    => 200..399,
  :client_error => 400..499,
  :server_error => 500..599,
  :error        => 400..599
}

Instance Method Summary collapse

Constructor Details

#initialize(*specifiers) ⇒ StatusGroup

Public: Create a new group.

statuses - One or more status specifiers or an Array of status specifiers.



28
29
30
31
32
33
34
# File 'lib/clownfish/helpers/status_group.rb', line 28

def initialize(*specifiers)
  @members = []

  specifiers.flatten.each do |status|
    self << status
  end
end

Instance Method Details

#<<(specifier) ⇒ Object

Public: Add a status specifier to this group.

specifier - A status specifier

Returns self for chaining purposes.



41
42
43
44
# File 'lib/clownfish/helpers/status_group.rb', line 41

def <<(specifier)
  @members << (resolve_alias(specifier) || specifier)
  self
end

#include?(status) ⇒ Boolean

Public: Tells if this group includes a given status code.

status - Integer status code

Returns true if status is included, false otherwise.

Returns:

  • (Boolean)


51
52
53
# File 'lib/clownfish/helpers/status_group.rb', line 51

def include?(status)
  @members.any? {|m| m === status}
end