These are chat archives for dry-rb/chat

15th
Aug 2016
dan-klasson
@dan-klasson
Aug 15 2016 08:36
how to chain with custom predicates?
this does't work: required(:username).filled(:unique?).value(size?: 3..10)
and neither does this:
        required(:username).filled(:unique?)
        required(:username).value(size?: 3..10)
Piotr Solnica
@solnic
Aug 15 2016 08:58
@dan-klasson required(:username).value(size?: 3..10, :unique?) although there’s a silly bug that might affect you: dry-rb/dry-validation#227
if that’s the case just pass a block required(:username) { size?(3..10) & unique? }
I’m gonna fix that this week (finally) and push 0.9.5
dan-klasson
@dan-klasson
Aug 15 2016 09:18
@solnic First one gives me a syntax error. The second one:
/home/dan/.rvm/gems/ruby-2.3.1@rails-4.2.6/gems/dry-validation-0.8.0/lib/dry/validation/schema/rule.rb:141:in `and': undefined method `to_ast' for :unique?:Symbol (NoMethodError)
Did you mean?  to_s
dan-klasson
@dan-klasson
Aug 15 2016 09:31
tried upgrading to 0.9.4 as well but same thing
Piotr Solnica
@solnic
Aug 15 2016 09:33
@dan-klasson required(:username) { size?(3..10) & unique? } <= this really should work
dan-klasson
@dan-klasson
Aug 15 2016 09:34
@solnic yeah: required(:username) { size?(3..10) & :unique? }
the configure block:
        configure do
          config.messages_file = 'config/locales/validation.yml'
          def unique?(value)
            User.find_by(username: value).nil?
          end
         end
maybe it could be a TRB thing?
Piotr Solnica
@solnic
Aug 15 2016 09:41
@dan-klasson configure needs to be before rule definitions btw
maybe that’s the case
dan-klasson
@dan-klasson
Aug 15 2016 09:41
@solnic it is
works fine if i take out the size predicate
dan-klasson
@dan-klasson
Aug 15 2016 09:54
@solnic It's in this repo if you want to have a look: https://github.com/dan-klasson/todo-server
under user/operation.rb
Piotr Solnica
@solnic
Aug 15 2016 09:58
@dan-klasson that’s weird, I’ll look into it
dan-klasson
@dan-klasson
Aug 15 2016 09:59
thx :)
Piotr Solnica
@solnic
Aug 15 2016 10:02
@dan-klasson you have tried to use a :unique? symbol in that block, this cannot work, just use a method call required(:username) { size?(3..10) & unique? }
dan-klasson
@dan-klasson
Aug 15 2016 10:03
haha, silly me
i was staring at your and my version above and I still didn't see it
thanks
dan-klasson
@dan-klasson
Aug 15 2016 10:09
@solnic actually, I had to put the unique? before to get it to work, like so: required(:username) { unique? & size?(3..10) }
Piotr Solnica
@solnic
Aug 15 2016 10:13
wdym?
what’s the outcome if it’s first?
dan-klasson
@dan-klasson
Aug 15 2016 10:14
the value of the value variable in the method is always what I call it the first time in my test
resulting in all the other tests to fail
Piotr Solnica
@solnic
Aug 15 2016 10:14
the value of the value variable?
dan-klasson
@dan-klasson
Aug 15 2016 10:15
yes:
          def unique?(value)
            puts value # <--here
            User.find_by(username: value).nil?
          end
Piotr Solnica
@solnic
Aug 15 2016 10:15

is always what I call it the first time in my test

^^ ??

dan-klasson
@dan-klasson
Aug 15 2016 10:16
yeah because i do a check for the error string
so since unique always return true after the first call, the error string contains "username is taken"
but the problem is that unique gets passed the same value it was passed the first time it was called
could be a TRB issue
dan-klasson
@dan-klasson
Aug 15 2016 10:21
sorry, meant to say unique always returns false after the first call
Piotr Solnica
@solnic
Aug 15 2016 10:27
maybe a db-cleanup issue?
dan-klasson
@dan-klasson
Aug 15 2016 10:47
i thought so too. but when i switch the order back i get the error again
and since i do puts value and i can see the value doesn't change
Piotr Solnica
@solnic
Aug 15 2016 11:01
dry-v doesn’t store values anywhere
Piotr Solnica
@solnic
Aug 15 2016 11:17
@/all hey folks, here’s a big one for you - introducing dry-system http://dry-rb.org/news/2016/08/15/introducing-dry-system/
Tim Riley
@timriley
Aug 15 2016 11:19
:clap: :clap: :clap:
Nick Sutterer
@apotonick
Aug 15 2016 11:32
cool!!!
Piotr Solnica
@solnic
Aug 15 2016 12:10
@apotonick cool cool :) now I can finally get back to dry-v business ;)
Nick Sutterer
@apotonick
Aug 15 2016 12:10
yeah fantastic, i want to release reform 2.3.0, i also rewrote the entire document suite for it
Jānis Miezītis
@janjiss
Aug 15 2016 12:30
:clap: :clap: :clap:
Semyon Pupkov
@artofhuman
Aug 15 2016 12:31
:fire: :+1:
henricus louwhoff
@hl
Aug 15 2016 13:16
:thumbsup: great work!
fyi super happy with icelab/berg, I'm basing my own project on it and it's amazing to see the source
Piotr Solnica
@solnic
Aug 15 2016 13:19
@hl great to know :) lots of cool stuff coming soon too, I’m esp excited about the monitoring API we’ve been talking about for like…months :)
henricus louwhoff
@hl
Aug 15 2016 13:20
@solnic I'm building such a great project because of you guys that when I takes off I will have to take you all out for beers and pizza
Piotr Solnica
@solnic
Aug 15 2016 13:20
@hl haha :beers: & :pizza: sounds awesome ;)
Jānis Miezītis
@janjiss
Aug 15 2016 13:20
Remote pizza?
henricus louwhoff
@hl
Aug 15 2016 13:21
@janjiss We'll meet up IRL and call it dry-meats ok?
note the deliberately misspelled gem name ;)
Jānis Miezītis
@janjiss
Aug 15 2016 13:22
Ha ha
henricus louwhoff
@hl
Aug 15 2016 14:46

