class BloodContracts::Core::MapValue
Mapper in form of refinement type, transforms the value using mapper_klass
Attributes
mapper_klass[RW]
Any callable object which you prefer to turn value into other form
@param [Class, call] @return [Class]
Public Class Methods
with(mapper_klass)
click to toggle source
Generates meta-class with predefined mapper_klass
@param mapper_klass
[Class, callable] callable object that will
transform the value
@return [MapValue]
# File lib/blood_contracts/core/map_value.rb, line 18 def with(mapper_klass) type = Class.new(self) type.mapper_klass = mapper_klass type end
Public Instance Methods
mapped()
click to toggle source
Mapped representation of the value
@return [Object]
# File lib/blood_contracts/core/map_value.rb, line 41 def mapped match.context[:mapped_value] end
match()
click to toggle source
Always successful matching process which transforms the value and store it in the context
@return [Refined]
# File lib/blood_contracts/core/map_value.rb, line 30 def match context[:mapper_input] = value context[:mapped_value] = self.class.mapper_klass.call(**context[:mapper_input]) self end