Another take on ActiveModel

4 views
Skip to first unread message

August Lilleaas

unread,
Sep 10, 2008, 1:53:17 AM9/10/08
to Ruby on Rails: Core
Greetings,

At RailsConf Europe 2008, I spent some time playing with my own
implementation of ActiveModel. Most of the validations stuff has been
implemented now, so I think it's ready to be shared with the
community.

http://github.com/leethal/activemodel/tree/master

I have not yet tried to integrate this into ActiveRecord (yet). Doing
so is probably quite a lot of work (deprecations etc.), and if it's
done now, it probably has to be re-done by the time of deciding to
actually implement it in the master branch (be it my implementation or
someone elses).

Some notes:

* After talking to DHH on the mentioned RailsConf and showing him my
ActiveModel implementation at the state it was in at that time, he
suggested having a system to hook your own validation methods in a way
that made sure they were available to all libraries using
ActiveModel::Validations. I have implemented this with the
ActiveModel::Validations.add method.
* It does not use the L18n library for validation messages, for no
particular reason. It doesn't really matter at this point, I guess,
and as far as I know, all it takes is adding a .t to the strings.
* The validations sort of implement it's own callback system as of
now. It should probably rely on ActiveModel::Callbacks instead.

August Lilleaas

unread,
Sep 10, 2008, 3:58:10 AM9/10/08
to Ruby on Rails: Core
Regarding the callback library in ActiveModel. I just started working
on that as a stand-alone implementation of callback functionality. But
I guess using ActiveSupport::Callbacks makes sense here?

August Lilleaas

unread,
Sep 10, 2008, 9:16:51 AM9/10/08
to Ruby on Rails: Core
Decided to remove ActiveModel::Callbacks alltogether. What exactly
should it do, anyway? For the purpose of making validations work, I'd
say it's overkill. Perhaps there's something I haven't though of.

7rans

unread,
Sep 10, 2008, 1:28:26 PM9/10/08
to Ruby on Rails: Core


On Sep 10, 1:53 am, August Lilleaas <augustlille...@gmail.com> wrote:
> Greetings,
>
> At RailsConf Europe 2008, I spent some time playing with my own
> implementation of ActiveModel. Most of the validations stuff has been
> implemented now, so I think it's ready to be shared with the
> community.
>
> http://github.com/leethal/activemodel/tree/master

This is kind of interesting to me b/c way back I suggested to DHH that
the underlying DB adapter code would also be a good thing to extract
into a separate project (I dubbed it ActiveDBA, I think DHH suggested
calling it ActionAdapter). I never ended up doing it, but still think
it would be a good project --and actually rather trivial by comparison
to what you are working on, I imagine. Perhaps there is interest
enough now that someone would like to pursue it? Although I wonder,
what is left of ActiveRecord once ActionAdapter and ActiveModel are
separated out of it?

In any case, bringing it all together I think these smaller project
units are a good idea and make an excellent stack of technologies in
its own right.

T.

August Lilleaas

unread,
Sep 11, 2008, 2:19:02 AM9/11/08
to Ruby on Rails: Core
Personally, I can't recall ever having needed a stand-alone DB adapter
library, so I can't be of much help there.

Hongli Lai

unread,
Sep 11, 2008, 5:05:03 AM9/11/08
to Ruby on Rails: Core
On Sep 10, 7:28 pm, 7rans <transf...@gmail.com> wrote:
> This is kind of interesting to me b/c way back I suggested to DHH that
> the underlying DB adapter code would also be a good thing to extract
> into a separate project (I dubbed it ActiveDBA, I think DHH suggested
> calling it ActionAdapter). I never ended up doing it, but still think
> it would be a good project --and actually rather trivial by comparison
> to what you are working on, I imagine. Perhaps there is interest
> enough now that someone would like to pursue it? Although I wonder,
> what is left of ActiveRecord once ActionAdapter and ActiveModel are
> separated out of it?

An excellent idea. This would make ActiveRecord a lot easier to read.

Hongli Lai

unread,
Sep 11, 2008, 5:06:37 AM9/11/08
to Ruby on Rails: Core
On Sep 11, 8:19 am, August Lilleaas <augustlille...@gmail.com> wrote:
> Personally, I can't recall ever having needed a stand-alone DB adapter
> library, so I can't be of much help there.

