These are chat archives for dry-rb/chat

9th
Aug 2016
Adam Davies
@adz
Aug 09 2016 00:51

Hello all! It’s been a while since I looked at ROM/dryrb…
I’m starting a greenfield app which requires a REST api, and thought of using Roda + ROM.

However, I have only seen passing tweets about dry-web :)
...and wonder what the status of it is?
Is it expected the API is fairly stable now? docs?

Tim Riley
@timriley
Aug 09 2016 00:53
No high-level docs for dry-web, unfortunately, @adz. We have an application generator via the dry-web-roda gem, though: dry-web-roda new my_project
APIs aren’t all fully stabilised, but they’re working an in production.
Sergey Kukunin
@Kukunin
Aug 09 2016 01:15
btw, released rspec matcher for dry-types (dry-struct in future) https://github.com/matic-insurance/rspec-dry-struct
it's dead simple, but can be extended
Adam Davies
@adz
Aug 09 2016 01:47
Hmm.. thanks @timriley
I’ll have to have a look through what’s included...
Tim Riley
@timriley
Aug 09 2016 06:34
confusing dry-view thing: when you just so happen to have a partial name the same as a method/attribute on a view part… and you’re expecting the latter to be called (but instead get the partial rendered and lots of unexpted errors)
stigchristian
@stigchristian
Aug 09 2016 07:46

Is this not valid any more?:

TournamentTableSchema = Dry::Validation.JSON do
  required(:type) { filled? > str? }
end

TournamentTablesSchema = Dry::Validation.JSON do
  required(:_embedded).schema do
    required(:tournament_results).each do
      schema(TournamentTableSchema)
    end
  end
end

Raises an ArgumentError input_processor_compiler.rb:66:invisit_implication': wrong number of arguments (given 2, expected 1) (ArgumentError)`

stigchristian
@stigchristian
Aug 09 2016 07:52

This works:

TournamentTableSchema = Dry::Validation.JSON do
  required(:type).filled(:str)
end

TournamentTablesSchema = Dry::Validation.JSON do
  required(:_embedded).schema do
    required(:tournament_results).each do
      schema(TournamentTableSchema)
    end
  end
end

So the error occurs when a block is given to required in a sub schema.

