Forum: Ruby Merb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Mike M. (Guest)
on 2009-04-30 17:17
Hi I'm writing a class in /lib,
I would like the class accessing the "request" object

have you an idea ?

Thx
Phlip (Guest)
on 2009-04-30 17:35
(Received via mailing list)
Mike Mickey wrote:
> Hi I'm writing a class in /lib,
> I would like the class accessing the "request" object
>
> have you an idea ?

Don't. If it accesses that, it's a Controller, no matter where you put
it.

Now, can you pass what you need into the class in lib?

And if the class is modular (even if it has no database hooks), should
it be a
model?

And do you have unit tests on it, so you can refactor it as you learn
the best
role for it?

(But note that questions which are actually about Merb belong on its
cheerful,
friendly, and mature mailing list...)
Mike M. (Guest)
on 2009-04-30 17:40
> Now, can you pass what you need into the class in lib?

actually i need a lot of information from the request object

> And if the class is modular (even if it has no database hooks), should
> it be a
> model?

I thought a model could not access the request ?

> And do you have unit tests on it, so you can refactor it as you learn
> the best
> role for it?

not unit tests for it (for the moment)
Phlip (Guest)
on 2009-04-30 18:03
(Received via mailing list)
Mike Mickey wrote:

>> Now, can you pass what you need into the class in lib?
>
> actually i need a lot of information from the request object

What is the class doing? I can think of things like correlating the
user_agent
with the IP and the login history, to detect excessive login attempts...

> I thought a model could not access the request ?

For the same reason a lib item can't see the request.

Just pass the request into your top method.

> not unit tests for it (for the moment)

Write the tests first! Don't write them "last" - you will have no
incentive to
get back to it.
Mike M. (Guest)
on 2009-04-30 19:07
> What is the class doing? I can think of things like correlating the
> user_agent
> with the IP and the login history, to detect excessive login attempts...

it's an API wrapper but a lot of calls are cached in the session, so i
need to access the session in all the function of the class.

Have you a better solution ?
Phlip (Guest)
on 2009-05-01 04:46
(Received via mailing list)
Mike Mickey wrote:

> it's an API wrapper but a lot of calls are cached in the session, so i
> need to access the session in all the function of the class.
>
> Have you a better solution ?

Better than passing the whole object in? you said you need the whole
object; go
ahead and rely on OO and encapsulation. There's nothing architecturally
wrong
with passing a whole object in.

The Merb mailing list might have other ideas...

   news://news.gmane.org:119/gmane.comp.web.merb.devel

...but be prepared to answer the same questions as I asked.
This topic is locked and can not be replied to.