use of *args parameter?

1 view
Skip to first unread message

Eric Pugh

unread,
Aug 31, 2007, 5:43:33 PM8/31/07
to MOle Plugin
Hi,

I'm trying to use the *args parameter to pull out some specific params
and getting odd errors. Is there any examples of pulling out
parameters form the *args?

I wanted to do in my mole_it method:

:reporttype => args[:reporttype]

and I get Symbol errors...

Eric

Fernand Galiana

unread,
Aug 31, 2007, 6:21:47 PM8/31/07
to mole-...@googlegroups.com
Hi Eric,

   The args parameter in the mole callback will be the array of argument made in the call ie

   fred( "Hello", "Dog", 1 )

   then in you mole that call

Blee.after( :feature => :fred ) { |context, feature, ret, args, block|
  p args # =>  ["Hello", "Dog", 1 ]
}
 
   If however you are trying to grab state of your controller actions you would need to
   make the following call in you mole callback

MyController.after( :feature => :my_action ) { |context, feature, ret, args, block|
   # Grab controller state
   context.instance_variable_get("@blee")
   ...
   # Grab request params
   context.params [:blee]
   ...
   # Grab session params
   context.session[:fred]
   ...
}

   - my_controller

   def my_action
        @blee = "fred"
   end

   Does this make sense ?

-Fernand

Eric Pugh

unread,
Sep 4, 2007, 7:42:34 AM9/4/07
to MOle Plugin

It does... And that is how I *thought* it worked. However, I wanted
to use the nice method of pulling out specific parameters. If my
controller looks like /my_controller/do_something?id=20

then I thought I could do something like

:id => args[:id]

and store :id = 20 in the resulting YAML section. But that doesn't
quite seem to happen.. When you say args, are you meaning something
other then GET or POST parameters?

Eric

On Aug 31, 6:21 pm, "Fernand Galiana" <fernand.gali...@gmail.com>
wrote:

Fernand Galiana

unread,
Sep 4, 2007, 10:30:16 AM9/4/07
to mole-...@googlegroups.com
Hi Eric,

   Sorry for the confusion... Yes the args parameter is used when you want
   to mole methods calls that may take arguments. In the case of a controller
   action typically you would not have any arguments, but would pull request and session
   parameters directly of the context object passed into the mole block ie using something like
   context.request[:id] or context.session[:last_pull]. The args parameter would be used in case
   where you want to mole a third party type call ie something like:

   def calc_shopping_cart_total( user, items )
     ...
   end

   Then the args parameter would contain the passed in values for user and items when the call
    is made.

    In the case of a controller call we felt that storing session/request parameters in the args wouldn't be as useful, since that state is directly available in the passed in context object...

-Fernand
Reply all
Reply to author
Forward
0 new messages