Class: Salestation::Web::Extractors::ParamExtractor

Inherits:
Object
  • Object
show all
Includes:
Deterministic
Defined in:
lib/salestation/web/extractors.rb

Class Method Summary collapse

Class Method Details

.[](filters:, rack_key:) ⇒ Object



185
186
187
188
189
190
191
# File 'lib/salestation/web/extractors.rb', line 185

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



193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/salestation/web/extractors.rb', line 193

def self.extract(filters, request_hash)
  # Filter as a hash is used in some existing implementations that did not expect full 
  # recursive symbolizing of keys. In this case hash objects at the highest level of object 
  # are represented as hash of filter keys. This is no longer needed, but we support it 
  # to avoid a breaking change.

  filters_flat = filters
                  .flat_map {|filter| filter.is_a?(Hash) ? filter.keys : filter}
                  .map(&:to_s)

  request_hash = request_hash.select {|k,v| filters_flat.include?(k)}

  Symbolizer.symbolize(request_hash)
end