Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 08:53
    flash-gordon labeled #376
  • 08:44
    solnic commented #376
  • Dec 12 21:34
    flash-gordon commented #376
  • Dec 12 21:34
    flash-gordon labeled #376
  • Dec 12 21:34
    flash-gordon opened #376
  • Dec 12 19:32
    RyanLafferty starred dry-rb/dry-types
  • Dec 12 05:53
    technofreak starred dry-rb/dry-monads
  • Dec 12 00:14
    thekuwayama starred dry-rb/dry-monads
  • Dec 11 09:29
    blasterun starred dry-rb/dry-monads
  • Dec 11 08:34
    flash-gordon closed #115
  • Dec 11 08:34
    flash-gordon commented #115
  • Dec 11 08:31

    flash-gordon on v1.3.3

    (compare)

  • Dec 11 08:30

    flash-gordon on master

    Bump version to 1.3.3 (compare)

  • Dec 11 08:30

    flash-gordon on master

    Update CHANGELOG (compare)

  • Dec 10 23:46
    johnmaxwell commented #116
  • Dec 10 21:54

    flash-gordon on master

    Halt with mutable backtrace Ex… Merge pull request #116 from jo… (compare)

  • Dec 10 21:54
    flash-gordon closed #116
  • Dec 10 21:54
    flash-gordon commented #116
  • Dec 10 21:49
    johnmaxwell commented #116
  • Dec 10 21:47
    johnmaxwell commented #116
Eugene Khutko
@FoboCasteR
Also, it seems to me inconvenient that Result from Dry::Types instead of Dry::Monads
Piotr Solnica
@solnic
@FoboCasteR we could consider changing it to use Dry::Monads
Gustavo Caso
@GustavoCaso
I should not be a hard change to make
Eugene Khutko
@FoboCasteR
@GustavoCaso Maybe. But this change will make dry-monads a hard dependency.
Gustavo Caso
@GustavoCaso
Yes definitely it will make a dependency of dry-types
Pablo Herrero
@pabloh
Any Idea why this works:
class SubForm < Form
  define! do
    required(:foo).filled(:int?)
    optional(:bar).maybe(:int?)
  end
end

class MainForm < Form
  define! do
    required(:qux).filled(:int?)

    optional(:bar).maybe do
      schema(SubForm.new) # Using new
    end
  end
end
But this doesn't?:
class SubForm < Form
  define! do
    required(:foo).filled(:int?)
    optional(:bar).maybe(:int?)
  end
end

class MainForm < Form
  define! do
    required(:qux).filled(:int?)

    optional(:bar).maybe do
      schema(SubForm) # Using class directly
    end
  end
end
Gustavo Caso
@GustavoCaso
:clap: :clap:
Jeff Dickey
@jdickey
:tada:
Vasily Kolesnikov
@v-kolesnikov
:fire: :+1:
Chris Richards
@cmrichards
Is Factory Girl a good technique to create dB objects use during testing with a new app that will use dry-validation heavily when creating records from form data? Or would it be better to create servicey-type objects and only use them to setup initial DB data in tests?
Piotr Solnica
@solnic
@cmrichards whatever works, we use rom-factory but it's not as mature as FactoryBot (reminder: they renamed the gem)
Chris Richards
@cmrichards
ok. I thought you'd use the same service objects you create in your app to make the objects required in your tests. e.g. CreateCompany.({...}).
Chris Richards
@cmrichards
My concern with using something like factory-bot is that it's a third place you need to maintain the idea of what a valid object is: tests, normal-code, and factory-bot.
Chris Richards
@cmrichards
The functional style of dry-validation::Form is great. The way simple_form and rails renders forms using the form-object/AM-interface is also great. I want some way of living in both worlds, but im not sure if it is possible
@solnic how do you render forms? Do you just pass in a hash to the form renderer rather than any kind of form object?
Chris Richards
@cmrichards
So it seems like this can't be placed in a Service superclass: include Dry::Matcher.for(:call, with: Dry::Matcher::EitherMatcher)
Piotr Solnica
@solnic
@cmrichards we use an in-house gem called formalist
Chris Richards
@cmrichards
Strange. I have to turn rails' params into a hash before the string will be accepted as an integer:
(byebug) params[:company_branch]
<ActionController::Parameters {"company_id"=>"9", "name"=>"", "address"=>"", "post_code"=>"", "phone"=>""} permitted: true>
(byebug)  CreateCompanyBranch.new.call(params[:company_branch])
Failure({:company_id=>["must be an integer"], :name=>["must be filled"]})
(byebug)  CreateCompanyBranch.new.call(params[:company_branch].to_h)
Failure({:name=>["must be filled"]})
Scott Eckenrode
@selectport
@cmrichards - assuming you're on rails 5 now - params now returns a ActionController::Parameters object which is not hash-like itself
roma
@milushov

