## This works ##
def do_something
...
end
MyController.after (:feature=>:do_something) {}
## End ##
## This fails ##
def do_something
...
update_status()
...
end
def update_status
...
end
MyController.after(:feature=>:update_status) {}
## End ##
obviously it would be great to put the filter on the sub-method
(update_status). If 10 methods call update_status, I wouldn't want to
have to write 10 identical calls.
Is there a work-around for this?
By the way, the error I am getting from that second example is:
## Error ##
NameError (undefined local variable or method `public_class_methods'
for RequestsController:Class):
.//vendor/plugins/mole/lib/mole/module.rb:189:in
`find_public_class_method'
.//vendor/plugins/mole/lib/mole/module.rb:200:in `wrap'
.//vendor/plugins/mole/lib/mole/module.rb:125:in `after'
.//app/controllers/requests_controller.rb:569
.....
## End ##
Looking at module.rb (the error is on line 189):
# Attempt to find singleton class method with given name
def find_public_class_method(method)
public_class_methods.each { |m| return m if m.name == method }
#189
nil
end
The problem is that self doesn't equal RequestsController, but instead
RequestsController:Class, which doesn't have the public_class_methods
function. I am having this issue on two methods. Both are sub-
methods, in that they are called by other controller methods, as
described in the first post.
On Apr 13, 9:27 am, "Fernand Galiana" <fernand.gali...@gmail.com>
wrote:
> Hello again,
>
> Could it be the case that update_status might be private/protected on the
> controller ? Currently the MOle will only attempt to locate public
> methods...
>
> -Fernand
>
While I did in fact get a NameError, it was raised by module.rb:189,
not 201, which means that the error was raised by the system, not by
201: "raise NameError".
You asked if if might be a typo in the method name. Do you mean in
the :feature=><...> part?
I know that is right because I switch it to a non-error version when
I'm testing it:
### Code ###
def view
...
@foo = "FOO"
end
RequestsController.after(:feature=>:view) do |context, feature,
args, block|
Mole::DbMole.mole_it( context, feature,
context.session[:user], :args=>context.instance_variable_get(@foo))
#Mole::DbMole.mole_it( context, feature,
context.session[:user], :args=>args)
end
### End ###
The Readme has the following url for the beast demo:
svn://rubyforge.org/var/svn/liquidrail/plugins/mole/trunk/samples/beast
but that doesn't exist.
I found this, though: svn://rubyforge.org/var/svn/liquidrail/plugins/mole/samples/beast
The app failed to run. I guess I have to have beast installed to use
the demo? The database.yml file points to localhost, and the server
shows a page with "Oops! It looks like there was an error." Also, I
couldn't find any of the mole before/after calls in the controllers.
Maybe I downloaded the wrong thing? I don't see the similar case you
mentioned in your last post.
On Apr 15, 3:11 am, "Fernand Galiana" <fernand.gali...@gmail.com>
wrote:
> Patrick - I am updating the plugin as we speak. I have opted to remove
> the code to try to detect static methods.
>
> So could there be a typo on the method name ?
>
> I think I have a similar case illustrated and working on the beast sample
> app ( you'll need to svn update... ), take a look and see if the setup is
> any different from yours...
>
> Please keep me posted on this issue...
>
> -Fernand
>
The beast errors are all applicable, but the code segment should be:
### Code ###
def save_req(req)
...
end
RequestsController.after(:feature=>:save_req) do |context, feature,
args, block|
Mole::DbMole.mole_it( context, feature,
context.session[:user], :args=>args)
end
### End ###
turns out you have to put the mole_it call *after* the definition of
the function in the source file. I had originally had the sub-methods
at the end of the file, since they used to be private (before mole).