Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jan 18 14:38

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:38

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:38

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:38

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:38

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:37

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:37

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:37

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:37

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:37

    dry-bot on master

    [devtools] sync configs (compare)

  • Jan 18 14:15

    dry-bot on master

    [devtools] update CHANGELOG.md (compare)

  • Jan 18 14:15

    flash-gordon on master

    Fix YAML syntax (compare)

  • Jan 18 14:10

    flash-gordon on master

    gitignore .vscode Update changelog.yml (compare)

  • Jan 18 14:02

    flash-gordon on fix-key-optional

    (compare)

  • Jan 18 14:02

    flash-gordon on master

    Fix Schema::Key#optional It us… Merge pull request #385 from dr… (compare)

  • Jan 18 14:02
    flash-gordon closed #385
  • Jan 18 13:57
    dry-bot commented #385
  • Jan 18 13:55
    flash-gordon opened #385
  • Jan 18 13:54

    flash-gordon on fix-key-optional

    Fix Schema::Key#optional It us… (compare)

  • Jan 18 13:54

    dry-bot on master

    [devtools] sync configs (compare)

Alfonso Perez
@alfonsoperez
one hint I guess is that it says Types::AnswerOutcome, where it should say MyModel::Types::AnswerOutcome
Alfonso Perez
@alfonsoperez
(I am doing MyModel::Types::AnswerOutcome in another file and that's where it's failing)
Luca Guidi
@jodosha
@wafcio @solnic yay! :sparkles: :clap:
Steve
@dnd
I'm trying to validate an object that has an array of hashes where I want the sum of values from one of the hash keys to match a key from the main object. {total: 123, items: [{amount: 22}, {amount: 193}]} What complicates this is that I was thinking of defining the validation on items, but that means that if there are validation issues with some of the other content in the items hashes that the errors returned may sometimes be an array of error strings, other times an array of error hashes
Ramon Tayag
@ramontayag
How do I make initialization hash keys optional?
class Car < Dry::Struct
  attribute :brand_name, Types::String.optional
  attribute :model_number, Types::String.optional
end
Car.new(model_number: "81AC") # raises Dry::Struct::Error, ":brand_name is missing in Hash input"
Piotr Solnica
@solnic
@ramontayag constructor_type :schema
Ramon Tayag
@ramontayag
Thanks - not familiar with that macro. Will check it out.
Piotr Solnica
@solnic
@ramontayag structs can use different hash schema types from dry-types, it's strict by default so all keys are expected to be present in attributes hash that's passed to .new
Ramon Tayag
@ramontayag
Ok thanks for the explanation @solnic!
If anyone's interested, just putting this out there: https://github.com/imacchiato/dry-validation-matchers
Jeff Dickey
@jdickey
@ramontayag That's Useful :smiley:
Ramon Tayag
@ramontayag
@solnic I want to add something to the readme about constructor_type to the readme. As far as I can see, there are these types: :strict, :permissive, and :schema. I guess you meant that it is :strict by default, but what is the difference with the latter two?
Let me check dry-types first
Ramon Tayag
@ramontayag
There are certain schemas in the codebase of dry-struct that can't be found in http://dry-rb.org/gems/dry-types/hash-schemas/ that
Ramon Tayag
@ramontayag
For dry-struct, what is the recommended way of creating setters?
Ramon Tayag
@ramontayag
@jdickey cool :)
Piotr Solnica
@solnic
@ramontayag the recommend way is to not use setters :)
Piotr Solnica
@solnic
@ramontayag there’s a WIP PR which will add more docs about it dry-rb/dry-rb.org#104
Ramon Tayag
@ramontayag
@solnic ok cool I can discard my changes then! How would you go about replacing virtus with the dry gems? Would you recommend doing so?
Hannes Nevalainen
@kwando
dry-validation is freaking awesome! xD
Steve
@dnd
@timriley, @solnic I posted my question from the other day on the discussion board, but haven't gotten any traction on it. Any idea if there is a way to easily do this currently, or where I could start looking to make it possible? https://discuss.dry-rb.org/t/get-keys-instead-of-sentences-for-validation-errors/150/1
Piotr Solnica
@solnic
@dnd hey, I’ll be replying to posts later today. I’ve been busy with rom-sql new release lately
Steve
@dnd
cool, thanks
Lucas Hosseini
@beauby
Any specific reason why no built-in predicates on min/max length of strings in dry-validation?
Fran Worley
@fran-worley
@beauby there are built in predicates. min_size? And max_size? Work on anything that responds to size.
Lucas Hosseini
@beauby
Hmm some examples seem to imply that the _size? predicates work on string, but the doc says it is valid for arrays only
Fran Worley
@fran-worley
Take a look here to see all built in predicates and the code behind them: https://github.com/dry-rb/dry-logic/blob/master/lib/dry/logic/predicates.rb
Lucas Hosseini
@beauby
@fran-worley Right – yeah, that was my source of information, but as you can see, it explicitly talks only about arrays
I’ll issue a PR
Fran Worley
@fran-worley
Good spot on the docs and thanks in advance for the PR.
Piotr Solnica
@solnic
@kwando haha, is it? :D
@dnd re virtus, you need dry-struct + attr_writer
then, assuming your virtus models are relatively simple, this should be easy
just remember that dry-struct uses types that don't match virtus coercion logic
so ie if you use input from http params, you would have to use Types::Form::* types for your attributes
Steve
@dnd
@solnic I think someone else was looking for that information.
I think @ramontayag was?
I'm just here for the dry-validation errors question. :)
Piotr Solnica
@solnic
ugh sorry about that
@ramontayag see above re virtus ^^
Ramon Tayag
@ramontayag
I see - thanks @solnic
Ramon Tayag
@ramontayag

Given

schema = Dry::Validation.Schema do
  required(:age)
end

I expect to see an error that the key is missing when I do schema.({}).errors. Am I understanding right?

Soumya Ray
@soumyaray

I'm playing around with dry-monads for the first time, and I'm not sure if I'm using it as expected. Here's an example of a simple service object that I'm trying to make using it:

class FindGroup
  extend Dry::Monads::Either::Mixin

  def self.call(params)
    Right(params[:id]).bind do |group_id|
      group = Group.find(id: group_id)
      if group
        Right(group)
      else
        Left(Error.new(:not_found, 'Group not found'))
      end
    end
  end
end

Does this look right? Should I be using dry-transactions or something else over this?

The thing that is bothering me most right now is that this style of coding very quickly becomes hard to read with more complex examples.

Nikita Shilnikov
@flash-gordon
@soumyaray more or less, could be simplified ```
  def self.call(params)
    group = Group.find(id: params[:group_id])
    if group
      Right(group)
    else
      Left(Error.new(:not_found, 'Group not found'))
    end
  end
monads are just some sort of containers
they are giving you a unified interface for dealing with things, but nothing more
dry-transaction is an example of what you can do next by gluing your monads together :)
@soumyaray we often recommend this video to watch http://fsharpforfunandprofit.com/rop/
Soumya Ray
@soumyaray

@flash-gordon i agree! i was a influenced by the documentation of dry-monads, which has this:

    i = Integer(input)

    Right(i).bind do |value|
      if value > 1
        Right(value + 3)
      else
        Left("value was less than 1")
      end
    end.bind do |value|
      if value % 2 == 0
        Right(value * 2)
      else
        Left("value was not even")
      end
    end

I'll sit and give that video a watch. Like with many things that are new to Ruby (concurrency paradigms, monads, etc.), it really hard for those of use who haven't seen those used in another language.