Class: Salestation::Web::Extractors::ParamExtractor
- Inherits:
-
Object
- Object
- Salestation::Web::Extractors::ParamExtractor
- Includes:
- Deterministic
- Defined in:
- lib/salestation/web/extractors.rb
Class Method Summary collapse
Class Method Details
.[](filters:, rack_key:) ⇒ Object
186 187 188 189 190 191 192 |
# File 'lib/salestation/web/extractors.rb', line 186 def self.[](filters:, rack_key:) InputExtractor.new do |rack_request| request_hash = rack_request.env[rack_key] || {} input = extract(filters, request_hash) Result::Success(input) end end |
.extract(filters, request_hash) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/salestation/web/extractors.rb', line 194 def self.extract(filters, request_hash) filters.each_with_object({}) do |filter, extracted_data| case filter when Symbol stringified_key = filter.to_s extracted_data[filter] = request_hash[stringified_key] if request_hash.key?(stringified_key) when Hash filter.each do |key, nested_filters| stringified_key = key.to_s if request_hash.key?(stringified_key) value = request_hash.fetch(stringified_key) extracted_data[key] = value.nil? ? nil : extract(nested_filters, value) end end end end end |