by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Aug 09 16:13
    charly starred dry-rb/dry-initializer
  • Aug 09 03:48
    slashpai starred dry-rb/dry-system
  • Aug 08 14:57
    bobwhitelock starred dry-rb/dry-types
  • Aug 07 14:18
  • Aug 06 20:26
    psilospore starred dry-rb/dry-monads
  • Aug 06 08:32
    solnic commented #32
  • Aug 06 08:30
    solnic milestoned #32
  • Aug 06 03:05
    razertory starred dry-rb/dry-monads
  • Aug 06 01:46
  • Aug 05 14:01
    francois commented #32
  • Aug 04 12:29
    flash-gordon commented #403
  • Aug 04 10:46
    adamransom commented #403
  • Aug 04 10:17
    solnic commented #403
  • Aug 04 10:03
    adamransom commented #403
  • Aug 04 09:42
    adamransom commented #403
  • Aug 04 09:39
    solnic commented #403
  • Aug 04 09:36
    adamransom commented #403
  • Aug 04 09:35
    adamransom commented #403
  • Aug 04 09:33
    solnic commented #403
  • Aug 04 09:29
    adamransom edited #403
Artemiy Solopov
@art-solopov
And here's the app/forms/bill_form.rb:
class BillForm < ApplicationForm
  attribute :period_month, Types::Params::Integer.default { Time.zone.today.month }
  attribute :period_year, Types::Params::Integer.default { Time.zone.today.year }
  attribute :cost, Types::Params::Float.default(0.0)
  attribute :paid_at, Types::Params::Date.optional.default(nil)
  attribute :state, Types::Coercible::String.default('init')
  attribute :payment_method_id, Types::Params::Integer.optional.default(nil)
  attribute :tags, Types::Coercible::Array.of(Types::Coercible::String).default([])

  SCHEMA = Dry::Validation.Params(BillBasicSchema)

  attr_accessor :errors

  def self.from_model(model)
    period = model.period || Time.zone.today
    attrs = model.values.slice(:cost, :state, :paid_at,
                               :payment_method_id, :tags)
              .merge(period_month: period.month, period_year: period.year)
    new(attrs)
  end

  def self.new_attrs(overrides = {})
    period = Time.zone.today
    overrides.reverse_merge(state: :init,
                            period_month: period.month,
                            period_year: period.year)
  end
end
choallin
@choallin
Hey guys! I have a strange problem with dry-validations... . I have a validate block in my scheme and, if I have an error in it I get the message that it fails.
But when I want to access the errors, I get the error TypeError (no implicit conversion of Hash into String)
I tried to access the errors with the errors and the messages methods but I get the same error everytime...
Kacper Pucek
@KacperPucek

Is it possible to use validate in combination with each? Let me show the example:

Dry::Validation.Params do
  required(:tickets).each do
    validate(allowed_quantity: %i(selling_strategy quantity)) do |selling_strategy, quantity|
      # Some logic for checking if quantity can be used
    end

    required(:price).filled(:int?)
    required(:quantity).filled(:int?)
    required(:selling_strategy).filled(:str?)
  end
end

While required checks are nicely nested under tickets, allowed_quantity always bubbles to the top. It would look like this:

