These are chat archives for dry-rb/chat

7th
Apr 2016
Tim Riley
@timriley
Apr 07 2016 00:00 UTC
you must be seeing the same thing as me then
OK – If I delete one of the previous articles, then the new one gets built
Piotr Solnica
@solnic
Apr 07 2016 00:01 UTC
it’s like they were limited to 2
Don Morrison
@elskwid
Apr 07 2016 00:03 UTC
that’s one way to make building quick
Andy Holland
@AMHOL
Apr 07 2016 00:03 UTC
lol
Custom step adapters are awesome
<3
Tim Riley
@timriley
Apr 07 2016 00:04 UTC
Thanks @AMHOL. One day you might even be able to read about them on the internet.
:)
Andy Holland
@AMHOL
Apr 07 2016 00:04 UTC
:joy:
Tim Riley
@timriley
Apr 07 2016 00:04 UTC
Like now!
Max at Icelab somehow had everything working
dry-transaction 0.6.0 is out and you won’t believe what it can do
is that too cheeky for a tweet? ;)
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:06 UTC
can it make some cookies?
Piotr Solnica
@solnic
Apr 07 2016 00:06 UTC
hope he didn’t Max out the number of posts available
Tim Riley
@timriley
Apr 07 2016 00:06 UTC
He’s our new chief editor everyone
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:06 UTC
little typo in the first sentence: "applicartion"
Tim Riley
@timriley
Apr 07 2016 00:06 UTC
Always happens after publishing. Thanks!
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:08 UTC
if I were to use a transaction in a controller or in a roda route, should I define it right there, or would be better to have them defined elsewhere and just call them?
Piotr Solnica
@solnic
Apr 07 2016 00:08 UTC
defined elsewhere
and simply called in controller
Tim Riley
@timriley
Apr 07 2016 00:09 UTC
Yep.
Piotr Solnica
@solnic
Apr 07 2016 00:09 UTC
@timriley u tweetin?
Tim Riley
@timriley
Apr 07 2016 00:09 UTC
@solnic yep, one sec
Piotr Solnica
@solnic
Apr 07 2016 00:10 UTC
:D
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:11 UTC
I retweeted to my 1 follower o/
Andy Holland
@AMHOL
Apr 07 2016 00:12 UTC
I might save the retweet for lunch time tomorrow
Piotr Solnica
@solnic
Apr 07 2016 00:12 UTC
oops
Don Morrison
@elskwid
Apr 07 2016 00:12 UTC
@AMHOL good call. Don’t retweet on an empty stomach.
(I’ll be here all week)
Andy Holland
@AMHOL
Apr 07 2016 00:12 UTC
:joy:
Tim Riley
@timriley
Apr 07 2016 00:12 UTC
haha
Don Morrison
@elskwid
Apr 07 2016 00:12 UTC
Don’t forget to tip your @solnic
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:13 UTC
BTW great article @timriley. Those custom step are powerfull
step adapters*
Piotr Solnica
@solnic
Apr 07 2016 00:13 UTC
such extensibility
would be nice to add Object#transaction patch, it’d be so concise and beautiful
Ralf Schmitz Bongiolo
@mrbongiolo
Apr 07 2016 00:14 UTC
A bit off topic, what's the Import used for? I've seen it in dry-web, it comes from container?
Andy Holland
@AMHOL
Apr 07 2016 00:14 UTC
@solnic should we try HN too?
Piotr Solnica
@solnic
Apr 07 2016 00:15 UTC
@AMHOL I never post there, it has no impact unless you write posts like “rails is stupid” or something
lol
Can't do any harm?
Piotr Solnica
@solnic
Apr 07 2016 00:16 UTC
yeah it can't
Andy Holland
@AMHOL
Apr 07 2016 00:18 UTC
Want me to post it?
Or do you want to @timriley ?
Tim Riley
@timriley
Apr 07 2016 00:18 UTC
Happy for you to :)
Piotr Solnica
@solnic
Apr 07 2016 00:18 UTC
just do it, don’t let your dreams be dreams, or something
Andy Holland
@AMHOL
Apr 07 2016 00:18 UTC
:joy:
@solnic is it 2:20am there BTW?
Tim Riley
@timriley
Apr 07 2016 00:18 UTC
post-2am solnic doens’t mince words
Meanwhile, I’m signing up to reddit.
Piotr Solnica
@solnic
Apr 07 2016 00:19 UTC
@AMHOL I don’t know, but it’s very very dark
Tim Riley
@timriley
Apr 07 2016 00:19 UTC
Oh! I was sad my username was taken. But it appears I must’ve claimed it years ago, haha.
Piotr Solnica
@solnic
Apr 07 2016 00:19 UTC
@timriley oh yeah? you’re gonna have so much fun there :D
Tim Riley
@timriley
Apr 07 2016 00:20 UTC
I’m just there to +1 your comments about ruby
Andy Holland
@AMHOL
Apr 07 2016 00:20 UTC
Please limit title to 80 characters. This had 81.
Damit
Tim Riley
@timriley
Apr 07 2016 00:20 UTC
get rid of 0.6
Andy Holland
@AMHOL
Apr 07 2016 00:21 UTC
That works :)
Soumya Ray
@soumyaray
Apr 07 2016 03:00 UTC
I'm still trying to wean myself off of Virtus over here and wrap my head around dry-types. I find that with Dry::Types::Struct and Dry::Types::Value, we cannot set an attribute of an instance after instantiation (i.e., there is no attribute= methods). However, for instances of both dry structs and values, we can call methods that mutate the value of attributes (like .capitalize! on Type::String attributes). So my questions are: (1) is there any way to change the attributes of structs? (2) why can we alter the attributes of values?
Tim Riley
@timriley
Apr 07 2016 03:03 UTC
I think (2) would be the case because deep freezing everything would be too slow.
And I don’t think either of these are designed to allow you to change their attributes after they’ve been initialized. They’re meant to be used as value objects.
François Bernier
@fbernier
Apr 07 2016 03:05 UTC
and about (1), the library author is against adding such functionality to the library not to encourage the creation of mutable objects. If you look up I have posted kind of a hack to do that.
     # Hack to make things writable with type checking
     def self.attributes(new_schema)
       super

       new_schema.keys.each do |k|
         define_method("#{k}=") do |value|
           instance_variable_set("@#{k}", self.class.schema[k][value])
         end
       end
     end
