Merb

Hi I’m writing a class in /lib,
I would like the class accessing the “request” object

have you an idea ?

Thx

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…)

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)

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 ?

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 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.