Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
Vladimir Dralo
@vladra
I see. Atm I’m overriding initializer, but just don’t like how it looks like. Thanks
Maciej Mensfeld
@mensfeld
@mrbongiolo yeah but I would like to have a hard error failure on a case like that to be honest
otherwise for internal usage it will create silnet issues like "why the heck isn't a key in the return" - I use dry-validations to define an internal data exchange format
Ralf Schmitz Bongiolo
@mrbongiolo
@mensfeld Ah I see, so unless the given input is exactly like the expected one you just want it to raise something. It should act like a Strict mode?
Tanner Donovan
@ttdonovan
I’ve just started playing around with Crystal and wanted to get some thoughts on porting some of the dry-rb gems .i.g. https://github.com/ttdonovan/dry-monads.cr
could shards be part of dry-rb or would there be any objection to spin-off a dry-cr
Gilbert Komin
@myf9000
Hi, everyone. I have small problem with form validation. I have optional array which can be empty or not - and when I want to use optional(:employee_attribiutes).maybe(:array?) - in test when I send empty params (nil) for this array - I’ve got a error: NoMethodError: undefined method `[]' for nil:NilClass. What I did wrong? :)
Tim Riley
@timriley
@myf9000 that test is not actually a fathful replication of a form post, since they can never send nil - always an empty string in cases like that. If you pass an empty string, does it work?
The dry-validation form schemas are meant to handle input from rack-processed forms posts.
Gilbert Komin
@myf9000

Thanks for answer but is any possibility to do something like that :

optional(:employee_attributes).maybe(:array?).each do
        key(:attribute_name).required(:str?)
        key(:value).required
        optional(:order).maybe(:int?)
 end

When I have in params employee_attributes I want to check its attributes, and when I have "" or nil or [] - return true. I tried to write my custom rule but it doesn’t work for array.

     optional(:employee_attributes).maybe(:array?)

      rule(present_employee_attributes: [:employee_attributes]) do |attributes|
        attributes.is_present?
      end

      configure do
        def is_present?(attributes)
          return true if attributes.empty?
          attributes
        end
      end

What I'm doing wrong?

Thanks to @flash-gordon, @mrbongiolo, @joevandyk and @ttdonovan!
Piotr Solnica
@solnic
@myf9000 maybe + each is not supported yet, I'll be adding this for 0.8.0 release
btw use schema inside each, nested key syntax will be gone in 0.8.0
Gilbert Komin
@myf9000
thanks a lot! when will be 0.8.0 release? :)
Dawid Leszczyński
@davebream
Hello everyone, I can not manage to validate array of integers using dry-validation. I want it to be required but check each value with int?. Can anybody help me?
Nikita Shilnikov
@flash-gordon
@myf9000 this month
Gilbert Komin
@myf9000
@flash-gordon Thanks
Piotr Solnica
@solnic
@davebream try key(:my_arr) { filled? & each { int? } } we’ll make it nicer in 0.8.0
Dawid Leszczyński
@davebream
@solnic when using it in Dry::Validation.Form I got
NoMethodError:
       undefined method `merge' for #<Dry::Types::Definition primitive=String options={}>
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `each'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `reduce'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `merge_with'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:48:in `visit_form_hash'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:23:in `visit_type'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:15:in `visit'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:53:in `visit_key'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:15:in `visit'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `block in merge_with'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `map'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:58:in `merge_with'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:48:in `visit_form_hash'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:23:in `visit_type'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:15:in `visit'
     # /bundle/gems/dry-types-0.6.0/lib/dry/types/compiler.rb:11:in `call'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation/input_processor_compiler.rb:16:in `call'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation/schema.rb:118:in `input_processor'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation/schema.rb:141:in `default_options'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation/schema.rb:45:in `new'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation.rb:36:in `Schema'
     # /bundle/gems/dry-validation-0.7.2/lib/dry/validation.rb:41:in `Form'
     # ./app/forms/api/v1/share_holidays_form.rb:34:in `schema'
     # ./app/forms/api/v1/share_holidays_form.rb:26:in `validate!'
     # ./app/forms/api/v1/share_holidays_form.rb:14:in `attributes'
     # ./spec/forms/api/v1/share_holidays_form_spec.rb:27:in `block (4 levels) in <top (required)>'
Piotr Solnica
@solnic
@davebream pls report an issue with a repro
Maciej Mensfeld
@mensfeld
@mrbongiolo exactly - I just want to know when something is not exactly as I defined
Oskar Szrajer
@gotar
Fast probably stupid question ;] how to list everything from container? To check what I have defined there
Tim Riley
@timriley
my_container.keys @gotar ?
Oskar Szrajer
@gotar
;] thx I was sure it must be sth obvious
Tim Riley
@timriley
Turned out the key was right before our eyes :wink:
Piotr Solnica
@solnic
hey folks, I improved/fixed how “safe” types work in dry-types which dry-validation heavily relies on and there were many known bugs that I think I fixed. please help with testing, just grab dry-v/t from master and lemme know if it works for you /cc @jodosha @timriley
Tim Riley
@timriley
Will take a look @solnic!
Fran Worley
@fran-worley
@solnic I think you've fixed dry-rb/dry-validation#125
Just checking the specs now
Fran Worley
@fran-worley
@solnic it looks like this can also be closed: dry-rb/dry-validation#133
Piotr Solnica
@solnic
@fran-worley I thought my commit would close them
Fran Worley
@fran-worley
@solnic I'm just updating the integration specs to check that all the skipped ones now pass
Piotr Solnica
@solnic
@fran-worley yeah we might need to tweak some of the specs, I noticed today that some specs had incorrect expectations
I fixed them but I didn’t have enough time to check xit specs
Fran Worley
@fran-worley
I'm going through them now. I'll PR in a few
Piotr Solnica
@solnic
sweeet
Fran Worley
@fran-worley
Are you happy for me to close the issues now fixed?
dry-validation issues: #125
Piotr Solnica
@solnic
@fran-worley yes please!
Fran Worley
@fran-worley
@solnic with regards to #134, would you raise the error when compiling the schema or when trying to validate ?
Piotr Solnica
@solnic
@fran-worley the dsl should yell when somebody tries to do that
Fran Worley
@fran-worley
so basically:
it "should raise error" do
  expect { Dry::Validation.Form do
      required(:foo).maybe(:none?)
    end }.to raise_error SomeError
end
Oskar Szrajer
@gotar

If I have container like:

require 'dry/web/container'

module Blog
  class Container < Dry::Web::Container
    setting :auto_register, 'lib'

    configure do
      load_paths!('lib')
    end
  end
end

and in lib directory I have for example repository, that require single arg when initialize, how I can do that? Container above register it automatically without any args,

module Persistence
  module Repo
    class Posts < ROM::Repository
      relations :posts

      def index
        posts.to_a
      end
    end
  end
end
>> Blog::Container['persistence.repo.posts']
ArgumentError: wrong number of arguments (given 0, expected 1)
    from /Users/gotar/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/bundler/gems/rom-repository-37ec20210a66/lib/rom/repository.rb:33:in `initialize'
Piotr Solnica
@solnic
@gotar you can use it with auto-inject thingie
include YourInjectModule[“your.rom.container”]
Oskar Szrajer
@gotar

hmm ok then I define sth like:

require_relative 'container'

module Blog
  Import = Container.import_module

  def self.Import(*args)
    Import[*args]
  end
end

and then

require "blog/import"

module Persistence
  module Repo
    class Posts < ROM::Repository
      include Blog::Import("persistence.rom")

      relations :posts

      def index
        posts.to_a
      end
    end
  end
end
??
those above do not works for me