@solnic question, is this the same (registering container)

Berg::Container.finalize(:postmark) do |_container|
  uses :config

  require "postmark"

  Berg::Container.register "postmark", Postmark::ApiClient.new(config.postmark_api_key)
end

vs

Berg::Container.finalize(:postmark) do |container|
  uses :config

  require "postmark"

  container.register "postmark", Postmark::ApiClient.new(config.postmark_api_key)
end
I think it is, just double checking
jdickey @jdickey cleans up the grue from head exploding after reading dry-system announcement 3x.
Jeff Dickey
@jdickey
Aug 15 2016 14:58
Gonna have to think on this awhile; I (think I) see where you're trying to take this, especially looking at Berg as an example, but… the thought that keeps coming to mind is "Rails without Rails", and I don't think that's fair either way
Piotr Solnica
@solnic
Aug 15 2016 17:03
@jdickey haha…well Berg is a dry-web app, and dry-web is a dry-system-based library which allows you plugging in whatever you want, so not really a framework, and it’ll never be one. That was my main motivation behind this stuff, to have some that allows you composing an app however you like and this is not for everybody.
you could put together a full-stack framework on top of these tools, just like you could build an ORM with rom-rb pieces, same philosophy
Andrew Kozin
@nepalez
Aug 15 2016 17:33

@solnic Hi! What do you think about extending dry-struct with more tolerant initializer?

My common case is related to instantiating struct from parsed json. I have 2 issues here:

  • accept hash with string keys (not symbolic ones)
  • assign values to nil if the key is absent (so that .optional type could accept those data)

Now I just inherit my struct in a way:

class MyStruct < Dry::Struct
  def initialize(data)
    schema  = self.class.schema
    default = schema.keys.each_with_object({}) { |key, hash| hash[key] = nil }
    actual  = data.to_hash.each_with_object({}) do |(key, val), hash|
      hash[key.to_sym] = val
    end

    super default.merge(actual)
  end
end

The question is what do you think about including this behaviour as a default to dry-struct. I have the third project with it and every time I need to make this additional extensions that is boring.

Piotr Solnica
@solnic
Aug 15 2016 17:34
@nepalez this is already being worked on and that’s why we extract dry-struct as a separate project
Andrew Kozin
@nepalez
Aug 15 2016 17:35
hmm, you mean it is already supported?
Piotr Solnica
@solnic
Aug 15 2016 17:36
I don’t remember what the status is O_o just check dry-struct source code / issues :/
you may want to talk with @backus about that
Andrew Kozin
@nepalez
Aug 15 2016 17:36
Yeah, ok, thanks
Jānis Miezītis
@janjiss
Aug 15 2016 17:38
@nepalez Why not use module? By the way, thanks for snoppet, I have exactly same problem :)
Andrew Kozin
@nepalez
Aug 15 2016 17:38
OMG, it was my PR (https://github.com/dry-rb/dry-struct/pull/5/files). Damn sclerosis!
Piotr Solnica
@solnic
Aug 15 2016 17:40
:laughing: :)
John Backus
@backus
Aug 15 2016 17:40
@nepalez I still need to find time to implement a new default constructor type that fills in default values when keys are omitted
Not sure if the constructor type you're proposing might already be supported
Piotr Solnica
@solnic
Aug 15 2016 17:41
@backus did we actually write down what we decided to do? :/
Andrew Kozin
@nepalez
Aug 15 2016 17:41
@janjiss module? You mean, isolate this extension in a module? Yeah, this could be done if we include it into the gem.
But in the application it is an overkill IMO
John Backus
@backus
Aug 15 2016 17:41
Yeah it's somewhere @solnic
Andrew Kozin
@nepalez
Aug 15 2016 17:42
@backus well, that snipped above could be taken as a draft
Jānis Miezītis
@janjiss
Aug 15 2016 17:42
@nepalez I meant on application level - At least until the functionality is in
John Backus
@backus
Aug 15 2016 17:42
@nepalez one thing that is important though is that the constructor types don't keep growing so I'd be wary of allowing string keys and optionals via nil values
Yeah I'll take another look at that PR. @solnic and I had a very specific agreement about the changes so I'll have to make sure it fits
Andrew Kozin
@nepalez
Aug 15 2016 17:46
@backus thank you!
Yes, I think nil default is a sort of evil.
In dry-initializer we implemented another one (when unassigned value has its own representation), but in optional we already have to deal with this "nil for not assigned value" convention.
Jānis Miezītis
@janjiss
Aug 15 2016 22:11
I have the following error each time i save a file in rails
There is already an item registered with the key “diet_planner.decorators.ingredient_with_amount"
Any ideas?
Jānis Miezītis
@janjiss
Aug 15 2016 22:34
Sorry, the dry-types-rails gem helps