Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Apr 09 12:23
    k0va1 starred dry-rb/dry-container
  • Apr 09 08:33

    dry-bot on master

    [devtools] sync (compare)

  • Apr 09 08:33

    solnic on master

    Update changelog.yml (compare)

  • Apr 09 08:21

    solnic on v0.3.2

    Bump dry-monitor to 0.3.2 (compare)

  • Apr 09 08:20
    flash-gordon commented #38
  • Apr 09 08:19

    dry-bot on master

    [devtools] sync (compare)

  • Apr 09 08:19

    solnic on master

    Update changelog.yml rubocop --safe-auto-correct Ignore warnings from rouge gem and 1 more (compare)

  • Apr 09 08:03
    mensfeld commented #38
  • Apr 09 02:41
    DaiAoki starred dry-rb/dry-monads
  • Apr 08 23:53

    davydovanton on improve-allocation-of-logger

    (compare)

  • Apr 08 23:53

    davydovanton on master

    Don't create a new formatter ob… Merge pull request #38 from dry… (compare)

  • Apr 08 23:53
    davydovanton closed #38
  • Apr 08 18:00
    dry-bot commented #38
  • Apr 08 17:59
    davydovanton review_requested #38
  • Apr 08 17:59
    davydovanton assigned #38
  • Apr 08 17:59
    davydovanton opened #38
  • Apr 08 17:54

    davydovanton on improve-allocation-of-logger

    Don't create a new formatter ob… (compare)

  • Apr 08 17:29
    JuPlutonic starred dry-rb/dry-monitor
  • Apr 08 13:48
  • Apr 08 09:13

    solnic on release-0.17

    Add information about built-in … (compare)

John Backus
@backus

Could their >-> example

result = Right(3) >-> value {
  if value > 1
    Right(value + 3)
  else
    Left("value was less or equal than 1")
  end
} >-> value {
  if value % 2 == 0
    Right(value * 2)
  else
    Left("value was not even")
  end
}

just be re-written such that Right and Left provided the method #bind like so?

Right(3).bind do |value|
  if value > 1
    Right(value + 3)
  else
    Left("value was less or equal than 1")
  end
end.bind do |value|
  if value % 2 == 0
    Right(value * 2)
  else
    Left("value was not even")
  end
end
Tim Riley
@timriley
I’d be up for us having a small set of useful things in either dry-fp or dry-monads
I’m really not the biggest fan of kleisli’s >-> trickery. It makes chaining hard in a lot of cases, I’ve found.
John Backus
@backus
Alright so I can define a dry-validation rule that depends on other values
I can also define a schema that works with arrays as input
But can I define a rule for a value in an array which is dependent on the entire array
For example, can I write a validation that says that a value is not repeated in an array
John Backus
@backus
Also am I missing something here or is this a bug?
require 'dry/validation'
require 'dry/validation/version'

Dry::Validation::VERSION # => "0.7.4"

schema1 = Dry::Validation.Schema do
  key(:thing).required(:unique?)

  configure do
    config.messages_file = 'custom_errors.yml'

    def unique?(array)
      array.uniq.size == array.size
    end
  end
end

schema2 = Dry::Validation.Schema do
  key(:thing).required(:unique?)

  key(:thing).each do
    inclusion?(%w[foo bar])
  end

  configure do
    config.messages_file = 'custom_errors.yml'

    def unique?(array)
      array.uniq.size == array.size
    end
  end
end

bad_value      = %w[foo wtf bar]
repeated_value = %w[foo bar foo]

schema1.call(thing: bad_value).messages[:thing]      # => nil
schema1.call(thing: repeated_value).messages[:thing] # => ["must not repeat values"]

schema2.call(thing: bad_value).messages[:thing]      # => {1=>["must be one of: foo, bar"]}
schema2.call(thing: repeated_value).messages[:thing] # => nil
only difference between schema1 and schema2 is the added inclusion? rule within each
Benjamin Klotz
@tak1n
@backus I had such similar cases too, but was not sure if I made smth wrong or not
Piotr Solnica
@solnic
@backus specifying same key twice will override other rules
Each applies rules to each value, so the way you wrote it is not what you want
Oh wait, it is. Sorry (in pre coffee mode)
John Backus
@backus
What would that look like then @solnic? Like so?
key(:thing).required(:unique?).each do
  inclusion?(%w[foo bar])
end
Piotr Solnica
@solnic
this will work in next version, atm I don’t think this is supported
required(:unique?) returns Schema::Rule object which doesn’t support each, IIRC
@backus btw key(:thing).each(inclusion: …) is better, use blocks only when you want ORs
ORs or schemas*
Tim Riley
@timriley
@solnic something I'd like to do in the next little while is change dry-view Layout's "root" config into an array of paths, so we can package up gems with view templates (like our paginator) and have them available to use within dry-web apps. Does that seem good with you, in principle?
I think you'd still configure the paths yourself manually, for each of your layout classes. That way you can be explicit about which gems' view paths you care to include (and also it means we avoid global state).
Piotr Solnica
@solnic
@timriley yes sounds good
Tim Riley
@timriley
Great :)
I want to start avoiding copy/paste code between our apps in situations where it's clear some things can be gem-ified.
Tim Cooper
@coop

@solnic have you thought about supporting unknown keys with dry-v? This is the JSON payload of one of the APIs that we don’t own:

{
  "RpYCgWVGkNyRk3JsPUj9Hzp_CLedN5xM": {
    "name": “Bedroom"
  },
  # … more hashes ...
}

If we were in control of the API I’d move the id into the payload and just have an array but unfortunately it is supplied by a third party.

Tim Riley
@timriley
Not answering your question directly, but you could make it work by putting a mapper in front to rearrange those into a normalised form?
Also, what an... interesting API structure
:wink:
Tim Cooper
@coop
Good call @timriley.
Piotr Solnica
@solnic
yeah I would map it
stigchristian
@stigchristian
Hi, how do I validate a nested array of hashes (I want to validate the hash keys/values as well). Something like:
key(:people).each(AddressSchema)
Oh, never mind, found out:
    key(:people).each do
      key(:address).required(:string?)
      key(:city).required(:string?)
    end
Piotr Solnica
@solnic
@stigchristian please wrap those two keys in a schema block
nested keys are going away in 0.8.0
where did you find that example?
stigchristian
@stigchristian
great, thanks.
Just tested, no example
    key(:people).each do
      schema do
        key(:address).required(:string?)
        key(:city).required(:string?)
      end
    end
Piotr Solnica
@solnic
just schema do .. end
stigchristian
@stigchristian
?
Piotr Solnica
@solnic
you wrote schema.do but now I can see you fixed it :)
stigchristian
@stigchristian
:thumbsup:
that’s where rom/dry ecosystems are going…
Benjamin Klotz
@tak1n
@solinc :+1: * 1000
Simon Schmid
@sled
a philiosophical question, shouldn't coercion be separate from a type? :)
Nikita Shilnikov
@flash-gordon
@sled you have strict types so any coercions are just additions to them. And coercions are proudly named "type constructors" :)
Simon Schmid
@sled
yeah but I always get the feeling that coercion is related to a specific "format"
it's like the coercer should know how to convert from "input" to requested "type" and the type should just check whether you're assigning a valid type and throw a TypeError if not
there's like two possibilities, passing a coercer in as dependency and in the type constructor do something like coercer.to_date(....) or do it "in-front" of everything e.g XYCoercer(schema, input, ... other options) => Schema Instance
Simon Schmid
@sled
(just thinking out loud here)