Module: Lotus::Action::Rack

Defined in:
lib/lotus/action/rack.rb

Overview

Rack integration API

Since:

  • 0.1.0

Constant Summary collapse

SESSION_KEY =

Since:

  • 0.1.0

'rack.session'.freeze
DEFAULT_RESPONSE_CODE =

Since:

  • 0.1.0

200
DEFAULT_RESPONSE_BODY =

Since:

  • 0.1.0

[]

Instance Method Summary collapse

Instance Method Details

#body=(body) ⇒ void (protected)

This method returns an undefined value.

Sets the body of the response

Examples:

require 'lotus/controller'

class Show
  include Lotus::Action

  def call(params)
    # ...
    self.body = 'Hi!'
  end
end

Parameters:

  • body (String)

    the body of the response

Since:

  • 0.1.0



52
53
54
55
# File 'lib/lotus/action/rack.rb', line 52

def body=(body)
  body   = Array(body) unless body.respond_to?(:each)
  @_body = body
end

#headersHash (protected)

Gets the headers from the response

Examples:

require 'lotus/controller'

class Show
  include Lotus::Action

  def call(params)
    # ...
    self.headers            # => { ... }
    self.headers.merge!({'X-Custom' => 'OK'})
  end
end

Returns:

  • (Hash)

    the HTTP headers from the response

Since:

  • 0.1.0



75
76
77
# File 'lib/lotus/action/rack.rb', line 75

def headers
  @headers
end

#responseArray (protected)

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 serialized Rack response (Array), according to the current

status code, headers, and body.

Returns:

  • (Array)

    the serialized response

See Also:

Since:

  • 0.1.0



92
93
94
# File 'lib/lotus/action/rack.rb', line 92

def response
  [ @_status || DEFAULT_RESPONSE_CODE, headers, @_body || DEFAULT_RESPONSE_BODY.dup ]
end

#status=(status) ⇒ void (protected)

This method returns an undefined value.

Sets the HTTP status code for the response

Examples:

require 'lotus/controller'

class Create
  include Lotus::Action

  def call(params)
    # ...
    self.status = 201
  end
end

Parameters:

  • status (Fixnum)

    an HTTP status code

Since:

  • 0.1.0



30
31
32
# File 'lib/lotus/action/rack.rb', line 30

def status=(status)
  @_status = status
end