Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 21 13:50
  • Nov 20 19:40
    lancecarlson starred dry-rb/dry-monads
  • Nov 20 15:22
    scaint starred dry-rb/dry-monads
  • Nov 20 11:05
    FunkyloverOne starred dry-rb/dry-monads
  • Nov 20 06:22
    zlei1 starred dry-rb/dry-web
  • Nov 18 00:58
    dteoh starred dry-rb/dry-types
  • Nov 17 21:02
    flash-gordon commented #374
  • Nov 17 21:01

    flash-gordon on master

    Update custom_ci.yml Merge pull request #374 from sk… (compare)

  • Nov 17 21:01
    flash-gordon closed #374
  • Nov 17 20:59
    skryukov opened #374
  • Nov 17 16:42

    flash-gordon on use-immutable-equalizer

    (compare)

  • Nov 17 16:42

    flash-gordon on master

    Use immutable equalizer for all… Merge pull request #373 from dr… (compare)

  • Nov 17 16:42
    flash-gordon closed #373
  • Nov 17 16:38
    flash-gordon opened #373
  • Nov 17 16:38

    flash-gordon on use-immutable-equalizer

    Use immutable equalizer for all… (compare)

  • Nov 17 16:34

    flash-gordon on no-rewrap-for-structs

    (compare)

  • Nov 17 16:34

    flash-gordon on master

    Don't build constructors when c… Merge pull request #371 from dr… (compare)

  • Nov 17 16:34
    flash-gordon closed #371
  • Nov 16 11:28
    marekciupak starred dry-rb/dry-monads
  • Nov 16 07:48
    luizfonseca starred dry-rb/dry-view
Jeff Dickey
@jdickey
Initialising with DateTime.now works when using Types::Strict::DateTime.default { DateTime.now }; it does not work when attempting to use a constant defined as Types::Strict::DateTime.default { DateTime.now }
Nikita Shilnikov
@flash-gordon
@jdickey try DateTimeOrNow = Types::Strict::DateTime.default { ::DateTime.now }
in Types module you have a clash with Types::DateTime constant
Piotr Solnica
@solnic
@rusilko heyyy sorry for this late reply, so in a nutshell: let's start with strong-params replacement, this is basically a schema that defines which keys are required and optional and what the types should be. Once we have that, along with some railitie that sets things up for you, we can think about what to do with model validation, I think the next natural would be to move validation out from AR models and provide some smooth integration with AM (although that is, IIRC, covered by gems like reform, so maybe makes no sense to go that far). All this stuff should go to a separate gem dry-validation-rails which provides Dry::Validation::Rails namespace with all the needed APIs. /cc @Ch4s3
oh and yes, we could create a separate channel for dry-validation, it's probably the biggest gem we have with adoption growing fast...
@gotar apologies for my rough reply, I was...driving :P anyhow, re keeping rails stuff separate - this will speed up development, ie I don't use rails (I guess you know that already :)) so I don't want to deal with rails-related code when working on OSS, that's pretty much it, it adds friction to dev cycles that I really don't like, and don't have time/energy to deal with this
one minor benefit is also that it screams "look how many gems need rails-specific code just to make them usable with rails"
at least I see some value in this kind of manifestation (maybe not the right word)
Ralf Schmitz Bongiolo
@mrbongiolo
@mensfeld I'm not sure if I understood you correctly, but for what you what you should use the Sanitizer input_processor, it will ignore any fields that are not declared in your schema.
configure do
  config.input_processor = :sanitizer
end
Tomek Rusiłko
@rusilko
@solnic hey, no probs. Thanks for clarifing things. So, pls set up a channel and lets start hacking away on it :) cc/ @Ch4s3
Chase Gilliam
@Ch4s3
@rusilko sounds good. @solnic Do you want dry-validation-rails to live in dry-rb or somewhere else?
Piotr Solnica
@solnic
@Ch4s3 dry-rb org :ok_hand:
Chase Gilliam
@Ch4s3
@solnic I thought so. If you want to fire up a repo, I can start work this weekend.
John Backus
@backus
require 'bundler/setup'
require 'dry/validation'

Dry::Validation.JSON do
  hash? do
    required(:data).schema do
      required(:foo).value(:int?)
    end
  end
end
/Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `merge': no implicit conversion of Dry::Types::Safe into Hash (TypeError)
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `each'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `reduce'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:80:in `merge_with'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:67:in `visit_json_hash'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:28:in `visit_type'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:15:in `visit'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-types-ce8761715332/lib/dry/types/compiler.rb:11:in `call'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/input_processor_compiler.rb:16:in `call'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:125:in `input_processor'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:148:in `default_options'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation/schema.rb:46:in `new'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation.rb:37:in `Schema'
  from /Users/johnbackus/.rvm/gems/ruby-2.3.1/bundler/gems/dry-validation-fa557778ff0f/lib/dry/validation.rb:46:in `JSON'
  from test.rb:36:in `<main>'
Should I open an issue?
Chase Gilliam
@Ch4s3
yeah
John Backus
@backus
k
Jeff Dickey
@jdickey
@flash-gordon D'oh! Should have seen that! Thanks, @flash-gordon! Gist updated, including credit
Nikita Shilnikov
@flash-gordon
@jdickey no problem, your gist was very helpful in reproducing the error, it took a couple of seconds, really
Jeff Dickey
@jdickey
@flash-gordon cool; thanks again
Vladimir Dralo
@vladra
hi guys
I’m new to dry-types and I’m wondering if it is possible to define custom type for ActiveRecords::Relation? I’m passing scope from controller to service, but not sure how to solve this
Piotr Solnica
@solnic
@vladra could you tell me what are you trying to do? what would that type do?
Vladimir Dralo
@vladra
@solnic I have a service, which requires scoped relation from controller (after applying specific scope permissions). It needs to be lazy, so query is not executed before I need to. So I have an ability to filter it further inside service. And I wanted to use dry-types to make sure that Relation/Scope is passed there or fail otherwise. But maybe I’m going in wrong direction and you can give me the tip on better approach
Piotr Solnica
@solnic
types should deal with simple values, AR::Relation feels a bit too much
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