These are chat archives for dry-rb/chat

14th
Jul 2017
Cassio Godinho
@cpgo
Jul 14 2017 14:42

hello, can anyone give me some pointers on how is this array syntax implemented?

class UserRepo < ROM::Repository[:users]
  commands :create
end

Never seem this anywhere

I'm talking about the ROM::Repository[:users]
ClassInterface is extended from lib/rom/repository.rb
Cassio Godinho
@cpgo
Jul 14 2017 16:19
@cllns thanks, will try to understand it
Nikita Shilnikov
@flash-gordon
Jul 14 2017 16:22
@cpgo you can have any expression on the right side of <. class Foo < Bar, class Foo < bar, class Foo < classes.get('myshinyparent'), class Foo < Parent[:bar]. All these are valid if the right expression returns a class
Cassio Godinho
@cpgo
Jul 14 2017 16:31
@flash-gordon so, in the snippet I posted I am inheriting from a meta programmed users class?
sorry if this is basic ruby and not the scope for this chat
Nikita Shilnikov
@flash-gordon
Jul 14 2017 16:32
right, klass = Class.new(self < Repository::Root ? self : Repository::Root) <- here we're creating a new class
Cassio Godinho
@cpgo
Jul 14 2017 16:35
so is this some shortcut for not having to define a User class?
Nikita Shilnikov
@flash-gordon
Jul 14 2017 16:38
nope, it's a shortcut for not having an invalid Root ancestor, in fact class UserRepo < ROM::Repository[:users] is equivalent to
class UserRepo < ROM::Repository::Root
  root :users
end
but with ROM::Repository[:users] you don't need to type root :users
that's basically it
Cassio Godinho
@cpgo
Jul 14 2017 16:40
ohhhh
thats much easier to understand
thank you @flash-gordon :smile:
Nikita Shilnikov
@flash-gordon
Jul 14 2017 16:41
np :)
Rafael George
@cored
Jul 14 2017 19:24
hi
if I pass a not defined attribtue to a dry-struct type
will a get a convinience accessor ?
or do I need to define those every time?
Nikita Shilnikov
@flash-gordon
Jul 14 2017 20:31
dry-struct is about defined attributes only, you might want to use optional attributes and the schema constructor type
Sergey Kukunin
@Kukunin
Jul 14 2017 23:38
is there a shortcut in dry-types for single value?