These are chat archives for dry-rb/chat

26th
Apr 2016
Published that article.
skus should be an array of hashes
ahh.. nevermind. i don’t need the schema inside the block
Joe Van Dyk
@joevandyk
Apr 26 2016 05:04
how can i ensure that the skus array has at least one element in it?
have to use a thing like?
  rule(skus: [:skus]) do |skus|
    skus.filled?
  end
Joe Van Dyk
@joevandyk
Apr 26 2016 05:32
Not sure if this is a bug — the rules seem to work when not in an array
  1) #<#<Class:0x007f8060043cf0>:0x007f805fff2c10> should not be empty
     Failure/Error: expect(described_class.(skus: [{}]).messages).to_not be_empty
       expected `{}.empty?` to return false, got true
     # ./products.rb:29:in `block (2 levels) in <top (required)>’
also is it possible to have rspec or these classes print out their names in a nice way?
Joe Van Dyk
@joevandyk
Apr 26 2016 05:42
sorry for all the questions ;) is there a way to share the schema between the flat schema and the nested schema?
Piotr Solnica
@solnic
Apr 26 2016 06:57
@joevandyk please use nested schema syntax in each, nested keys are going away in 0.8.0
=> key(:skus).each { schema { .. } }
oh and rule inside each…hmm I’ve never thought about this use case, does it work as expected (it should) ?
@joevandyk re anonymous classes, this sucks I know, just use a string in description for now…I’ll try to figure something out
Piotr Solnica
@solnic
Apr 26 2016 07:37
@joevandyk re ensuring array size, there’s no clean way of doing that yet, it’ll be improved in 0.8.0. For now you can do something like rule(arr_filled: :arr) { |arr| arr.array? & arr.filled? }
we can make it nicer easily, I just haven’t figured out the API yet, ideas are welcome
ie we could have required(:arr).each(:filled?) { … }
this means the predicate passed would be used against the value and rules provided by the block would be applied to value’s items
Piotr Solnica
@solnic
Apr 26 2016 08:44
while drinking coffee in the morning, it crossed my mind to move rom-rb to dry-a-better-name :laughing:
Tim Riley
@timriley
Apr 26 2016 09:02
Woah
Piotr Solnica
@solnic
Apr 26 2016 09:45
@timriley inorite, crazy idea, maybe later lol
dry-data dry-data-sql dry-data-mapper …. THINK ABOUT THAT ;)
Dry::Data::Collection
Dry::Data::Command
Dry::Data::Source
etc
dan-klasson
@dan-klasson
Apr 26 2016 09:47
@solnic doesn't sound that crazy
Piotr Solnica
@solnic
Apr 26 2016 09:47
I know, that’s the scary part
Tim Riley
@timriley
Apr 26 2016 09:55
I like it! And you renamed the original dry-data to dry-types – destiny ;)
Piotr Solnica
@solnic
Apr 26 2016 09:55
yea, funny
dan-klasson
@dan-klasson
Apr 26 2016 10:03
so it will go from DataMapper to ROM to data-mapper? :)
Piotr Solnica
@solnic
Apr 26 2016 10:21
:laughing:
Tim Riley
@timriley
Apr 26 2016 11:57
Weird. GitHub isn’t noticing my pushes to branches.
Nikita Shilnikov
@flash-gordon
Apr 26 2016 11:57
same here
Tim Riley
@timriley
Apr 26 2016 11:57
I was restarting Travis jobs and wondering why they weren’t working.
I think it’s just very slow. My commit just showed up (minutes later)
Piotr Solnica
@solnic
Apr 26 2016 12:01
@timriley I received an email notification about that PR, clicked and got 404 :D
Piotr Solnica
@solnic
Apr 26 2016 14:14
@timriley in case you missed it, here’s a clojure component lib that I think we should look at in search for inspiration for dry-component https://github.com/stuartsierra/component
Joe Van Dyk
@joevandyk
Apr 26 2016 16:10
@solnic the rule inside the each didn’t seem to work, but maybe i did it wrong
Piotr Solnica
@solnic
Apr 26 2016 16:11
@joevandyk define it in the root
it should not be allowed there now that I think about it
Joe Van Dyk
@joevandyk
Apr 26 2016 16:11
not sure what ‘root’ is
Piotr Solnica
@solnic
Apr 26 2016 16:11
top level
not nested
Joe Van Dyk
@joevandyk
Apr 26 2016 16:12
how can i use the rule inside the nested array?
Piotr Solnica
@solnic
Apr 26 2016 16:12
wdym?
Piotr Solnica
@solnic
Apr 26 2016 16:12
just define it for that array in the top level
Joe Van Dyk
@joevandyk
Apr 26 2016 16:12
i have { skus: [ { code that should have rule } }
Piotr Solnica
@solnic
Apr 26 2016 16:14
  key(:skus).each do
    schema do
      optional(:cost).required(:decimal?)
      optional(:price).required(:decimal?)

      rule(price_or_cost: [:cost, :price]) do |cost, price|
        cost.filled? | price.filled?
      end
    end
  end
Tim Riley
@timriley
Apr 26 2016 21:07
@solnic thanks, that's on my to-do list to learn some more about :)
Joe Van Dyk
@joevandyk
Apr 26 2016 22:13
better to pass something into call
if you pass an object into .call, do you not set instance variables?
instead pass all the function arguments that are needed around to private methods?
i just wrote this crappy code, we have a bunch of random IDs that we want to return yes on if the time is a certain date: https://gist.github.com/joevandyk/85ccdc88a2052795513e8eef202a6e9f
@solnic maybe in your book you could address this problem
but i’m assuming that if you do some_object.call(param), you don’t want to set instance variables based off param
otherwise you could lose thread safety if that object is shared
Tim Riley
@timriley
Apr 26 2016 22:34
@joevandyk That’s right, you shouldn’t be setting ivars in call. If we use private methods, we pass any info they need as args.
Joe Van Dyk
@joevandyk
Apr 26 2016 22:34
seems like a pain to keep passing around the same thing as a parameter
Tim Riley
@timriley
Apr 26 2016 22:38
You could always instantiate an internal class inside the #call method
class DoSomething
  class Action
    def initialize(some, state, here)
    end

    private

    def whatever?
      # can operate on ivars
    end
  end

  def call(some, state)
    Action.new(some, state).stuff
  end
end
But that’s even more work that just passing some params around
I don’t mind doing it. Because composition is so easy it’s rare that you end up having much need for many private methods anyway
Perhaps ShouldAutoTangaExpress doesn’t even need to be a functional object.
Couldn’t you just instantiate it with the data you need and run methods on it?