Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • 05:41

    solnic on main

    Add missing require (compare)

  • Nov 30 05:17
    jacortinas starred dry-rb/dry-initializer
  • Nov 29 01:53
    woarewe commented #439
  • Nov 29 00:33
  • Nov 29 00:27
    woarewe commented #439
  • Nov 29 00:27
    woarewe commented #439
  • Nov 29 00:02
    woarewe commented #439
  • Nov 28 06:13
    erik-brueggemann starred dry-rb/dry-monads
  • Nov 28 00:42
    hangsu starred dry-rb/dry-monads
  • Nov 27 13:58
    fapdash starred dry-rb/dry-types
  • Nov 26 08:40
    solnic commented #34
  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:24

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:23

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:17

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

  • Nov 26 08:17

    action-hero[bot] on main

    Update CODE_OF_CONDUCT.md from … (compare)

Tim Riley
@timriley
I’ll try take a look tomorrow morning
Igor Alexandrov
@igor-alexandrov
great!
Jaromír Červenka
@Cervajz
module TargetRequests
  CreateSchema = Dry::Validation.Schema(ApplicationSchema) do
    required(:customer_id).filled { valid_db_id? & record_exists?(Customer) }
    required(:parse_request_id).filled { valid_db_id? & record_exists?(ParseRequest) }

    optional(:webhook_id).filled { valid_db_id? & record_exists?(Webhook) }
    optional(:target_email_id).filled { valid_db_id? & record_exists?(TargetEmail) }

    rule(target: %i[webhook_id target_email_id]) do |webhook_id, target_email_id|
      webhook_id.filled? | target_email_id.filled?
    end
  end
end
What do you think? :)
The only thing that bothers me is the model class "hardcoded"
But that won't change that often, so it's OK I suppose
My initial idea was to somehow incorporate this:
class ApplicationSchema < Dry::Validation::Schema
  configure do |config|
    option :record
    option :user_repository, User
    option :customer_repository, Customer
    option :document_repository, Document
    option :document_content_repository, DocumentContent
    option :vendor_repository, Vendor
    option :template_repository, Template
    option :source_email_repository, SourceEmail
    option :parse_request_repository, ParseRequest
    option :target_email_repository, TargetEmail
    option :webhook_repository, Webhook

    config.messages_file = 'config/locales/validations.yml'
  end
...
end
Jaromír Červenka
@Cervajz
Is there any way of Dry::Validation returning only the keys which are part of the schema? I was under impression that this is done automatically, especially with .to_monad extension. But it looks like I was wrong. Or maybe that was some older version as I remember it worked.
I'd like to get rid of strong params
I am looking thru the documentation and source code and can't find any option (or method on Result object) which would help me with that. Or I am blind :))
MySchema.call({i_dont_want_you: 'xxx', customer_id: 1, parse_request_id: "0266fa8b-6878-44aa-ad2e-a1d6e9dffa9d", webhook_id: 1}).to_monad
=> Success({:i_dont_want_you=>"xxx", :customer_id=>1, :parse_request_id=>"0266fa8b-6878-44aa-ad2e-a1d6e9dffa9d", :webhook_id=>1})
Robert Schulze
@fnordfish
@Cervajz Using type specs (config.type_specs = true) does that. see: https://dry-rb.org/gems/dry-validation/input-preprocessing/
Jaromír Červenka
@Cervajz
@fnordfish Thank you
Jaroslav
@jarosluv
Hi there! Could you help me with dry-auto_inject? Can we use additional arguments in initialize method If we use dry-auto_inject for this class? Or initialize is needed only for dependencies in this approach?
Jaroslav
@jarosluv
And what intentions are to use dry-initializer over dry-struct?
Nikita Shilnikov
@flash-gordon
@jarosluv dry-auto_inject can be used for that and supports quite a bit of cases where you mix it with existing constructors
also, it improves over time, see dry-rb/dry-auto_inject#48
Jaroslav
@jarosluv
@flash-gordon Please, see:
class DependencyContainer
  extend Dry::Container::Mixin

  register("dependency") { Object }
end

