Last active
September 15, 2017 13:39
-
-
Save apotonick/e6ae91823385229673229ebca4848f2f to your computer and use it in GitHub Desktop.
Death of Reform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem "dry-validation" | |
require "dry-types" | |
module Types | |
include Dry::Types.module | |
end | |
require 'dry/logic' | |
require 'dry/logic/predicates' | |
include Dry::Logic | |
bla = ->(*args) { raise args.inspect } | |
nilify_rule = Rule::Predicate.new( bla ) | |
void_rule = Rule::Predicate.new( ->(value) { raise value.inspect; value+1 } ) | |
_or = void_rule & nilify_rule | |
_or.(1) | |
# is_format = Types::Strict::String.constrained( | |
is_format = Rule::Predicate.new( Predicates[:format?] ).curry( | |
/\d\d\.\d\d\.\d\d\d\d/ | |
) | |
bla = ->(*args) { raise args.inspect } | |
nilify = Dry::Types::Coercions::Form.method(:to_nil) | |
nilify_rule = Rule::Predicate.new( bla ) | |
# puts nilify.(" ").inspect | |
# puts nilify.("").inspect | |
puts "@@@@@ #{nilify_rule.("").inspect}" | |
coercion = nilify_rule | is_format & Types::Form::DateTime | |
result = coercion.( "11.11.2019" ) | |
puts "@@@@@ #{result.inspect}" | |
nilify | ( is_format & Types::Form::DateTime ) | |
nilify | default | ( is_format & Types::Form::DateTime ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x | |
.read(:dob) # read nested fragment Representable::Binding | |
== "" ? .nilify : .DAtetime.( x) # coercion, Dry::Types # what if coercion fails? | |
-> |domain, value| domain.date_of_birth = value | |
validate(date_of_birth > 1981) | |
model.date_of_birth = domain.date_of_birth # ROM, Twin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
defaults