Tim Riley
@timriley
Apr 07 2016 03:06 UTC
Perhaps a safer approach here would be to just create a copy of the object whenever you need to make adjustments to the attributes.
safer as in better design, avoiding mutable state
Soumya Ray
@soumyaray
Apr 07 2016 03:07 UTC
Thanks @timriley and @fbernier! All this makes sense, but i'm still a bit confused then as to what is supposed to be different about dry structs and values. what operation can i do on one that i can't do on another?
Tim Riley
@timriley
Apr 07 2016 03:08 UTC
They’re actually really similar. All the value class does that’s different to structs is freeze itself. I think this is something that should be improved in dry-types - either these classes should merge, or their different uses should be made more apparent.
Right now I just use Dry::Types::Value everywhere.
Soumya Ray
@soumyaray
Apr 07 2016 03:08 UTC
many thanks, and i concur :)
And one laaaaast thing: I'm teaching a development class, and wanted to switch from Virtus to dry-types. I know dry-types is in v0.7.x -- is the syntax close enough to 1.0 state that I can make material about it without requiring major changes in the coming year? i kinda have the same question about rom-rb but should perhaps ask this in rom's gitter room.
Tim Riley
@timriley
Apr 07 2016 03:12 UTC
If you can stand to wait a day or so, it might be good to ask @solnic that directly in a question on github issues, perhaps.
I’m sure he’d be keen for you not to use virtus though :)
Soumya Ray
@soumyaray
Apr 07 2016 03:13 UTC
sounds good. i'll try and catch him here first. i seem to have missed him by a few hours.
Tim Riley
@timriley
Apr 07 2016 03:13 UTC
He’s in Poland. Might be good to watch the time there.
Try to catch him this week, though. He’s taking a break from OSS for a bit starting next week.
Soumya Ray
@soumyaray
Apr 07 2016 03:15 UTC
sounds good. will live in polish time for a coupla days if i have to :D. yeah, i like virtus a bit too much and so do my students. it'll be a hard sell, especially given that there are so many resources and documentation out there about virtus. luckily, more good articles about dry-types are popping up lately.
Tim Riley
@timriley
Apr 07 2016 03:16 UTC
It certainly has more future ahead of it than virtus.
And I think it’s a clearer model.
Soumya Ray
@soumyaray
Apr 07 2016 03:17 UTC
it is certainly more mature in its design. i'll try adopting it in my teaching and coding fully in the coming weeks, or in the fall at latest.
Tim Riley
@timriley
Apr 07 2016 03:19 UTC
Cool, it’s exciting to hear that you’ll use some dry-rb libs in your Ruby teaching!
Is this at your university or elsewhere?
Soumya Ray
@soumyaray
Apr 07 2016 03:19 UTC
at my university
Tim Riley
@timriley
Apr 07 2016 03:20 UTC
Nice :)
Piotr Solnica
@solnic
Apr 07 2016 07:47 UTC
@soumyaray this is fantastic news, would love to hear what kind of feedback you’d get from the students.
Tim Cooper
@coop
Apr 07 2016 07:48 UTC
@solnic is there a feature list that you’d like worked on while you’re away?
It would be nice to keep development going forward while you’re having some downtime.
Piotr Solnica
@solnic
Apr 07 2016 07:49 UTC
@soumyaray re api changes in dry-types, things are not stable yet, although I’m happy with roughly 90% of the interfaces. We should reach 1.0 this year, hard to tell when exactly though
Nicolas Cavigneaux
@Bounga
Apr 07 2016 07:49 UTC
@solnic oh so this is a bug not a problem with my code? Do I need to create an issue?
Piotr Solnica
@solnic
Apr 07 2016 07:49 UTC
@Bounga no, I already fixed it and pushed a release
Nicolas Cavigneaux
@Bounga
Apr 07 2016 07:50 UTC
nice!
Piotr Solnica
@solnic
Apr 07 2016 07:50 UTC
@coop yes, a lot on my plate that I haven’t reported as issues
Tim Cooper
@coop
Apr 07 2016 07:51 UTC
I personally would like to see something done with dry-rb/dry-validation#90. Maybe it needs more discussion?
Cool - I’m guessing you’ll throw it up as a gist / issues and people can work through it?
Piotr Solnica
@solnic
Apr 07 2016 07:52 UTC
I’ll report issues in dry-v and dry-t
I’m gonna skip the big refactorings though, as I need to experiment a bit with that first
Tim Cooper
@coop
Apr 07 2016 07:53 UTC
That’s cool.
Piotr Solnica
@solnic
Apr 07 2016 07:53 UTC
@coop re #90 I think what we ended up with should be the final api. It reads very well IMO and will allow things that are now either awkward or impossible
so required(:foo).value(:str?) and required(:foo).filled(size?: 1..10)
Tim Cooper
@coop
Apr 07 2016 07:54 UTC
key(:name).orly? - I liked that too.
Piotr Solnica
@solnic
Apr 07 2016 07:54 UTC
oh yeah, we can do it too as an easter egg :laughing:
Tim Cooper
@coop
Apr 07 2016 07:54 UTC
hehe
Piotr Solnica
@solnic
Apr 07 2016 07:55 UTC
@coop btw your JSON stuff is released, not sure if you noticed
Tim Cooper
@coop
Apr 07 2016 07:55 UTC
Maybe we can drop a comment with a “this is what we want” and someone can take up the challenge? It looks like @endash is quite passionate about it.
Piotr Solnica
@solnic
Apr 07 2016 07:55 UTC
I only tweeted about it
Tim Cooper
@coop
Apr 07 2016 07:55 UTC
Yep I follow the conversations in here when I wake up.
Hannes Nevalainen
@kwando
Apr 07 2016 07:56 UTC
we can have a gem called dry-wtf that monkeypatches other dry-libs with "useful" methods =P
Piotr Solnica
@solnic
Apr 07 2016 07:56 UTC
@kwando great idea
Tim Cooper
@coop
Apr 07 2016 07:57 UTC
I’d be really interested in seeing a blog post with real life examples - what would be a good laugh is submitting a PR to rails where you replace strong params with dry-v :P
Piotr Solnica
@solnic
Apr 07 2016 07:57 UTC
@coop I’m actually going to talk to Sean about that…he wrote on reddit yesterday that he’d removed AM::V if backward compat wasn’t an issue
and he wrote that he’s planning to add proper coercion/sanitization/validation for params in Rails 5.1 or 6.0
so I was like “hey, there’s a library for that” :)
Hannes Nevalainen
@kwando
Apr 07 2016 07:58 UTC
that would be amazing =)
Piotr Solnica
@solnic
Apr 07 2016 07:58 UTC
it would be fun to see dry-v being used in rails :laughing:
well, Sean is my great hope in the Rails world, really
he knows this stuff, we talked a couple of times about ORMs and things
Tim Cooper
@coop
Apr 07 2016 07:59 UTC
Sean? From Thoughtbot?
Piotr Solnica
@solnic
Apr 07 2016 07:59 UTC
@coop not anymore, but yes
Tim Cooper
@coop
Apr 07 2016 07:59 UTC
Piotr Solnica
@solnic
Apr 07 2016 07:59 UTC
yes
Tim Cooper
@coop
Apr 07 2016 08:00 UTC
Cool - I saw that he has recently been making some nice changes to AR.
Piotr Solnica
@solnic
Apr 07 2016 08:00 UTC
yeah, he added attributes API
Tim Cooper
@coop
Apr 07 2016 08:00 UTC
That’s the one I was thinking of.

