sorry to robert. Took me a night to figure out the git code. with method_added and class_eval.
nice piece of code. it works too. On Wed, Jun 27, 2012 at 10:19 PM, salamond <[email protected]> wrote: > Hi, Henry. > > thanks for the info. > > method missing might be a good option. > > class Process > def run; end > end > > class FileUtils > def mkdir; end > end > > class Agent > def method_missing > if Process.new.respond_to(method) || FileUtiles.response_to(method) > do_as_me > Process.new.send(method) > end > end > end > > sort of like this. what do you think? > > > > > On Wed, Jun 27, 2012 at 6:26 PM, Henry Maddocks <[email protected]> wrote: > >> >> On 27/06/2012, at 8:12 PM, salamond <[email protected]> wrote: >> >> Hi, guys. >> >> I want An agent on machine, so that it can fake user actions. >> >> ... >> >> My problem is, I have a very long list of actions, like mv, touch, mkdir, >> rm, etc. >> I don't want to add save and restore euid for all methods. >> >> >> First thing I'd do is remove all the duplication, maybe something like >> this... >> >> class Agent >> def initialize(user, dir) >> @user = user >> @dir = dir >> end >> >> def as_me_do >> bak = Process.euid >> yield >> >> ensure # hat tip Robert >> Process.euid = bak >> end >> >> def mkdir(dir) >> as_me_do {`mkdir`} >> end >> >> def create_file(file, content) >> as_me_do {`echo #{content} > #{file}`} >> end >> end >> >> The next step might be more obvious. >> >> I kind of guess here I should use some meta programming skills. here's >> what i tried. >> >> >> Defining methods is going to be tricky, because you don't have consistent >> method signatures and system calls. Maybe a have a hash of methods => >> system calls and method missing? >> >> Also, why back ticks, why not use ruby File methods? >> >> Henry >> >> > -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
