These are chat archives for dry-rb/chat

25th
Aug 2016
Michał Pietrus
@blelump
Aug 25 2016 07:48
morning @solnic , I've recently bumped dry-v to the newest version (0.9.5) and there's one thing that used to work in 0.7, but it seems it doesnt in 0.9.5. In particular, you were able to configure configure { config.messages = :i18n } globally
uhm, perhaps I assumed it worked because of this one I18n backend is no longer required and set by default (solnic). Might be related?
Piotr Solnica
@solnic
Aug 25 2016 08:07
@blelump yes probably. You can still set it in a single place
Michał Pietrus
@blelump
Aug 25 2016 08:09
@solnic , oh, how should I do that ?
Piotr Solnica
@solnic
Aug 25 2016 08:10
Define a base schema class and inherit from it
Michał Pietrus
@blelump
Aug 25 2016 08:12
I see. Since I'm with Reform, there's some work to do to make it possible
Piotr Solnica
@solnic
Aug 25 2016 08:15
Reform should handle it then somehow
Michał Pietrus
@blelump
Aug 25 2016 08:16
yup
Tim Riley
@timriley
Aug 25 2016 10:34
Interesting Ruby behaviour I encountered today:
Thing = Struct.new(:thing)
# => Thing

Thing.new("hi")
# => #<struct Thing thing="hi">

Array(Thing.new("hi"))
# => ["hi"]
# ಠ_ಠ - my struct object got totally stripped away
I see that this is probably due to Struct#to_a
A(nother) reason it’s probably better to define your own classes for holding small values etc. when you need them.
Piotr Solnica
@solnic
Aug 25 2016 10:42
@timriley Struct is a pretty bad API tbf
it’s a) slow!!! b) comes with gotchas like you just mentioned c) splat args in constructor are meh
I initially implemented Message in dry-v using Struct then it turned out to be 2 x slower to instantiate than a custom class with a constructor and attr readers….
Tim Riley
@timriley
Aug 25 2016 10:45
wow!
Piotr Solnica
@solnic
Aug 25 2016 10:45
I was surprised too, I used to think Struct is a very cheap object
Piotr Solnica
@solnic
Aug 25 2016 10:59
@timriley dry-stdlib? O_o
Piotr Solnica
@solnic
Aug 25 2016 11:27
@backus do you think we could wrap up dry-struct?
I have a growing need for it in my current project at work…I start having usecases similar to yours, so I’m motivated to help with that
furthermore, we’re gonna have important improvements in dry-types so would be nice to release it, and in master Struct is no more…:)
Nikita Shilnikov
@flash-gordon
Aug 25 2016 11:30
@solnic dry-rb/dry-struct#8
Piotr Solnica
@solnic
Aug 25 2016 11:49
can somebody remind me why we’re using gemnasium? O_o
Piotr Solnica
@solnic
Aug 25 2016 12:39
dry-rb/dry-validation#241 #help-wanted
Igor
@svilenkov
Aug 25 2016 13:32
Does anyone can see why am I getting a ArgumentError: wrong number of arguments (1 for 0) for initialize the error points to the line def initialize
class IsobusExportAdapter
  extend Dry::Initializer::Mixin

  attr_reader :gis_api_params

  option :application_map_id
  option :field_id
  option :strategy_bundle_id
  option :worker

  def initialize
  end
end
IsobusExportAdapter.new(application_map_id: 43, field_id: field.id, strategy_bundle_id: bundle.id, worker: user)
Piotr Solnica
@solnic
Aug 25 2016 13:35
@keeperhood initialize from Mixin expects arguments
you can’t override it w/o args
Igor
@svilenkov
Aug 25 2016 13:35
Can I use *args ?
Piotr Solnica
@solnic
Aug 25 2016 13:35
yes
def initialize(*args); super; # your-stuff; end
Igor
@svilenkov
Aug 25 2016 13:36
would it work without ; ?
def initialize(*args)
  super
end
gives me
     Failure/Error: super

     ArgumentError:
       wrong number of arguments (1 for 0)
but without super but with just *args doesn't fail, but it doesn't call the mixin initializer
Can you call super with .send or __send__ somehow?
Ralf Schmitz Bongiolo
@mrbongiolo
Aug 25 2016 13:43
@keeperhood do you really need to override initialize? are you setting other variables there or something like that?
Igor
@svilenkov
Aug 25 2016 13:44
Yeah setting more complex variables, based on some db ids
internal objects
Ralf Schmitz Bongiolo
@mrbongiolo
Aug 25 2016 13:45
since you're using options, try this:
def initialize(**args)
  super
  # your stuff
end

# or just define it with the correct options
def initialize(application_map_id:, field_id:, strategy_bundle_id:, worker:)
end
Igor
@svilenkov
Aug 25 2016 13:45
I think this works normally without the mixin, the mixin somehow disallows the same ruby behavior
same error with **args
superis not the same in that scope somehow
hence the error wrong number of arguments (1 for 0) for the line the super is being called
Ralf Schmitz Bongiolo
@mrbongiolo
Aug 25 2016 13:47
maybe, try to call super with the parameters defined to see what happens
Igor
@svilenkov
Aug 25 2016 13:48
wrong number of arguments (4 for 0)
I don't know how the mixin redefines the initialiser, but looks like super is not picking up that
having a after_initialize or some kind of callback would be nice to have
or on_initialize
Ralf Schmitz Bongiolo
@mrbongiolo
Aug 25 2016 13:52
it has something like an __after_initialize__ but I guess that's used internally, but maybe you could use super with it
tbh I haven't used initializer yet, but the ability to use super is something that should work
or then as you suggested some kind of hooks into it
Igor
@svilenkov
Aug 25 2016 13:54
looks like defining a private method __after_initialize__ works
Ralf Schmitz Bongiolo
@mrbongiolo
Aug 25 2016 13:54
try to get a failling spec and add it as an issue there, then we can take a better look at it
Igor
@svilenkov
Aug 25 2016 13:55
This works definitely
private

  def __after_initialize__
    # custom initializer code
    super
  end
