Class: Salestation::Web::Extractors::InputCoercer
- Inherits:
-
Object
- Object
- Salestation::Web::Extractors::InputCoercer
- Defined in:
- lib/salestation/web/extractors.rb
Overview
Handles coercing input values
Instance Method Summary collapse
- #call(rack_request) ⇒ Object
- #coerce(input) ⇒ Object
-
#initialize(extractor, rules) ⇒ InputCoercer
constructor
A new instance of InputCoercer.
- #merge(other) ⇒ Object
Constructor Details
#initialize(extractor, rules) ⇒ InputCoercer
Returns a new instance of InputCoercer.
72 73 74 75 |
# File 'lib/salestation/web/extractors.rb', line 72 def initialize(extractor, rules) @extractor = extractor @rules = rules end |
Instance Method Details
#call(rack_request) ⇒ Object
77 78 79 80 81 |
# File 'lib/salestation/web/extractors.rb', line 77 def call(rack_request) @extractor .call(rack_request) .map(&method(:coerce)) end |
#coerce(input) ⇒ Object
83 84 85 86 87 88 |
# File 'lib/salestation/web/extractors.rb', line 83 def coerce(input) @rules.each do |field, coercer| input[field] = coercer.call(input[field]) if input.key?(field) end Deterministic::Result::Success(input) end |
#merge(other) ⇒ Object
90 91 92 |
# File 'lib/salestation/web/extractors.rb', line 90 def merge(other) CombinedInputExtractor.new([self, other]) end |