From: salamond Date: 2012-06-27T23:17:27+09:00 Subject: Re: how about adding method hook --e89a8fb1eef2da6c6304c374df80 Content-Type: text/plain; charset=ISO-8859-1 thanks, robert. I applied aspectr once in my project. the code i'm trying here is that i want to implement my own rspec. but failed. :) On Wed, Jun 27, 2012 at 5:18 PM, Robert Klemme wrote: > On Wed, Jun 27, 2012 at 10:12 AM, salamond wrote: > > Hi, guys. > > > > I want An agent on machine, so that it can fake user actions. > > > > class Agent > > def initialize(user, dir) > > @user = user > > @dir = dir > > end > > def mkdir(dir) > > bak = Process.euid > > `mkdir` > > Process.euid = bak > > end > > def create_file(file, content) > > bak = Process.euid > > `echo #{content} > #{file}` > > Process.euid = bak > > end > > end > > > > 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. > > Btw, your code is not safe as it does not restore on exception. > > > Any one been here before? > > Could be that AspectR is for you. I also once created code to insert > methods before and after a method invocation but I can't seem to find > it in the archives. > > A simple solution could look like this > https://gist.github.com/3002732 > > Kind regards > > robert > > > -- > remember.guy do |as, often| as.you_can - without end > http://blog.rubybestpractices.com/ > > --e89a8fb1eef2da6c6304c374df80 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable thanks, robert.

I applied aspectr once in my project.
the code i'm trying here is that i want to implement my own rsp= ec.
but failed. :)=A0

On Wed, J= un 27, 2012 at 5:18 PM, Robert Klemme <shortcutter@googlemail.com= > wrote:
On Wed, Jun 27, 2012 at 10:12 AM, salamond &= lt;jarodzz@gmail.com> wrote: > Hi, guys.
>
> I want An agent on machine, so that it can fake user actions.
>
> class Agent
> =A0 def initialize(user, dir)
> =A0 =A0 @user =3D user
> =A0 =A0 @dir =3D dir
> =A0 end
> =A0 def mkdir(dir)
> =A0 =A0 bak =3D Process.euid
> =A0 =A0 `mkdir`
> =A0 =A0 Process.euid =3D bak
> =A0 end
> =A0 def create_file(file, content)
> =A0 =A0 bak =3D Process.euid
> =A0 =A0 `echo #{content} > #{file}`
> =A0 =A0 Process.euid =3D bak
> =A0 end
> end
>
> My problem is, I have a very long list of actions, like mv, touch, mkd= ir,
> rm, etc.
> I don't want to add save and restore euid for all methods.

Btw, your code is not safe as it does not restore on exception.

> Any one been here before?

Could be that AspectR is for you. =A0I also once created code to insert
methods before and after a method invocation but I can't seem to find it in the archives.

A simple solution could look like this
https://gist.= github.com/3002732

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end
http://blo= g.rubybestpractices.com/


--e89a8fb1eef2da6c6304c374df80--