Class: Hanami::Action::BaseParams Private
- Inherits:
-
Object
- Object
- Hanami::Action::BaseParams
- Defined in:
- lib/hanami/action/base_params.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.
Provides access to params included in a Rack request.
Offers useful access to params via methods like #[], #get and #to_h.
These params are available via Request#params.
This class is used by default when Validatable is not included, or when no params validation schema is defined.
Direct Known Subclasses
Instance Attribute Summary collapse
- #env ⇒ Object readonly private
- #raw ⇒ Object readonly private
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Returns the value for the given params key.
-
#each {|key, value| ... } ⇒ to_h
Iterates over the params.
-
#get(*keys) ⇒ Object, NilClass
(also: #dig)
Returns an value associated with the given params key.
-
#initialize(env) ⇒ BaseParams
constructor
private
Returns a new frozen params object for the Rack env.
-
#to_h ⇒ Hash
(also: #to_hash)
Returns a hash of the parsed request params.
-
#valid? ⇒ TrueClass
Returns true at all times, providing a common interface with Params.
Constructor Details
#initialize(env) ⇒ BaseParams
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 frozen params object for the Rack env.
40 41 42 43 44 45 |
# File 'lib/hanami/action/base_params.rb', line 40 def initialize(env) @env = env @raw = _extract_params @params = Utils::Hash.deep_symbolize(@raw) 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.
26 27 28 |
# File 'lib/hanami/action/base_params.rb', line 26 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.
32 33 34 |
# File 'lib/hanami/action/base_params.rb', line 32 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object?
Returns the value for the given params key.
55 56 57 |
# File 'lib/hanami/action/base_params.rb', line 55 def [](key) @params[key] end |
#each {|key, value| ... } ⇒ to_h
Iterates over the params.
Calls the given block with each param key-value pair; returns the full hash of params.
135 136 137 |
# File 'lib/hanami/action/base_params.rb', line 135 def each(&blk) to_h.each(&blk) end |
#get(*keys) ⇒ Object, NilClass Also known as: dig
Returns an value associated with the given params key.
You can access nested attributes by listing all the keys in the path. This uses the same key path semantics as `Hash#dig`.
91 92 93 |
# File 'lib/hanami/action/base_params.rb', line 91 def get(*keys) @params.dig(*keys) end |
#to_h ⇒ Hash Also known as: to_hash
Returns a hash of the parsed request params.
119 120 121 |
# File 'lib/hanami/action/base_params.rb', line 119 def to_h @params end |
#valid? ⇒ TrueClass
Returns true at all times, providing a common interface with Params.
109 110 111 |
# File 'lib/hanami/action/base_params.rb', line 109 def valid? true end |