These are chat archives for dry-rb/chat

Aug 2016
Krzysztof Wawer
Aug 26 2016 06:34
@solnic What is the difference between load_path and auto_register ? In example code (dry-system) you use these two methods with the same arguments. I read dry/system/container.rb but unfortunatelly I still don’t know the difference
Tim Riley
Aug 26 2016 07:11
Load path just adds the directories to Ruby's $LOAD_PATH
Krzysztof Wawer
Aug 26 2016 07:22
I have just found small bug in dry-system, comment say that system_dir by default is component but in code I see system value. I can send PR with fix it but I don’t know which part should be changed
Michał Pietrus
Aug 26 2016 07:27
Hi @elskwid ! Nah, not yet... From what I remember, the Rails.application.config.to_prepare performs after reloading so I've started with ActionDispatch::Reloader.to_prepare. However, even though I explicitly override the container instance (AppContainer.instance_variable_set('@_container',, the underlying problem still persists. I've seen how dry-t rails solves this problem, but I'm not sure it would help. I'll start with it again in September
Andrew Kozin
Aug 26 2016 07:37

I think, the error you've reported yesterday, caused not by super method (it should work), but unexpected data you send to the initializer.

This definition

class IsobusExportAdapter
  extend Dry::Initializer::Mixin

  option :application_map_id
  option :field_id
  option :strategy_bundle_id
  option :worker

is equal to

def initializer(application_map_id:, field_id:, strategy_bundle_id:, worker:)

Notice, that this method expects hash with symbolic keys, not strings. If you try to send something like this

{ "application_map_id" => 1, ... }

Then you'll receive exactly the same error you've reported:

ArgumentError: wrong number of arguments (1 for 0)

So the solution of your problem would be like this (if you want to send hash with indifferent access to the initializer):

class IsobusExportAdapter
  # ...

  def initialize(hash)
    # symbolize keys of the input hash
    super(hash.each_with_object({}) { |(key, val), obj| obj[key.to_sym] = val })
(OMG, I wonder whether I like this parrot style of snippets)
Tim Riley
Aug 26 2016 08:51
@wafcio the right name should be "system" - thanks!
Sergey Kukunin
Aug 26 2016 08:53
is there a way in dry-v to set empty value for key in output array, even there was no key in input hash. Like
MySchema = Dry::Validation.Form do
validation ={})
validation.output[:key] == nil
Piotr Solnica
Aug 26 2016 09:20
@Kukunin nope, schema doesn’t fill in missing data
Jānis Miezītis
Aug 26 2016 20:27
Guys, in my schema I have - required(:email).filled({format?: EMAIL_RGEXP}, :email_unique?)
Where :email_unique? is a call to DB. The problem that I have is that if first validation fails, there are two error messages appearing even if the email is not already taken. Same stuff happens if I do it vice versa. Both for format and email uniquiness:
:email => ["Email is in invalid format", "Email is already taken"]
Adam Davies
Aug 26 2016 20:50
@janjiss I just started with dry-validation and had similar thing happen (cc @yujiyokoo ). I’d like to understand what should happen… but we got around it by adding a second rule:
rule(email: [:email]) do |email|
  email.format? & email.email_unique?
and first one just had required(:email).filled(:str?)
Jānis Miezītis
Aug 26 2016 20:54
@adz Thank you for the reply!
Literally just arrived at the same solution :)
Adam Davies
Aug 26 2016 21:03

…cool. but I’d like to understand why ‘required’ seems to exectute all, but ‘rule’ doesn’t. Is that expected behaviour?
If it’s not filled in I assumed intuitiviely the subsequent validations wouldn’t run…

Is there a better way to express the dependency of validations?

Tim Riley
Aug 26 2016 23:40
@adz @yujiyokoo @janjiss what you’re seeing there are validation hints, and it’s true that they need a little more work. We’ve had some discussion about these in, which’d be worth a read.