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
- GET_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Separator for #get
'.'.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(key) ⇒ Object, NilClass
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.
45 46 47 48 49 50 |
# File 'lib/hanami/action/base_params.rb', line 45 def initialize(env) @env = env @raw = _extract_params @params = Utils::Hash.new(@raw).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.
30 31 32 |
# File 'lib/hanami/action/base_params.rb', line 30 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.
36 37 38 |
# File 'lib/hanami/action/base_params.rb', line 36 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object?
Returns the object associated with the given key
59 60 61 |
# File 'lib/hanami/action/base_params.rb', line 59 def [](key) @params[key] end |
#each(&blk) ⇒ Object
Iterates through params
132 133 134 |
# File 'lib/hanami/action/base_params.rb', line 132 def each(&blk) to_h.each(&blk) end |
#get(key) ⇒ Object, NilClass
Get an attribute value associated with the given key. Nested attributes are reached with a dot notation.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/hanami/action/base_params.rb', line 92 def get(key) key, *keys = key.to_s.split(GET_SEPARATOR) return if key.nil? result = self[key.to_sym] Array(keys).each do |k| break if result.nil? result = result[k.to_sym] end result end |
#to_h ⇒ ::Hash Also known as: to_hash
Serialize params to Hash
122 123 124 |
# File 'lib/hanami/action/base_params.rb', line 122 def to_h @params end |
#valid? ⇒ TrueClass
Provide a common interface with Params
113 114 115 |
# File 'lib/hanami/action/base_params.rb', line 113 def valid? true end |