Where communities thrive


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

    flash-gordon on use-immutable-equalizer

    (compare)

  • 16:42

    flash-gordon on master

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

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

    flash-gordon on use-immutable-equalizer

    Use immutable equalizer for all… (compare)

  • 16:34

    flash-gordon on no-rewrap-for-structs

    (compare)

  • 16:34

    flash-gordon on master

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

  • 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
  • Nov 15 18:52
    waiting-for-dev commented #114
  • Nov 15 16:06
    businessBoris starred dry-rb/dry-system
  • Nov 15 15:16
    businessBoris starred dry-rb/dry-monads
  • Nov 15 08:22
    gruz0 starred dry-rb/dry-types
  • Nov 14 12:03
    pedrofurtado starred dry-rb/dry-matcher
  • Nov 14 08:21

    flash-gordon on master

    Fixing codeblock in maybe.html.… Remove duplicated dot from exam… Merge pull request #372 from Zi… (compare)

  • Nov 14 08:21
    flash-gordon closed #372
  • Nov 14 08:20
    flash-gordon edited #372
  • Nov 13 17:56
    voloyev starred dry-rb/dry-matcher
  • Nov 13 15:48
Jaromír Červenka
@Cervajz
(as per their ID)
Or I can be completely wrong :D
So what I'd do is Dry::Validation.Params(MyParentSchemaWithConfig) do ... end
Kacper Pucek
@KacperPucek
Thanks for looking into this, that's exactly what I ended up with for now - simply Dry::Validation.Params(Dry::Validation::Schema). Thanks again :)
Jaromír Červenka
@Cervajz
We would probably have to look how dry-configurable works.
Interesting
Now I am trying to understand how that works :D
Jaromír Červenka
@Cervajz
From line #19
And it's parent is Schema
So it's acutally Schema.configure do |config| on that line #9
I am lost :/
Pablo Crivella
@pablocrivella
What would be the best/easiest to mock the result of a Dry::Transcation::Operation when it returns a block?
Operation.new.call(arg) do |result|
  result.success { ... }
  result.failure { ... }
end
Piotr Solnica
@solnic
@pablocrivella are you using rspec?
Pablo Crivella
@pablocrivella
Yes
Piotr Solnica
@solnic
too bad your operation is not injected and you manually instantiate it
this makes mocking it harder
Pablo Crivella
@pablocrivella
I will try the injected version ASAP then :)

Is it still possible to inject a operation, even if i’m using inside other operation:

i.e:

class CheckAccess
  include Dry::Transaction::Operation

  def call(user)
    return Success(user.licenses.first) if active_license_for?(user)

    check_purchase = CheckPurchase.new
    check_purchase.call(user.purchases.first) do |result|
      result.success do |purchase|
        Success(purchase)
      end

      result.failure do
        if user.on_trial?
          Success(Trial.new(user: user))
        else
          Failure(user)
        end
      end
    end
  end

  private

  def active_license_for?(user)
    user.licenses.first_or_initialize.active?
  end
end
Viet (Drake) Tran
@tiev
I prefer not using that block syntax at all. It’s a kind of dry-matcher Class enhancement.
I think it’s just a sugar-syntax that’s hard to write tests.
Just use normal Result matcher.
Or better, with the nature of your code, use Do notation
Tim Riley
@timriley
In that context I personally would just use the plain Result API
check_purchase.call(user.purchases.first).or {
  if user.on_trial?
    Success(Trial.new(user: user))
  else
    Failure(user)
  end
}
Tim Riley
@timriley
@pablocrivella also, that check_purchase operation cannot injected given you hard code its initialization in the call method
if you want it to be an injected dependency, you need to pass it to initialize
e.g.
def initialize(check_purchase:)
  @check_purchase = check_purchase
end
Then you can use it from inside #call and also inject a test double during your tests
Pablo Crivella
@pablocrivella
Thanks @timriley ! I’ll take a look
Pablo Crivella
@pablocrivella
There is not something similar to include Dry::Transaction(container: Container) for Operations right? Is that a flaw on my desing? should operations not depend on other operations as a common practice?
Tim Riley
@timriley
@pablocrivella you want dry-auto_inject for that
Pablo Crivella
@pablocrivella
@timriley Yeah i checked that one but i’m having a hard time wrapping my head around how it should be the correct way of including it on a rails project.
For now i went for the “hybrid” approach:
# frozen_string_literal: true

require "dry/transaction/operation"

class CheckAccess
  include Dry::Transaction::Operation

  def initialize(check_purchase: CheckPurchase.new)
    @check_purchase = check_purchase
  end

  def call(user)
    return Success(user.licenses.first) if active_license_for?(user)

    @check_purchase.call(user.purchases.first).or(
      if user.on_trial?
        Success(Trial.new(user: user))
      else
        Failure(user)
      end
    )
  end

  private

  def active_license_for?(user)
    user.licenses.first_or_initialize.active?
  end
end
David Dawson
@DangerDawson
@pablocrivella I take a similar approach, plus you can always use the following gem: https://github.com/dry-rb/dry-initializer for your initializer
Matheus Silva Santos de Oliveira
@matheussilvasantos
Does someone know how to validate an optional field with a set of values?
I found this in documentation required(:sample).value(eql?: 1234), but I the field I want to validate is optional and there is more than one value that it could be.
Piotr Solnica
@solnic
@matheussilvasantos required(:sample).maybe(included_in?: [1, 2, 3])
Matheus Silva Santos de Oliveira
@matheussilvasantos
@solnic thank you!!
Igor Alexandrov
@igor-alexandrov
@matheussilvasantos if you have optional key (it may be missed in input) then you should use optional instead of required
optional(:sample).maybe(included_in?: [1, 2, 3])
Igor Alexandrov
@igor-alexandrov
irb(main):013:0> VALUE = 1
=> 1
irb(main):014:0> Dry::Monads::Success(Dry::Monads::Success(VALUE))
=> Success(Success(1))
I always thought that it should be just Success(1)
Igor Alexandrov
@igor-alexandrov
Don't know maybe #flatten or #compact should be added for such cases
Nikita Shilnikov
@flash-gordon
you usually use fmap/bind depending on the case, there's no flatten/join because it's normally not required
flattening by default will ruin the semantics
it won't "type check"
Igor Alexandrov
@igor-alexandrov
Ok, got it
Thanks!
Igor Alexandrov
@igor-alexandrov
The question above was because we tried to combine Try and Result monads, but we found a solution:
irb(main):003:0> Try { Failure(5) }.to_result.bind(&:itself)
=> Failure(5)
irb(main):004:0> Try { raise RuntimeError.new }.to_result.bind(&:itself)
=> Failure(#<RuntimeError: RuntimeError>)
irb(main):005:0> Try { Success(1) }.to_result.bind(&:itself)
=> Success(1)
Matheus Silva Santos de Oliveira
@matheussilvasantos
@igor-alexandrov yes, I'm using optional :smile:
hasimisikli
@hasimisikli
@solnic hello ,firstly thanks of uploaded. can I ask a question?
can you explain this project please?
Igor Alexandrov
@igor-alexandrov
@hasimisikli you mean to explain dry-rb?