Injector = Dry::AutoInject(DependencyContainer)
class MyClass
  include Injector["dependency"]

  def initialize(name:)
    @name = name
    @object = dependency.new
  end
end

MyClass.new(name: "Foo")
# ArgumentError: unknown keyword: dependency
# from (pry):10:in `initialize'
class MyClass2
  include Injector["dependency"]

  def initialize(name:, **params)
    @name = name
    @object = dependency.new
  end
end

MyClass2.new(name: "Foo")
# NoMethodError: undefined method `new' for nil:NilClass
# from (pry):21:in `initialize'
Nikita Shilnikov
@flash-gordon
you don't call super in your constructors
def initialize(name:, **deps)
  super(deps)
  @name = name
  @object = dependency.new
end
Jaroslav
@jarosluv
@flash-gordon Oh, of course, I got it now. Thank you!
And maybe you can give me some examples of use-cases of dry-initializer in compare with dry-struct?
I find out that I need use this gems for objects of different purposes. But what does it mean technically?
Nikita Shilnikov
@flash-gordon
I don't have any examples of using dry-initializer beyond library code. You can find plenty of usages in rom but I don't need it in application code because of DI and dry-auto_inject
and dry-struct is ADT in ruby, basically
that is plain structures or combinations via sums
I don't have custom constructors for structs, it would feel wrong
Jaroslav
@jarosluv
Thank you for explanation!
Felix Wolfsteller
@fwolfst
Hi there
Where is the source to the documentation and how can I contribute to it?
Nikita Shilnikov
@flash-gordon
@fwolfst here you are https://github.com/dry-rb/dry-rb.org
Felix Wolfsteller
@fwolfst
I am quite surprised that I did not find any pointers to that question.
@flash-gordon cool, thanks.
@flash-gordon fwiw, there is an issue with the dry-initializer doc, I believe (last example of the type-constraints section: https://github.com/dry-rb/dry-rb.org/blob/master/source/gems/dry-initializer/type-constraints.html.md
Nikita Shilnikov
@flash-gordon
@fwolfst you can ping @nepalez if something isn't right
Felix Wolfsteller
@fwolfst
@nepalez ^^ I think location shall be an option and not an param in that last example. And also the naming "param" is weird for the first reader. It assumes some knowledge about the second argument. Arguably it could be named "this_param" for clarification (or something like that).
Felix Wolfsteller
@fwolfst
@nepalez feel free to create an issue and assign it or mention me, I'd update the doc
thanks.
Ahmad Musaffa
@musaffa
The example shows deploying a Sinatra app in AWS Lambda. Deploying dry-web-rodaapp should also be trivial.
Grant Shangreaux
@gcentauri
Hoping to get something at my work using dry/rom/lambda . There was
Peter Solnica
@solnic
this is awesome news indeed :)
Nikita Shilnikov
@flash-gordon
AFAIK cobol is also supported
Jeff Dickey
@jdickey
Coming soon: IBM RPG :older_man:
not to take away from the awesomeness; anything that lets devs use their favourite/existing-products' languages in new ways is almost by definition a Good Thing
Christian Georgii
@cgeorgii

Hi, I've been thinking about opening a pull request for dry-struct to make it quack a bit more like a hash in order to enable validating it with dry-validation. Nowadays an attempt to call a schema with a struct object throws an error. I don't understand if this is a conscious design decision because it seems like a useful use case.

What I want to enable is this:

schema = Dry::Validation.Schema { required(:age).filled(gteq?: 18) }

User.new(age: 17)

schema.(user)
#<Dry::Validation::Result output=#<User age=17> errors={:age=>["must be greater than or equal to 18"]}>
Nikita Shilnikov
@flash-gordon
you're supposed to create structs from valid data hence it doesn't make sense to pass structs to dry-v
Christian Georgii
@cgeorgii
Ok, thanks for the quick answer

Another question, then

BMI = Dry::Types['strict.int'].constrained(gteq: 18, lteq: 42).constructor { |x| x.round }

BMI[17.5]
#=> 18

BMI.valid?(17.5)
#=> false

Does this behavior make sense or is it a bug?