{:tickets => { 0 => {:price => ["is missing"]}, :allowed_quantity => ["some msg]}

Any ideas how to nest this custom validation block as well? Cheers!

Kacper Pucek
@KacperPucek
For anyone interested: dry-rb/dry-validation#305
Chris Richards
@cmrichards

Hi, is it possible to validate the keys and values of a hash like this? These are the posted params.

{
 "sample_tests"=>{
   "1"=>{"sample_id"=>149, "lod"=>"200.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2}, 
   "2"=>{"sample_id"=>149, "lod"=>"101.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2}, 
   "3"=>{"sample_id"=>149, "lod"=>"101.0", "lod_top_unit_id"=>2, "lod_bottom_unit_id"=>1, "top_unit_id"=>2},
   ..... repeated
  }
}

This is all I have right now. :

      Schema = Dry::Validation.Params do
        required(:sample_tests).filled
      end

I need to validate the part that goes {"sample_id"=>149, "lod"=>"200.0", "lod_top_unit_id"=>2.....

There is no mention of a repeated key like this in the dry-types docs. Maybe I need to convert the hash into a simple array before validating?
Piotr Solnica
@solnic
@cmrichards not possible yet, it'll be supported in dry-schema
Chris Richards
@cmrichards
Sweet :-) . must. resist. urge. to. ask. when. is. it. ready.
Jeff Dickey
@jdickey
"Resistance is futile", sayeth the Borg. Locutus 1:1
Brice Sanchez
@bricesanchez
Hi ! Is input preprocessing works on Dry::Validation.Schema ? I would like to convert string id to integer before validating it
@timriley Thanks for your previous answer, for now i use Module include for resuable methods and i use guard style for conditional steps
Brice Sanchez
@bricesanchez
Ok I've seen this dry-rb/dry-validation#357
So i've created a Dry::Validation::Params
Piotr Solnica
@solnic
@cmrichards not sure
Ethan Turkeltaub
@ethnt
Hey again 👋 is it possible to have optional nested hashes within dry-struct?
Nikita Shilnikov
@flash-gordon
@ethnt hashes or structs? Regardless the answer, yes, it's possible
you can use recently added method for this https://github.com/dry-rb/dry-struct/blob/master/CHANGELOG.md#added
Mikhail Slyusarev
@mikhailvs
hey, is there a way to easily reuse procs for calls to validate() within schemas? when i assign procs to variables (and call as validate(validation_key: %I[param1 param2], &stored_proc)), I get "+proc+ is not a valid predicate name"
it does however seem to work if instead of doing stored_proc = proc { |a, b| a <= b } I do stored_proc = Proc.new { |a, b| a<= b }, but that way makes rubocop unhappy. why does doing the proc {} syntax not work?
Nikita Shilnikov
@flash-gordon
because proc isn't defined within schema's DSL
you can use ::Kernel.proc
Alexander
@cutalion
hi there! is it possible to translate keys in dry-v errors?
Tonni Tølbøll Lund Aagesen
@ta
require "dry-struct"

module Types
  include Dry::Types.module
end

class User < Dry::Struct
  attr_writer :name

  attribute :name, Types::Strict::String.optional.default(nil)
end

u = User.new
puts u.inspect
u.name = "Steve"
puts u.inspect
The attr_writer statement used to work in dry-struct v0.4 but it doesn't work in v0.6 - is this by design?
Chris Richards
@cmrichards
I thought dry-struct was immutable by design so I'm surprised this ever worked as intented
Nikita Shilnikov
@flash-gordon
it never worked like this, using writers will ignore type checks
Chris Richards
@cmrichards
yeah that's what I guessed
Nikita Shilnikov
@flash-gordon
as for storing values in attributes, this was changes and mentioned in the changelog
since I foresaw this could break "someone's workflow" :)
Chris Richards
@cmrichards
haha brutal
Tonni Tølbøll Lund Aagesen
@ta
Oh, silly me :)
what is the right way of writing storing values in attributes - or is dry-struct not meant for that?
Nikita Shilnikov
@flash-gordon
the right way is to create a new struct based on an existing one
i.e. user.new(name: 'John Doe')
.new is an instance method
Tonni Tølbøll Lund Aagesen
@ta
@flash-gordon Great! thanks
Chris Richards
@cmrichards
My name is Chris and I don't understand Rails autoloading. Suddenly, many of my tests are failing because I need to place :: in-front of module names that I previously didn't have to. Frustrating.
Piotr Solnica
@solnic
it's an abomination
Jaromír Červenka
@Cervajz
@solnic The rails version or code reloading as a concept?
Piotr Solnica
@solnic
autoloading and reloading in rails
Grant Shangreaux
@gcentauri
is anyone here at rubyconf?
Andy Holland
@AMHOL
I wish, have fun @gcentauri :)
Nick Luparev
@SuperManEver

I need some help
suppose I have few steps in my transation declared as

step :store_params
step :assign_record_attributes

how store_params will give a control to assign_record_attributes and pass some params along the way?

Jaromír Červenka
@Cervajz
@SuperManEver What do you mean by give a control?
Nick Luparev
@SuperManEver
store_params finished its job and assign_record_attributes should continue
Jaromír Červenka
@Cervajz
A step can return only two states: Success(some_data) or Failure(some_data_or_error). Transaction will run the next step if the previous one returned Success
If you want to pass some data to the next step give it to the Success(<data_here>) object
Nick Luparev
@SuperManEver
how do I send multiple things, using hash?