so I was like “hey, there’s a library for that”

I think it would be good exposure to create a PR that introduced dry-v and not worry about backwards compat. It wouldn’t get merged but the exercise is about publicity.

Piotr Solnica
@solnic
Apr 07 2016 08:01 UTC
@coop man, I will do that at some point
Tim Cooper
@coop
Apr 07 2016 08:02 UTC
Just don’t get your hopes up on getting it merged haha.
Piotr Solnica
@solnic
Apr 07 2016 08:02 UTC
actually no, wait, I won’t, but I will find somebody who will. I promised myself not to do anything rails related ;)
well, we could just submit an issue “Consider replacing strong params with dry-v”
Hannes Nevalainen
@kwando
Apr 07 2016 08:04 UTC
I think you want it to reach 1.0 before then though =)
Piotr Solnica
@solnic
Apr 07 2016 08:04 UTC
yes, that’s why I said “at some point”
Tim Cooper
@coop
Apr 07 2016 08:04 UTC
If you did that you’d just piss people off - code speaks volumes. Also shows that you’re actually willing to put in the effort to see it through. I get what you mean though.
Hannes Nevalainen
@kwando
Apr 07 2016 08:04 UTC
gotcha
Piotr Solnica
@solnic
Apr 07 2016 08:04 UTC
@coop but it has potential to cause some dramatic discussions, it would be so worth it :laughing:
Tim Cooper
@coop
Apr 07 2016 08:05 UTC
True.
I reckon you could do it after #90 gets merged. The API would feel pretty stable.
Strong Params wouldn’t be that hard to replace.

