Class: Lotus::Action::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/action/params.rb

Overview

A set of params requested by the client

It’s able to extract the relevant params from a Rack env of from an Hash.

There are three scenarios:

* When used with Lotus::Router: it contains only the params from the request
* When used standalone: it contains all the Rack env
* Default: it returns the given hash as it is. It's useful for testing purposes.

Since:

  • 0.1.0

Constant Summary collapse

RACK_INPUT =

The key that returns raw input from the Rack env

Since:

  • 0.1.0

'rack.input'.freeze
ROUTER_PARAMS =

The key that returns router params from the Rack env This is a builtin integration for Lotus::Router

Since:

  • 0.1.0

'router.params'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Params

Initialize the params and freeze them.

Parameters:

  • env (Hash)

    a Rack env or an hash of params.

Since:

  • 0.1.0



40
41
42
43
44
# File 'lib/lotus/action/params.rb', line 40

def initialize(env)
  @env    = env
  @params = Utils::Hash.new(_extract).symbolize!
  freeze
end

Instance Attribute Details

#envObject (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.

Since:

  • 0.2.0



31
32
33
# File 'lib/lotus/action/params.rb', line 31

def env
  @env
end

Instance Method Details

#[](key) ⇒ Object?

Returns the object associated with the given key

Parameters:

  • key (Symbol)

    the key

Returns:

  • (Object, nil)

    return the associated object, if found

Since:

  • 0.2.0



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

def [](key)
  @params[key]
end