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.
74 75 76 77 |
# File 'lib/salestation/web/extractors.rb', line 74 def initialize(extractor, rules) @extractor = extractor @rules = rules end |
Instance Method Details
#call(rack_request) ⇒ Object
79 80 81 82 83 |
# File 'lib/salestation/web/extractors.rb', line 79 def call(rack_request) @extractor .call(rack_request) .map(&method(:coerce)) end |
#coerce(input) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/salestation/web/extractors.rb', line 85 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
92 93 94 |
# File 'lib/salestation/web/extractors.rb', line 92 def merge(other) CombinedInputExtractor.new([self, other]) end |