These are chat archives for dry-rb/chat

12th
Oct 2017
Piotr Solnica
@solnic
Oct 12 2017 06:51
@hlegius there's an experimental feature called 'type specs' (which will be default behavior in 1.0.0) http://dry-rb.org/gems/dry-validation/type-specs/
@andriytyurnikov what kind of contracts?
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:15
@solnic contracts that describe and ensure method signature - types of input values and types of returned values
Piotr Solnica
@solnic
Oct 12 2017 09:21
@andriytyurnikov yes you could achieve that with dry-types
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:23
@solnic , are you sure?)
Piotr Solnica
@solnic
Oct 12 2017 09:25
well, yes
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:26
@solnic , here is an example of contract library https://github.com/egonSchiele/contracts.ruby ; But in order to export code into other languages with typed return values one would need ability to ... inspect existing contract of the method
@solnic so far I came with idea of implementation that will just store output type, and maybe wrapping method invocation with routine that will throw an exception if output type doesn't match stored... which could be enough, I guess)
Piotr Solnica
@solnic
Oct 12 2017 09:32
> t = Types::Strict::String.constrained(size: 2..16)
=> #<Dry::Types::Constrained type=#<Dry::Types::Definition primitive=String options={} meta={}> options={:rule=>#<Dry::Logic::Operations::And rules=[#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[String]}>, #<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#size?> options={:args=>[2..16]}>] options={}>} rule=#<Dry::Logic::Operations::And rules=[#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[String]}>, #<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#size?> options={:args=>[2..16]}>] options={}> meta={}>
> t.to_ast
=> [:constrained, [[:definition, [String, {}]], [:and, [[:predicate, [:type?, [[:type, String], [:input, Undefined]]]], [:predicate, [:size?, [[:size, 2..16], [:input, Undefined]]]]]], {}]]
@andriytyurnikov ^^
which means you can dump dry-types type objects to formal AST representation and convert them to whatever you want
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:47
@solnic thank you so much. This is second time I bother you with AST related question. First one was about generational ability of types (ability to generate instances that conform to spec). Is AST documented somewhere and I am missing something obvious?
Piotr Solnica
@solnic
Oct 12 2017 09:47
create an AST from your spec, and compile it using type compiler from dry-types
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:51
@solnic , you lost me here (: this type compiler and 'formal AST' - are they documented somewhere? RDoc or something?
Piotr Solnica
@solnic
Oct 12 2017 09:53
@andriytyurnikov it's not documented, dry-types is in beta, no time to keep docs up to date
you can look at specs
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 09:56
@solnic , ok, thanks for sharing knowledge of dark magic)
Piotr Solnica
@solnic
Oct 12 2017 09:57
haha
it's actually the opposite of dark magic :)
it's just not so common in ruby libs
irb(main):009:0> require 'dry/types/compiler'
=> false
irb(main):010:0> tc = Dry::Types::Compiler.new(Dry::Types)
=> #<Dry::Types::Compiler:0x007fca038cacd8 @registry=Dry::Types>
irb(main):011:0> Undefined = Dry::Core::Constants::Undefined
=> Undefined
irb(main):012:0> tc.visit([:constrained, [[:definition, [String, {}]], [:and, [[:predicate, [:type?, [[:type, String], [:input, Undefined]]]], [:predicate, [:size?, [[:size, 2..16], [:input, Undefined]]]]]], {}]])
=> #<Dry::Types::Constrained type=#<Dry::Types::Definition primitive=String options={} meta={}> options={:rule=>#<Dry::Logic::Operations::And rules=[#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[String]}>, #<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#size?> options={:args=>[2..16]}>] options={}>} rule=#<Dry::Logic::Operations::And rules=[#<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#type?> options={:args=>[String]}>, #<Dry::Logic::Rule::Predicate predicate=#<Method: Module(Dry::Logic::Predicates::Methods)#size?> options={:args=>[2..16]}>] options={}> meta={}>
@andriytyurnikov FYI ^
Andriy Tyurnikov
@andriytyurnikov
Oct 12 2017 10:02
yeah, the fact that AST/CST tools are not in core lib of MRI is frustrating, jruby has some, btw
so
Dry::Types::Compiler.new(Dry::Types).visit(SOME_AST)
will compile AST
Alexander Chernik
@achernik
Oct 12 2017 16:21
Hello!
When is dry-system's stop lifecycle event triggered?
I'm trying to figure out if it is a good place to put cleanup logic for a component, i.e. shutdown/kill a background task.
Dmitry P
@fenec
Oct 12 2017 16:27
Hey guys
is it a place to submit a proposals or forum would be better?
Alexander Chernik
@achernik
Oct 12 2017 16:41
I guess I expect Dry::System::Container#stop to be there, so it is possible to cleanup all bootable components at exit. But there is no such method :)
I might be misunderstanding something
Dmitry P
@fenec
Oct 12 2017 18:19
I'm using dry-transaction and I need a user object in one of the steps in the middle. Obviously, I don't want to pass it all the way from the first step, what are my options?
Alexander Chernik
@achernik
Oct 12 2017 20:35
@fenec there's an example of this in the docs here: http://dry-rb.org/gems/dry-transaction/basic-usage/, you inject additional arguments into steps by using #with_step_args