In places where performance is critical, or when dealing with legacy
databases, it might be necessary to drop to raw SQL. An
"ActionAdapter" might make that a bit easier.

August Lilleaas

unread,
Sep 12, 2008, 4:32:34 AM9/12/08
to Ruby on Rails: Core
Anyone in the core team interested in this?

Michael Koziarski

unread,
Sep 12, 2008, 11:05:33 AM9/12/08
to rubyonra...@googlegroups.com
On Fri, Sep 12, 2008 at 10:32 AM, August Lilleaas
<augustl...@gmail.com> wrote:
>
> Anyone in the core team interested in this?

I've pinged david again to get his feedback. From my own perspective,
we're so close to shipping 2.2 that I'm tryiing not to get distracted
by shiny new things :)

I like the fact that you're cleaning up validations, we've had a few
other threads on this recently, and in the 2.3 lifecycle it'd be
really nice integrate a nice, modular validations module.

So yeah, I like the approach you've taken, but would prefer to hold
off doing anything with it for a few weeks while we try and get a 2.2
beta out the door.

--
Cheers

Koz

August Lilleaas

unread,
Sep 12, 2008, 5:10:30 PM9/12/08
to Ruby on Rails: Core
Sure, I'm thinking of this as a 2.3 (with deprecations) and 3.0 (with
the deprecations removed) kind of thing anyways. Thanks!

On Sep 12, 5:05 pm, "Michael Koziarski" <mich...@koziarski.com> wrote:
> On Fri, Sep 12, 2008 at 10:32 AM, August Lilleaas
>

Rick Olson

unread,
Sep 13, 2008, 12:39:06 AM9/13/08
to rubyonra...@googlegroups.com
On 9/12/08, August Lilleaas <augustl...@gmail.com> wrote:
>
> Sure, I'm thinking of this as a 2.3 (with deprecations) and 3.0 (with
> the deprecations removed) kind of thing anyways. Thanks!

Didn't we talk about tweaking some of the state machine event guarding
and state transitioning stuff to use more validations and callbacks
too? Being able to add validations to anything would be interesting.

The toy yak shave project I thought I was going to be working on over
the summer didn't pan out (no couchdb for me). Therefore, I didn't
get anything done on AMo liked I probably said I would :)

Another thought I had was moving the association proxy and scoping
stuff from AR to AMo. See:
http://www.ideaforge.org/blog/?p=8#comment-67

--
Rick Olson
http://entp.com
http://lighthouseapp.com

S. Brent Faulkner

unread,
Sep 13, 2008, 9:40:35 AM9/13/08
to Ruby on Rails: Core
Hey all

> Didn't we talk about tweaking some of the state machine event guarding
> and state transitioning stuff to use more validations and callbacks
> too? Being able to add validations to anything would be interesting.

I recently experimented with state machines that use callbacks/
observers. I also detect transitions that occur through direct state
manipulation (as opposed to invoking an event! method... e.g.
update_attributes(:state => 'closed')) and fire the appropriate enter/
exit callbacks.

Source is at http://github.com/sbfaulkner/has_states

It's working nicely for me in my current project.

(FYI... had I noticed ActiveModel rather than the other plugins that
are out there I'd have tried this there instead).

Cheers.

--Brent

August Lilleaas

unread,
Sep 19, 2008, 9:23:56 AM9/19/08
to Ruby on Rails: Core
I'm going to put this on hold until 2.2 is out. Then I'll start
working with the AR tests.

On Sep 13, 3:40 pm, "S. Brent Faulkner" <bre...@unwwwired.net> wrote:
> Hey all
>
> > Didn't we talk about tweaking some of the state machine event guarding
> > and state transitioning stuff to use more validations and callbacks
> > too?  Being able to add validations to anything would be interesting.
>
> I recently experimented with state machines that use callbacks/
> observers. I also detect transitions that occur through direct state
> manipulation (as opposed to invoking an event! method... e.g.
> update_attributes(:state => 'closed')) and fire the appropriate enter/
> exit callbacks.
>
> Source is athttp://github.com/sbfaulkner/has_states
Reply all
Reply to author
Forward
0 new messages