Class: Hanami::Action::BaseParams
- Inherits:
-
Object
- Object
- Hanami::Action::BaseParams
- Defined in:
- lib/hanami/action/base_params.rb
Overview
Direct Known Subclasses
Constant Summary collapse
- RACK_INPUT =
The key that returns raw input from the Rack env
'rack.input'.freeze
- ROUTER_PARAMS =
The key that returns router params from the Rack env This is a builtin integration for Hanami::Router
'router.params'.freeze
Instance Attribute Summary collapse
- #env ⇒ Object readonly private
- #raw ⇒ Object readonly private
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Returns the object associated with the given key.
-
#each(&blk) ⇒ Object
Iterates through params.
-
#get(*keys) ⇒ Object, NilClass
(also: #dig)
Get an attribute value associated with the given key.
-
#initialize(env) ⇒ Params
constructor
Initialize the params and freeze them.
-
#to_h ⇒ ::Hash
(also: #to_hash)
Serialize params to Hash.
-
#valid? ⇒ TrueClass
Provide a common interface with Params.
Constructor Details
#initialize(env) ⇒ Params
Initialize the params and freeze them.
37 38 39 40 41 42 |
# File 'lib/hanami/action/base_params.rb', line 37 def initialize(env) @env = env @raw = _extract_params @params = Utils::Hash.new(@raw).deep_dup.symbolize!.to_h freeze end |
Instance Attribute Details
#env ⇒ Object (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.
22 23 24 |
# File 'lib/hanami/action/base_params.rb', line 22 def env @env end |
#raw ⇒ Object (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.
28 29 30 |
# File 'lib/hanami/action/base_params.rb', line 28 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object?
Returns the object associated with the given key
51 52 53 |
# File 'lib/hanami/action/base_params.rb', line 51 def [](key) @params[key] end |
#each(&blk) ⇒ Object
Iterates through params
122 123 124 |
# File 'lib/hanami/action/base_params.rb', line 122 def each(&blk) to_h.each(&blk) end |
#get(*keys) ⇒ Object, NilClass Also known as: dig
Get an attribute value associated with the given key. Nested attributes are reached by listing all the keys to get to the value.
86 87 88 |
# File 'lib/hanami/action/base_params.rb', line 86 def get(*keys) @params.dig(*keys) end |
#to_h ⇒ ::Hash Also known as: to_hash
Serialize params to Hash
112 113 114 |
# File 'lib/hanami/action/base_params.rb', line 112 def to_h @params end |
#valid? ⇒ TrueClass
Provide a common interface with Params
103 104 105 |
# File 'lib/hanami/action/base_params.rb', line 103 def valid? true end |