Class: Hanami::Router::Block::Context Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/router/block.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Context to handle a single incoming HTTP request for a block endpoint

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blk, env) ⇒ Context

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Context.

Since:

  • 2.0.0



16
17
18
19
# File 'lib/hanami/router/block.rb', line 16

def initialize(blk, env)
  @blk = blk
  @env = env
end

Instance Attribute Details

#envHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Rack env

Returns:

  • (Hash)

    the Rack env

Since:

  • 2.0.0



26
27
28
# File 'lib/hanami/router/block.rb', line 26

def env
  @env
end

Instance Method Details

#callObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



67
68
69
70
# File 'lib/hanami/router/block.rb', line 67

def call
  body = instance_exec(&@blk)
  [status, headers, [body]]
end

#headersInteger #headers(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overloads:

  • #headersInteger

    Gets the current HTTP headers code

    Returns:

    • (Integer)

      the HTTP headers code

  • #headers(value) ⇒ Object

    Sets the HTTP headers

    Parameters:

    • value (Integer)

      the HTTP headers code

Since:

  • 2.0.0



48
49
50
51
52
53
54
# File 'lib/hanami/router/block.rb', line 48

def headers(value = nil)
  if value
    @headers = value
  else
    @headers ||= {}
  end
end

#paramsHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

HTTP Params from URL variables and HTTP body parsing

Returns:

  • (Hash)

    the HTTP params

Since:

  • 2.0.0



61
62
63
# File 'lib/hanami/router/block.rb', line 61

def params
  env[Router::PARAMS]
end

#statusInteger #status(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Overloads:

  • #statusInteger

    Gets the current HTTP status code

    Returns:

    • (Integer)

      the HTTP status code

  • #status(value) ⇒ Object

    Sets the HTTP status

    Parameters:

    • value (Integer)

      the HTTP status code

Since:

  • 2.0.0



34
35
36
37
38
39
40
# File 'lib/hanami/router/block.rb', line 34

def status(value = nil)
  if value
    @status = value
  else
    @status ||= Router::HTTP_STATUS_OK
  end
end