Piotr Solnica
@solnic
Aug 09 2016 10:29
@stigchristian filled? > str? this is not correct (regardless of the crash, which is a bug) as it means that if it’s filled then it must be a string, if it’s not filled, then it’s valid too
we’re moving away from inferring coercions (which is what that ‘input_processor_compiler’ does) so I won’t be fixing this bug
you want required(:type).filled(:str?) which means it a) must be filled b) it must be a string
Piotr Solnica
@solnic
Aug 09 2016 10:58
@timriley ping
Tim Riley
@timriley
Aug 09 2016 11:08
@solnic hey
Piotr Solnica
@solnic
Aug 09 2016 11:44
@timriley some refactorings there…dry-rb/dry-component#27
there are a couple more things I gotta clean up, some things should be moved from container to component. This will simplify container’s code quite a bit
Tim Riley
@timriley
Aug 09 2016 12:10
@solnic very nice, this is taking a much better shape now
What parts from dry-container would move, do you think?
Piotr Solnica
@solnic
Aug 09 2016 12:15
@timriley namespace/key/identifier-related stuff
components should be more namespace-aware and should expose APIs related to that
Tim Riley
@timriley
Aug 09 2016 12:16
ah yeah, I think that’s very smart
Piotr Solnica
@solnic
Aug 09 2016 12:16
like are you namespaced? gimme your ns name, pls. gimme your import-key name, gimme your fully qualified id etc
Jānis Miezītis
@janjiss
Aug 09 2016 13:39
Hey guys, is :alias a reserved word for dry-initializer?
Piotr Solnica
@solnic
Aug 09 2016 13:39
@janjiss it’s a reserved word for Ruby
Jānis Miezītis
@janjiss
Aug 09 2016 13:40
Right!
Piotr Solnica
@solnic
Aug 09 2016 13:40
:)
Jānis Miezītis
@janjiss
Aug 09 2016 13:40
That's what happens when you try to map csv in to the ruby object directly
Thanks @solnic . dry-* is such an awesome collection of gems.
Piotr Solnica
@solnic
Aug 09 2016 13:41
@janjiss I’m glad you like it :)
Jānis Miezītis
@janjiss
Aug 09 2016 16:37
Is it possible to have dry-initializer alongside with dry-types? For example, if I have a class that is constructed by dry-initializer and there is a method that builds another class for dry-type attribute
Piotr Solnica
@solnic
Aug 09 2016 16:43
@janjiss I’d expect both libs to work together w/o any issues (IIRC dry-initializer supports typed attributes already)
Jānis Miezītis
@janjiss
Aug 09 2016 16:46
Sorry to formulate more clearly, can I use Dry::Types::Struct with the dry-initialiser?
It throws an error with missing key if I dont assign the attribute in the initialization. I sort of want fancy attr readers and writers, if that makes sense
Piotr Solnica
@solnic
Aug 09 2016 16:51
ah, I’ve no idea, dry-types struct are going through a redesign process in dry-struct (not released yet). I initially built it only for my use cases in rom-rb, but people would like to use them in different contexts, so default strict behavior (all keys are required) isn’t really working in various cases, so we’re expanding the API in dry-struct
Jānis Miezītis
@janjiss
Aug 09 2016 16:51
Got it :) I’ll probably will try to tinker with default values
Piotr Solnica
@solnic
Aug 09 2016 16:52
@janjiss try setting constructor_type(:schema) in Struct class
this won’t require all keys, but then there are funky cases where defaults aren’t being set and stuff like that, just see if it works for you (it may)
Jānis Miezītis
@janjiss
Aug 09 2016 16:55
This does the trick:
option :user_info,  default: proc {map_user_info}

  def map_user_info
    user_info = UsersImport::Dtos::UserInfo.new()
  end
no need for assignment :D
Sergey Kukunin
@Kukunin
Aug 09 2016 21:42
just came to say, that I enjoy dry-types so much! making structs behave like a type with the same interface is AWESOME!
Jānis Miezītis
@janjiss
Aug 09 2016 21:46
@Kukunin Can you show me an example if that is possible?
Sergey Kukunin
@Kukunin
Aug 09 2016 21:48
@janjiss
class Address < Dry::Types::Struct
  attribute :street, Types::Strict::String 
  # other attributes
end
class Customer < Dry::Types::Struct
  attribute :address, Address.optional
end
Jānis Miezītis
@janjiss
Aug 09 2016 21:48
Got it, thanks!
Sergey Kukunin
@Kukunin
Aug 09 2016 21:48
or even
attribute :address, Types::Nil | Address
so types algebra works for structs as well
Jānis Miezītis
@janjiss
Aug 09 2016 21:49
Im experimenting with Maybe, anyone has an idea how to set up Struct to be a maybe?
Sergey Kukunin
@Kukunin
Aug 09 2016 21:49
Address.optional - makes it Maybe
Jānis Miezītis
@janjiss
Aug 09 2016 21:49
Eureka!
Sergey Kukunin
@Kukunin
Aug 09 2016 21:49
you can set .constrained as well as .constructor for struct as well as for types
Jānis Miezītis
@janjiss
Aug 09 2016 21:49
Thanks @Kukunin
Jānis Miezītis
@janjiss
Aug 09 2016 22:06
@Kukunin Little correction Address.maybe actually creates a monad :)
Sergey Kukunin
@Kukunin
Aug 09 2016 22:08
@janjiss oh. exactly. .optional and .maybe are different
Jānis Miezītis
@janjiss
Aug 09 2016 22:08
@Kukunin That pointed me in the right direction anyways, so thank you very much for that :+1: