class Massager::AttributeWithSingleKey
Attributes
block[R]
key[R]
name[R]
opts[R]
Public Class Methods
new(name:, key:, opts: {}, block: nil)
click to toggle source
# File lib/massager/attributes/attribute_with_single_key.rb, line 3 def initialize(name:, key:, opts: {}, block: nil) @name, @key, @opts, @block = name, key, opts, block end
Public Instance Methods
call(values)
click to toggle source
# File lib/massager/attributes/attribute_with_single_key.rb, line 7 def call(values) value = values.fetch(key) Dry::Monads::Maybe(block).fmap {|block| value = block.call(value)} Dry::Monads::Maybe(opts[:type]).fmap {|type| begin value = type.call(value) rescue Dry::Types::ConstraintError raise Massager::ConstraintError, "Attribute #{name} did not pass the constraint for value of #{value}" end } value end
match_schema?(attrs)
click to toggle source
# File lib/massager/attributes/attribute_with_single_key.rb, line 20 def match_schema?(attrs) attrs.keys.include?(key) end