Property delegation

8 views
Skip to first unread message

Steve V

unread,
Nov 24, 2014, 1:03:17 PM11/24/14
to roar...@googlegroups.com
I've lately found myself setting a lot of properties that delegate to another object:

property :first_name, getter: lambda {|*| user.first_name}

I'm pretty sure roar/representable don't support a way to simplify that statement, but please correct me if I'm wrong.

If it's not supported, would a syntax like this be acceptable or are there things I'm not considering?

property :first_name, from: :user

Thanks,
Steve


Steve V

unread,
Nov 24, 2014, 4:20:01 PM11/24/14
to roar...@googlegroups.com
I thought of a potential issue which is if the property name needed to differ from the attribute name then this wouldn't work, but we already have `:as` that would have us covered for that.

Where in the code would this change go? I think definition.rb would need to be updated to accept the argument. Where would the actual process of getting the value happen? binding.rb?

Daniel Doubrovkine

unread,
Nov 25, 2014, 9:12:34 AM11/25/14
to roar...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "Roar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to roar-talk+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Steve Valaitis

unread,
Nov 25, 2014, 9:19:09 AM11/25/14
to roar...@googlegroups.com

It would. That's where the files I mentioned are from. As far as I know though, there is no representable discussion group.

You received this message because you are subscribed to a topic in the Google Groups "Roar" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/roar-talk/tAMPTIosTmc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to roar-talk+...@googlegroups.com.

Daniel Doubrovkine

unread,
Nov 25, 2014, 9:36:42 AM11/25/14
to roar...@googlegroups.com
I think this is it basically ;0 Open an issue on Github or just contribute!

Nick Sutterer

unread,
Nov 30, 2014, 12:18:15 AM11/30/14
to roar...@googlegroups.com

Steve Valaitis

unread,
Dec 1, 2014, 10:21:17 AM12/1/14
to roar...@googlegroups.com
I know aliasing can get me a different property name, and use it a
lot, but can it get an attribute of another attribute? Does `:as`
support dot-syntax? I didn't think it did, but maybe I missed that.

Nick Sutterer

unread,
Dec 1, 2014, 5:39:29 PM12/1/14
to roar...@googlegroups.com
Ah, ok, sorry Steve! The delegation you need is implemented in disposable's Composition/Delegation. This is in use in Reform and I want to allow this in Roar/Representable, too.

Basically, you'd do the following then.

property :title, on: :song


Daniel Doubrovkine

unread,
Dec 2, 2014, 8:01:13 AM12/2/14
to roar...@googlegroups.com
Oh, on: is nice! Does is survive `nil`?

Nick Sutterer

unread,
Dec 2, 2014, 4:43:01 PM12/2/14
to roar...@googlegroups.com
The :on option so far only works in Reform (and disposable), and here only for compositions, not delegations. To put this straight: Disposable's job is to provide the data modelling, Reform, Cells, Roar, etc. shouldn't know about mappings and the like. By using Disposable, we have the same semantics and implementation in all the gems.

I might actually need this delegation myself today, Steve, so you might get lucky! 
35C.gif
Reply all
Reply to author
Forward
0 new messages