Nested keys will be removed prior 1.0

lol I’ve heard you mention that quite a few times now.

As an FYI http://dry-rb.org/gems/dry-validation/array-as-input/
schema = Dry::Validation.Schema do
  each do
    key(:name).required
    key(:age).required
  end
end
Piotr Solnica
@solnic
Apr 07 2016 08:09 UTC
dammit
Tim Cooper
@coop
Apr 07 2016 08:09 UTC
I can update it.
Piotr Solnica
@solnic
Apr 07 2016 08:10 UTC
ok
I had to :(
Tim Cooper
@coop
Apr 07 2016 08:15 UTC
dry-rb/dry-rb.org#51 - dry-rb.org doesn’t seem to show up in the activity feed.
I could probably write docs on JSON validation too. Might see if I get some time on the weekend.
Nicolas Cavigneaux
@Bounga
Apr 07 2016 08:22 UTC
@solnic I tried the new release, no more exception. But it's doesn't seem to do the validation of the rule
Piotr Solnica
@solnic
Apr 07 2016 08:24 UTC
require 'dry-validation'

TypeSchema = Dry::Validation.Schema do
  key(:name).required
end

Schema = Dry::Validation.Schema do
  key(:number).required(:str?)
  key(:type).schema(TypeSchema)

  rule(number_format: [[:type, :name], :number]) do |type_name, number|
    type_name.eql?('CODEP').then(number.format?(/^D\d{3}$/))
  end
end

puts Schema.(number:AbCD’, type: { name: 'CODEP' }).inspect
@Bounga I wrote this script to double-check, it works fine for me
Nicolas Cavigneaux
@Bounga
Apr 07 2016 08:29 UTC
@solnic You're right, I'll double check my code
Thanks a lot
Nicolas Cavigneaux
@Bounga
Apr 07 2016 08:43 UTC
@solnic oh! I have to set number as required for the rule to be triggered?
Piotr Solnica
@solnic
Apr 07 2016 08:44 UTC
@Bounga yes, it’s the main idea behind high-lvl rules, they are only triggered when basic validation of a given value passed
we should somehow detect when you specify dependencies for a high-lvl rule and you’re missing validation for these
and raise an error
Nicolas Cavigneaux
@Bounga
Apr 07 2016 08:46 UTC
ok! got it. It works like a charm now. dry-v adopted for my project
Piotr Solnica
@solnic
Apr 07 2016 08:46 UTC
:) :tada: :tada: :tada: :tada: :tada: :tada: :)
Tim Cooper
@coop
Apr 07 2016 08:58 UTC

