I'm a bit stuck with where to put some method calls (separation of
responsibility) and although I'm trying to do it just simply now in the
models, I think my problem raises a bigger question about Fat Models. But
that's another subject for another day.
Right now, I have ....
Event
has_many meetings
## has an a invitation_expiry date field.
def invitation_expired?
DateTime.now.in_time_zone('UTC') >=
event.invitation_expiry.in_time_zone('UTC')
end
Meeting
belongs_to :event
has_many :invitations
def invitation_expired?
event.invitation_expired?
end
Invitation
belongs_to :meeting
My problem is when an invitation is made, I want to check if the invitation
has expired. I have thought of the following ....
1. include a method call in the Invitation model
## Check if the meeting (event's invitation) has expired (should it be
called event_invitation_expired?
## Should the invitation know anything about the Event class?
def meeting_expired? ## event_invitation_expired?
meeting.invitation_expired? ## meeting.event.invitation_expired?
end
2. include an event_id foreign key in the invitations table so I can have
the same method as in the Meeting model
def invitation_expired?
event.invitation_expired?
end
I'm happy with either one but am open to other ideas or what you would do.
The BIGGER question is, what exactly should go in the models?!! We talk
about Fat models, but for me, that doesn't fit nice with OO programming. To
me, it's quite clear that the we are not doing OO programming by stuffing
our models with everything related to that model. There needs to be another
level of abstraction to keep everything clean and have the separation of
concerns.
I'm a self taught OO programmer and I come from a functional programming
background, so maybe I'm talking out of my hat. But while writing tests for
my app, to me, there are just too many code smells.
I look forward to your thought
-ants
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.