From: Dave Birch Date: 2010-01-15T23:42:16+09:00 Subject: Re: Binding scope Marnen Laibow-Koser wrote: > Dave Birch wrote: >> Hi Marnen >> >> Thanks very much for the reponse. >> >> Marnen Laibow-Koser wrote: >>> Dave Birch wrote: >> >>> You are aware of the serious security problems with this, right? >> >> Yes, this isn't a public-facing site, and there will be no front-end >> access to the database that will generate and store the code. > > Then you shouldn't need to do this in the first place. If there's no > frontend access to the DB, presumably that means that the app itself is > generating the code. If so, then it can keep it as a method in a live > object rather than writing it to the database and opening up a security > hole. > To give you a bit of background to this - I've got a "macro" that is generating a bunch of reports. The reports contain lines like "the number of people in this group are X and they have spent a total of Y on your product this year". The problem is, I can't substitute X and Y for their real values at the time the macro runs, because I don't know what filters the user will apply when viewing the reports. So I need a way to do the calculations and substitute in the values when the user views the report, and to recalculate these each time the user changes the filter (e.g. show me only people older than 30). So unless I'm missing something, I can't keep a live object. It's a rails app, and the controller will be pulling together a "@results" variable, but will not necessarily know what kinds of stats need to be pulled from it. That's why i'd like to be able to do things like "the number of people in this group are @results.size and they spent @results.collect(&:spend).sum on your product this year". Doees this make sense? >> >>> [...] >>>> But I cannot work out how to get the scope of the class within >>>> which Substitutable has been "include"d. >>> >>> Perhaps you should use the Module#included callback to register it. >> >> I will look at this - thanks again for the tip. >> >> Regards, >> Dave >> >> >>> >>> Best, >>> --  >>> Marnen Laibow-Koser >>> http://www.marnen.org >>> marnen@marnen.org > > Best, > --  > Marnen Laibow-Koser > http://www.marnen.org > marnen@marnen.org -- Posted via http://www.ruby-forum.com/.