In dry-types is there support for types that aren’t dry-types? I couldn’t find any documentation on it but I get the feeling it is supported.

require "dry-types"
require "dry-validation"
require "money"

Dry::Types.register_class(Money)

module Types
  include Dry::Types.module
end

class Rate < Dry::Types::Value
  constructor_type(:schema)

  attribute :fixed, Types::Money
  attribute :variable, Types::Strict::Decimal.default(BigDecimal("0.0"))

  def self.variable(percentage_as_string, currency = "AUD")
    new(
      variable: BigDecimal(percentage_as_string.tr("%", "")),
      fixed: Money.zero(currency),
    )
  end

  def self.fixed(amount)
    new(fixed: amount)
  end
end

puts Rate.variable("5%").inspect
#<Rate fixed=#<Money fractional:0 currency:AUD> variable=#<BigDecimal:7fc4248bcac8,'0.5E1',9(18)>>

puts Rate.fixed(Money.us_dollar(1_23)).inspect
#<Rate fixed=#<Money fractional:123 currency:USD> variable=#<BigDecimal:7fc4248bdc70,'0.0',9(18)>>

puts Rate.fixed("lolz").inspect
#<Rate fixed=#<Money fractional:0 currency:USD> variable=#<BigDecimal:7fc4248bdc70,'0.0',9(18)>>

I expected the last one to error.