Piotr Solnica
@solnic
Aug 25 2016 13:55
I wouldn’t recommend hiding complex object building inside a constructor
I suspect you’d like to hit the db in that overridden constructor?
Igor
@svilenkov
Aug 25 2016 13:56
Well they are just ActiveRecord objects
a simple find method
Can that be set in a proc block of a initializer option ?
Krzysztof Wawer
@wafcio
Aug 25 2016 13:57
Where can I find explanation about components (why it is named components) which are used in dry-web-roda ?
Piotr Solnica
@solnic
Aug 25 2016 13:58
in my head, probably :D
it’s just an idea that a system is composed of multiple components, a component is an isolated part of a system that exposes some API that other components rely on
ie persistence component provides repositories that other components use to get application data
Krzysztof Wawer
@wafcio
Aug 25 2016 14:02
I am wondering why it is named components instead of containers inside lib directory
Piotr Solnica
@solnic
Aug 25 2016 14:02
components are stored in containers
actually system == container
but the fact it’s a container is an implementation detail, it just happens to use dry-container under the hood, hence the System::Container class name
Krzysztof Wawer
@wafcio
Aug 25 2016 14:19
ok thanks
Rafael George
@cored
Aug 25 2016 14:19
@solnic I was checking dry-validation specs
what do you think in turning some of those integration test into feature test. In terms of presenting some use cases like
'when you do this you will have that' because even following the integration specs is hard to know how everything works together from a client point of view
Piotr Solnica
@solnic
Aug 25 2016 14:24
@cored the intentation of these specs wasn’t really to document usage :)
Rafael George
@cored
Aug 25 2016 14:24
do you think will be valuable to have somthing like that ?
Piotr Solnica
@solnic
Aug 25 2016 14:25
not sure tbh, the amount of use cases that we have is enormous, pretty much unlimited, there are already thousands of integration specs, not sure what kind of value feature specs would give us
esp that at the end of the day we need to write user documentation anyway
no specs will replace that
so I’m not very fond of the idea of having even more specs, unless they really provide additional value from test cov pov
Rafael George
@cored
Aug 25 2016 14:39
gotcha
I was trying to understand what will be an entry point for the library
Jānis Miezītis
@janjiss
Aug 25 2016 14:49
This message was deleted
Jānis Miezītis
@janjiss
Aug 25 2016 15:58

Hey folks, wanted to discuss following idea. In application there are cases
where I want to have inheritance on Dry::Struct, but the child struct has
few less attributes. For example user has name, but manager does not require it:

class User < Dry::Types::Struct
  attribute :name, Dry::Types::String
end
class Manager < User
  ignore_attributes :name
end

What about having ignore_attributes option that just removes a specified attribute? Thoughts?

Piotr Solnica
@solnic
Aug 25 2016 16:48
@janjiss just restructure your inheritance hierarchy so it’s not needed
@cored an entry point?
Rafael George
@cored
Aug 25 2016 16:49
like I think in terms of what operations can I do with this system
Piotr Solnica
@solnic
Aug 25 2016 16:49
Schema#call
Rafael George
@cored
Aug 25 2016 16:49
taking an example from your own talk
you had something like CreateUser def call() method in that case createUser is my entry point
maybe a vague word to describe that situation
John Backus
@backus
Aug 25 2016 17:19
@backus do you think we could wrap up dry-struct?
I have a growing need for it in my current project at work…I start having usecases similar to yours, so I’m motivated to help with that
@solnic I'm glad our use cases are beginning to overlap :) :)
I can try to find some time for it soon
To manage expectations though you should know that I have some big deadlines for work over the next 7 days so I might not get to it until then worst case
Piotr Solnica
@solnic
Aug 25 2016 17:20
@backus cool man, it’d be awesome if we could wrap this up before Sept 12
John Backus
@backus
Aug 25 2016 17:22
Okie doke that works with my timeline I think
Piotr Solnica
@solnic
Aug 25 2016 17:22
@backus I fixed a bunch of things today so it’s pretty much ready for development
John Backus
@backus
Aug 25 2016 17:22
Nice yeah I saw
I assume the constrained? thing is API on dry-types that needs to be consistent
Piotr Solnica
@solnic
Aug 25 2016 17:25
@backus that and also fixed gemspec to use VERSION and fixed one failing spec due to a reference to a constant that was no longer there :)
small stuff
John Backus
@backus
Aug 25 2016 17:27
Great
@solnic do you think dry-struct needs to implement these new interfaces before it can be released?
in other words, are the different constructor behaviors release blockers?
Piotr Solnica
@solnic
Aug 25 2016 17:34
no, but I wouldn’t want to release it w/o them, as it’s gonna introduce a new lib, so people may start picking it up, and a couple of weeks later we may change things, so better to change it already :)
John Backus
@backus
Aug 25 2016 17:39
ah kk
Jānis Miezītis
@janjiss
Aug 25 2016 17:59
Is there a way to map Sequel result set to Dry::Structs apart from doing result.map {|attrs| MyStruct.call(attrs) } ?
Don Morrison
@elskwid
Aug 25 2016 22:11
Hey @blelump, did you ever get your reloading thing working? The message I saw you post seemed familiar to me - something we saw when using Wisper in Rails.
The fix was to wrap up the container clearing in the Rails.application.config.to_prepare block. Not sure if that will help you but it may.