These are chat archives for dry-rb/chat

5th
Jan 2016
Piotr Solnica
@solnic
Jan 05 2016 00:08
@timriley wdym?
Tim Riley
@timriley
Jan 05 2016 00:08
I’m currently debugging more deeply
but my initial issue was this:
It wants the constraints to be supplied as a hash, but there’s no “value” or argument for filled?
and it also crashes, whatever I put in there as a placeholder
:)
Here’s the issue
Piotr Solnica
@solnic
Jan 05 2016 00:11
I need a repro script. Sorry
Tim Riley
@timriley
Jan 05 2016 00:11
Here you go:
# require "bundler/setup"
require "dry-validation"
require "dry-data"
require "dry/data/type/constrained"
# require "byebug"

FilledString = Dry::Data['string'].constrained(filled: nil)
Piotr Solnica
@solnic
Jan 05 2016 00:11
And I'll take a look tomorrow. 1am over here :)
Tim Riley
@timriley
Jan 05 2016 00:11
And here’s the issue I found in debugging
Piotr Solnica
@solnic
Jan 05 2016 00:11
Tech speaking today, but later
Tim Riley
@timriley
Jan 05 2016 00:12
inside dry-v’s RuleCompiler#visit_predicate, I have a breakpoint and do the following:
Piotr Solnica
@solnic
Jan 05 2016 00:12
filled is for forms
Tim Riley
@timriley
Jan 05 2016 00:12
(byebug) predicates[:format?].curry(*args)
#<Dry::Validation::Predicate id=:format?>

(byebug) predicates[:filled?].curry(*args)
*** TypeError Exception: wrong argument type TrueClass (expected Proc)
which is the source of the crash
Anyway, I’ll think about other ideas. Have a good sleep :)
Piotr Solnica
@solnic
Jan 05 2016 00:13
OK pls report an issue and we can take it from there
Tim Riley
@timriley
Jan 05 2016 00:13
sure thing :)
Piotr Solnica
@solnic
Jan 05 2016 00:13
I'm literally in bed now lol
Tim Riley
@timriley
Jan 05 2016 00:13
hahaha
Piotr Solnica
@solnic
Jan 05 2016 00:14
I'll get back to you when I'm awake :) :zzz:
Tim Riley
@timriley
Jan 05 2016 00:14
Gnight!
Hannes Nevalainen
@kwando
Jan 05 2016 10:38
I want to delay initialization of an object until it is needed. Is there a way of dry-container to memoize a block?
container.register('my_object'){ HeavyObject.new }
I want my heavy object "cached" or memoized
Piotr Solnica
@solnic
Jan 05 2016 11:19
@kwando we’ve been talking about this many times, still undecided where this should be done, I’m leaning towards using some singleton pattern for classes that should be lazy-initializable but singleton
and not polluting container’s apis with this
Andre Stuhrmann
@Khalasar
Jan 05 2016 12:47
Is there a way to mix strict and optional keys in a hash?
require 'dry/data'

mixed_hash = Dry::Data['hash'].strict(
  :first_name => 'string',
  :last_name => 'string',
  :middle_name => 'string', # optional?
)

p mixed_hash.call(first_name: "Foo", last_name: "Bar", middle_name: "Baz")
# Should also work
p mixed_hash.call(first_name: "Foo", last_name: "Bar")
Piotr Solnica
@solnic
Jan 05 2016 12:49
@Khalasar no, all keys must be present
if you want to use it for validation then use dry-validation rather than dry-data