Nikita Shilnikov
@flash-gordon
Apr 07 2016 09:00 UTC
@coop dry-rb/dry-types#71 but it seems you already know about the PR
Tim Cooper
@coop
Apr 07 2016 09:01 UTC
Yeah I know why I had to add constructor_type (which is a little gross but I can deal), I’m more interested why Rate.fixed("lolz”) didn’t get upset that I didn’t pass a Money.
Piotr Solnica
@solnic
Apr 07 2016 09:02 UTC
it’s not strict, so it won’t raise
Types::Money.constrained(type: Money) would build a strict version
Tim Cooper
@coop
Apr 07 2016 09:04 UTC
I thought it was something like that, I originally was trying Types::Strict::Money but that obviously didn’t work. You’re suggestion makes more sense.
Piotr Solnica
@solnic
Apr 07 2016 09:05 UTC
register_class just does Definition.new(Money).constructor(Money.method(:new))
Tim Cooper
@coop
Apr 07 2016 09:05 UTC
@flash-gordon I think I +1 your PR by accident, I thought you were talking about something else :blush:
Nikita Shilnikov
@flash-gordon
Apr 07 2016 09:07 UTC
oops, you're right (=
Tim Cooper
@coop
Apr 07 2016 09:08 UTC
@flash-gordon I thought you were describing the problem where :strict requires keys even if a default is set.

@solnic that didn’t give me a strict version of Money.

class Rate < Dry::Types::Value
  constructor_type(:schema)

  attribute :fixed, Types::Money.constrained(type: Money)
  attribute :variable, Types::Strict::Decimal.default(BigDecimal("0.0"))
end

I get the same output:

#<Rate fixed=#<Money fractional:0 currency:USD> variable=#<BigDecimal:7fc4248bdc70,'0.0',9(18)>>

I will keep digging around because I thought it is a feature that is worth documenting.

Piotr Solnica
@solnic
Apr 07 2016 09:13 UTC
@coop sorry busy with other stuff atm
Tim Cooper
@coop
Apr 07 2016 09:13 UTC
It’s cool - not a big issue for me at the moment. Put it on the back burner.
Nikita Shilnikov
@flash-gordon
Apr 07 2016 09:14 UTC
@coop nope. It is about using :schema constructor with strict types and missing keys. Very similar to your first example
Nicolas Cavigneaux
@Bounga
Apr 07 2016 09:59 UTC
@solnic this key(:parent) { none? | type?(Hash) }works but this key(:parent) { none? | hash? } throws ArgumentError: wrong number of arguments (given 0, expected 1..3)
from /Users/nico/Synbioz/Sites/ffepgv/ifederation/vendor/bundle/gems/dry-validation-0.7.3/lib/dry/validation/schema/key.rb:27:in `instance_eval'
    from /Users/nico/Synbioz/Sites/ffepgv/ifederation/vendor/bundle/gems/dry-validation-0.7.3/lib/dry/validation/schema/key.rb:27:in `hash?'
hum let me upgrade dry-v
Piotr Solnica
@solnic
Apr 07 2016 10:01 UTC
yeah, we expect hash to be used with a block
use type?(Hash) for now
Nicolas Cavigneaux
@Bounga
Apr 07 2016 10:01 UTC
ok
Piotr Solnica
@solnic
Apr 07 2016 10:01 UTC
but why not maybe(:hash?) instead?
Nicolas Cavigneaux
@Bounga
Apr 07 2016 10:01 UTC
oh yes you're right. That's because I'm not fluent with dry-v yet
Piotr Solnica
@solnic
Apr 07 2016 10:02 UTC
lemme know if that works
Nicolas Cavigneaux
@Bounga
Apr 07 2016 10:09 UTC
it works, thx
François Bernier
@fbernier
Apr 07 2016 12:35 UTC
would be handy to be able to pass a proc to default and pass it the object
example:
attribute :stuff, Dry::Types['coercible.string'].default(-> obj { obj.class.something })
because right now if I have a class User and a class Admin which inherits from User, and I define such an attribute on User, I can't override the behavior of this default inside Admin as self references User.
Hannes Nevalainen
@kwando
Apr 07 2016 12:47 UTC
is there a way to derive a dry-v schema from a dry-types struct?
Piotr Solnica
@solnic
Apr 07 2016 13:12 UTC
@kwando yes. It is a new feature, just pass struct class to schema
Hannes Nevalainen
@kwando
Apr 07 2016 13:12 UTC
so Dry::Validation.Schema(MyStructClass) ?
Piotr Solnica
@solnic
Apr 07 2016 13:14 UTC
Uhm. Nope. I meant schema meth in the dsl
Hannes Nevalainen
@kwando
Apr 07 2016 13:14 UTC
oh, got it
<3
Piotr Solnica
@solnic
Apr 07 2016 13:14 UTC
We could make it work like that too. It is a fresh and experimental feature. Not even documented yet
Hannes Nevalainen
@kwando
Apr 07 2016 13:16 UTC
I almost thought you would have this covered somehow =)
Nikita Shilnikov
@flash-gordon
Apr 07 2016 13:29 UTC
@fbernier you can make your type optional and set any default value at #initialize if ivar is nil. It is not so cool though because you won't be able to use the type independently from this custom default logic. But you won't do that with your proposal either. Probably dry-t should allow to override attributes in some cases (e.g. when schema was inherited from the superclass)
Soumya Ray
@soumyaray
Apr 07 2016 14:49 UTC
@solnic: thanks for the update. I'll give dry-types a shot sooner rather than later in my classes then :)
Piotr Solnica
@solnic
Apr 07 2016 15:30 UTC
@soumyaray great, lemme know if you have questions
Artem Pyankov
@iBublik
Apr 07 2016 18:50 UTC
@solnic I'm here :) so what's about situation with empty array from ROM chat? any ideas?
Piotr Solnica
@solnic
Apr 07 2016 18:52 UTC
@iBublik cool, thanks for joining. gimme a sec I’ll try out one thing
aaah dammit
it’s a known issue, it’s not gonna work yet :(
Piotr Solnica
@solnic
Apr 07 2016 18:57 UTC
I’m gonna try to fix that somehow, probably by adding value DSL that we talked about
so ie this would work: key(:stuff).value(:filled?).each(:str?)
Artem Pyankov
@iBublik
Apr 07 2016 19:03 UTC
OK, thanks for your feedback. I'll use rule workaround for now
Piotr Solnica
@solnic
Apr 07 2016 19:03 UTC
:+1:
Andrew Kozin
@nepalez
Apr 07 2016 22:47 UTC

@solnic I've looked at dry-types defaults and now I think it plays slightly different role than in dry-initializer.

In dry-types I see no difference between nil and "value not assigned". I'm ok with this in the context of "value coercion".

But in dry-initializer defaults are not related to coercion in any way. They serve a case when a value is not assigned (an optional dependency). Definitions def initialize(name) and def initialize(name = nil) are different ones.

Potentially I can imagine a case when both defaults coexist:

class User
  extend Dry::Initializer

  param :name, default: -> { nil }, type: Types::Strict::String.default('Dude')
end

At first we allow not assigning a name via default: -> { nil }.
Then we use strict type to ensure all assigned values are strings. But .default('Dude') allows to exclude a case of nil from type constraint.

I think this is a good reason for both defaults to be kept along.