Hey guys, mb somebody already asked, but I did not find; so can u help me find information about:

How to add custom variable to the error message?

en:
  errors:
    minimum_amount?: "amount must be greteat or equal to %{minimum}, yours is %{value}"

I have the value, but what is the best way to pass minimum variable to the err message?

Pablo Herrero
@pabloh

Sorry, an idea why this works:

class SubForm < Form
  define! do
    required(:foo).filled(:int?)
    optional(:bar).maybe(:int?)
  end
end

class MainForm < Form
  define! do
    required(:qux).filled(:int?)

    optional(:bar).maybe do
      schema(SubForm.new) # Using new
    end
  end
end

but this doesn't:

class SubForm < Form
  define! do
    required(:foo).filled(:int?)
    optional(:bar).maybe(:int?)
  end
end

class MainForm < Form
  define! do
    required(:qux).filled(:int?)

    optional(:bar).maybe do
      schema(SubForm) # Using class directly
    end
  end
end

?

Aaron Barthel
@abrthel
@pabloh a couple of questions, what's Form and what are you trying to do with these schemas, are you just trying to be able to reuse them or are you trying to create some form of base schema that other schemas can build off of?
Aaron Barthel
@abrthel
I'm just going to take a leap of faith and assume you're most likely just looking for reusable validation schemas. Hopefully that's the case :smile:
SubForm = Dry::Validation.Form do
  required(:foo).filled(:int?)
  optional(:bar).maybe(:int?)
end

MainForm = Dry::Validation.Form do
  required(:qux).filled(:int?)
  optional(:bar).maybe do
    schema(SubForm)
  end
end
Chris Richards
@cmrichards
Might be nice if my Dry::Matcher::EitherMatcher when used as service-objects would throw an exception if a success and failure block aren't used - not sure though.
Tim Riley
@timriley
@cmrichards dry-matched already raises an exception if the result block isn’t exhaustive (ie. If it doesn’t provide handlers for all cases)
Dry-matcher I mean
Is that what you were asking?
Chris Richards
@cmrichards
so it does!
--thumbs-up--
Tim Riley
@timriley
:information_desk_person:
Pablo Herrero
@pabloh
@abrthel , sorry I couldn't answer you yesterday, Form is just Dry::Validation::Schema::Form.
And what I was trying to do is define base forms so you can latter extend them by doing:
class AppForm < Dry::Validation::Form
  define! do
    # define common rules, if any
  end
end

MyForm = Dry::Validation.Schema(AppForm) do
  # define your rules
end
I was surprised you could do Dry::Validation.Schema(AppForm) but required(:foo).schema(AppForm) would not work.
Since apparently the schema method can take a class as parameter: https://github.com/dry-rb/dry-validation/blob/master/lib/dry/validation/schema/rule.rb#L31
Aaron Barthel
@abrthel
@pabloh, you're running into a problem of definitions vs instanced objects. When you use Dry::Validation.Form you're actually creating an instance of a schema but when you subclass Dry::Validation::Schema::Form all you have is the subclass but it isn't an instantiated instance... if that makes sense. Methods like required(:qux).schema() need schema instances to work which is why you needed Subform.new
Can you describe the situation where you need to define a base schema that also references another base schema?
An example of what I mean by an instance problem
SubForm = Dry::Validation.Form do
  required(:foo).filled(:int?)
  optional(:bar).maybe(:int?)
end

class MainForm < Dry::Validation::Schema::Form
  define! do
    required(:qux).filled(:int?)

    optional(:bar).maybe do
      schema(SubForm)
    end
  end
end

schema = Dry::Validation.Form(MainForm) do
end

puts schema.call({qux: 1, bar: {foo: 2, bar: 'f'}}).inspect
Chris Richards
@cmrichards
Does anyone know how to grab the Dry::Validation.Form from a Reform::Form class?
Aaron Barthel
@abrthel
@cmrichards Probably a question to as over at https://gitter.im/trailblazer/chat
Chris Richards
@cmrichards
it's ok now, I solved this a different way
thanks
Chris Richards
@cmrichards
hmmm... I wonder how safe it is to add a before_action for params = params.to_h
Vasily Kolesnikov
@v-kolesnikov
Hi! Is it possible to configure dry-inflector to camelize('rss') as 'RSS'?
Gustavo Caso
@GustavoCaso
There is an issue open at the moment for that sort of problems
dry-rb/dry-inflector#16
dry-rb/dry-inflector#19
Chris Richards
@cmrichards
What does the exclamation point do here? result.value!
Success / Failure are better than Right / Left. Good change :-)