[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[Facets] Add a Module#attr_validator method

Daniel Schierbeck

4/1/2006 3:53:00 PM

I couldn't find a Facets mailing list, and I know the developers use
this list, so therefore I send my proposal here.

I'd like to see the addition of an attribute validator, i.e. a setter
that checks to see if a block returns true when called with the new
value as its only argument. Without further ado, I hereby present
Module#attr_validator:

class Module
def attr_validator(*symbols, &validator)
symbols.each do |symbol|
define_method "#{symbol}=" do |val|
unless validator.call(val)
raise ArgumentError, "Invalid value provided for #{symbol}"
end
instance_variable_set("@#{symbol}", val)
end
end
end
end

Use it, change it, polish it - it's yours.


Cheers,
Daniel Schierbeck
28 Answers

Daniel Schierbeck

4/1/2006 3:59:00 PM

0

Daniel Schierbeck wrote:
> I couldn't find a Facets mailing list, and I know the developers use
> this list, so therefore I send my proposal here.
>
> I'd like to see the addition of an attribute validator, i.e. a setter
> that checks to see if a block returns true when called with the new
> value as its only argument. Without further ado, I hereby present
> Module#attr_validator:
>
> class Module
> def attr_validator(*symbols, &validator)
> symbols.each do |symbol|
> define_method "#{symbol}=" do |val|
> unless validator.call(val)
> raise ArgumentError, "Invalid value provided for #{symbol}"
> end
> instance_variable_set("@#{symbol}", val)
> end
> end
> end
> end
>
> Use it, change it, polish it - it's yours.
>
>
> Cheers,
> Daniel Schierbeck

Note that this of course only works when you actually *use* the setter
method, i.e. `@attr = val' will not validate `val'. Nor do I think it
should.


Cheers,
Daniel Schierbeck

Trans

4/1/2006 8:20:00 PM

0

Thanks Daniel, I'll give this some consideration.

A more interesting alternative that could soon come to pass is an
extension to Facets' annotation system. Right now one can easily do:

require 'facet/annotation'

class Foo
attr_accessor :x
ann :x, :validation => proc { |x| ... }
end

But this is nothing more than a note. For it to actually have any
effect one would have to manually utilize the note. With then next
version of annotation.rb I plan to add annotation hooks. By defining a
hook you can automatically have it do what you would like when a
particular annotation is define. For instance:

Annotation.annotation_action( :validation ) { |symbol, validator|
wrap_method( "#{symbol}=") { |target, x|
unless validator.call( x )
raise ArgumentError, "Invalid value provided for #{symbol}"
else
target.call(x)
end
}
}

Now when you make the above annotation it will automatically generate
the validating setter as you describe.

The only downside to this kind of thing at the moment is the lack of an
adequate AOP foundation built into Ruby.

But all that is down the road yet. In the mean time I will likely add
your method. Thanks.

T.

P.S. Using this list is fine, especially if you're interested in wider
input from the Ruby community. You can also email the Nitro list
--Facets is a key component of Nitro/Og. And of course you can always
email me directly.

Ara.T.Howard

4/1/2006 8:48:00 PM

0

Daniel Schierbeck

4/2/2006 2:20:00 PM

0

Trans wrote:
> Thanks Daniel, I'll give this some consideration.
>
> A more interesting alternative that could soon come to pass is an
> extension to Facets' annotation system. Right now one can easily do:
>
> require 'facet/annotation'
>
> class Foo
> attr_accessor :x
> ann :x, :validation => proc { |x| ... }
> end
>
> But this is nothing more than a note. For it to actually have any
> effect one would have to manually utilize the note. With then next
> version of annotation.rb I plan to add annotation hooks. By defining a
> hook you can automatically have it do what you would like when a
> particular annotation is define. For instance:
>
> Annotation.annotation_action( :validation ) { |symbol, validator|
> wrap_method( "#{symbol}=") { |target, x|
> unless validator.call( x )
> raise ArgumentError, "Invalid value provided for #{symbol}"
> else
> target.call(x)
> end
> }
> }
>
> Now when you make the above annotation it will automatically generate
> the validating setter as you describe.
>
> The only downside to this kind of thing at the moment is the lack of an
> adequate AOP foundation built into Ruby.
>
> But all that is down the road yet. In the mean time I will likely add
> your method. Thanks.
>
> T.
>
> P.S. Using this list is fine, especially if you're interested in wider
> input from the Ruby community. You can also email the Nitro list
> --Facets is a key component of Nitro/Og. And of course you can always
> email me directly.

Thanks for considering my idea. Personally, I like to think of a
validator as a setter/writer that adds value validation - annotations
just don't fit in my perception of that process, though what you
describe would be useful, too.

Cheers,
Daniel Schierbeck

Jerome Kelly

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #003


On Mon, 12 Jan 2009 11:09:51 -0600, Kunt_Lochner
<kunt_lochner@NOSPAMhotmail.com> wrote:
>>Give us an example
>Oh, so you're afraid to look at the message-ID header yourself?
>You claimed it was 75.189.155.174.

No, little Kuntie, I NEVER claimed THAT post was from IP:
75.189.155.174.

I claimed THAT POSTER was a FRAUD.

I PROVED THAT POSTER was a FRAUD.

More importantly, I SET ANOTHER TRAP, and YOU WALKED RIGHT INTO IT!

But THIS TIME, I set a trap JUST FOR YOU!

And YOU LURCHED RIGHT INTO IT with your OkieHomo bobbleheaded face on
a pencil-neck swivel!!

Bwahahahahahahhaha!!!

>http://groups.google.com/group/alt.politics/msg/92d4dc0c72f770e5?hl=en&dm...
>--Go look up the IP-address of "incontinentmccain@gmail.com", moron..

Yes, Kuntie, I had ALREADY checked that 97.82.146.167 was the SAME
FRAUD POSTER from 75.189.155.174....

Hahahahahahhaa!!

And I WITHHELD THAT FACT to BAIT my TRAP for Iris' little basement
short-stroker!

And, so, Dear Friends, Kuntie Lochner-Harrington HAS BEEN BUSTED,
again...

>I already checked those IP addresses because I don't make claims, I
>PROVE FACTS.
>
>YOU DID NOT check those IP addresses because YOU ARE A FRAUD. You have
>a bullshit incomplete education, a damaged maladjusted personality,
>and the burdensome baggage of a disgraced and discarded basement
>bastard.
>
>From: incontinentmccain@gmail.com
>Date: Sun, 11 Jan 2009
>NNTP-Posting-Host: 97.82.146.167
>
>From: cake_and_eat_it_...@yahoo.com
>Date: Wed, 7 Jan 2009
>NNTP-Posting-Host: 97.82.146.167
>
>From: i_hate_gwb...@yahoo.com
>Date: Sun, 11 Jan 2009
>NNTP-Posting-Host: 97.82.146.167
>
>Sources:
>http://groups.google.com/group/alt.politics.democrats/msg/7916968db3929cc7?hl=en&dm...
>Or: http://tinyurl....
>
>http://groups.google.com/group/alt.politics.bush/msg/bcc853f05f52e913?hl=en&dm...
>Or: http://tinyurl....
>
>Original Post ----------------------------------
>From: cake_and_eat_it_too@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: everonlynice@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: graverobber_69@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: i_hate_gwbush@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: haterofneocons@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: psyber_operations@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>From: triba_la_raza@yahoo.com
>NNTP-Posting-Host: 75.189.155.174
>75.189.155.174 = Raleigh, North Carolina.
>------------------------------------------------------
>
>Thanks for the opportunity to SHIT in your OPEN MOUTH IN PUBLIC!
>
>I have SHIT in your OPEN MOUTH IN PUBLIC repeatedly.
>
>I will continue to SHIT in your OPEN MOUTH IN PUBLIC.
>
>I will continue to SHIT in your OPEN MOUTH IN PUBLIC F O R E V E R!
>
>There is NOTHING you can do about it.
>
>There is NOTHING you can do to prevent it.
>
>IT WILL NEVER END.
>
>Is it clear NOW? Do you understand NOW? Is any of this getting
>through to your little faggot brain?
>
>I'll type slow so you can follow along:
>
>I w i l l N E V E R s t o p p o s t i n g y o u r L I E.
>
>N E V E R!
>
>Are you paying attention NOW, Kunt?
>
>One more time:
>
>I w i l l N E V E R s t o p p o s t i n g y o u r L I E.
>
>N E V E R!

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...

D Swan

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #005


On Sun, 18 Jan 2009 19:37:19 -0600, Kunt_Lochner
<kunt_lochner@NOSPAMhotmail.com> wrote:
>W Bush took a budget surplus and ran up the national debt into
>the trillions, banks are being closed daily...

Oops! Caught LYING, again...

Somebody call Iris and tell her that Little Short-Stroker Kuntie is
using that
computer in the basement again!

No, banks are NOT "being closed daily."

No, it is DEMOCRATS who have a 112.5% Bank Failure Rate.

Failed Bank List Since October 1, 2000.
http://www.fdic.gov/bank/individual/failed/ban...
(Last Updated 1/16/09)

Before Democrats Controlled Congress

2001: 0
2002: 1
2003: 2
2004: 3
2005: 5
2006: 1
Total: 12

After Democrats Controlled Congress
(As of 1/16/09)

2007: 3
2008: 25
2009: 2
Total: 30

Republican Bank Failures: 29%
Democrat Bank Failures: 71%

Clinton Bank Failures:
http://www.fdic.gov/bank/historical/bank/...

1993: 42
1994: 13
1995: 6
1996: 6
1997: 1
1998: 3
1999: 8
2000: 7
Total: 86

Bush Bank Failures:

2001: 0
2002: 1
2003: 2
2004: 3
2005: 5
2006: 1
2007: 3
2008: 25
Total: 40

Bush Bank Failures: 32%
Clinton Bank Failures: 68%

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...

R Wyatt

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #004


On Thu, 15 Jan 2009 10:55:29 -0600, Kunt_Lochner
<kunt_lochner@NOSPAMhotmail.com> wrote:
>Nor is there even mentions of a "climate
>czar" over on "The Hill" site, where the cabinet selections are listed..

Oops! CAUGHT LYING, Again...

OOPS!

Little short-stroker Kuntie Lochner-Harrington snuck out of Iris'
basement and got CAUGHT LYING...

Again.....

http://search2.thehill.com/search?ie=&site=thehill_com&output=xml_no_dtd&client=thehill_frontend&lr=&proxystylesheet=thehill_frontend&oe=&q=climate+czar&btnG.x=8&...

Or: http://tinyurl....

Searched for climate czar. Results 1 - 10 of about 100. Search took
2.19 seconds

First page:

The Hill?s Blog Briefing Room ? Colin Powell ... According to an
unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/colin-powell/ - 101k

The Hill?s Blog Briefing Room ? Gore Rejects Obama ... ... Gore's name
had been entered into speculation for the position of a "climate
czar,"playing on his specialty in environmental and climate change
issues. ...
briefingroom.thehill.com/2008/11/13/gore-rejects-obama-administration-position/
- 68k - 2008-11-13

The Hill?s Blog Briefing Room ? Al Gore ... According to an unofficial
transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/al-gore/ - 101k

The Hill?s Blog Briefing Room ? MORNING READ ... According to an
unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/2008/11/12/morning-read-164/ - 101k -
2008-11-12

The Hill?s Blog Briefing Room ? Robert F. Kennedy Jr. ... According to
an unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/robert-f-kennedy-jr/ - 101k

TheHill.com - Obama irks panel heads with silence ... and Public Works
Committee, had a similar complaint about being kept in the dark
before the president-elect named Carol Browner climate czar and Lisa
Jackson ...
thehill.com/content/view/78894/70/1/1/ - 52k - 2009-01-14

The Hill?s Blog Briefing Room ? John McCain ... According to an
unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/john-mccain/page/3/ - 101k

The Hill?s Blog Briefing Room ? Sarah Palin ... According to an
unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/sarah-palin/page/3/ - 101k

The Hill?s Blog Briefing Room ? Caroline Kennedy ... According to an
unofficial transition flowchart going around Washington, Gore could
serve as "climate czar," Powell could serve as Education Secretary,
Robert F ...
briefingroom.thehill.com/tag/caroline-kennedy/page/4/ - 101k

The Hill?s Blog Briefing Room ? Energy & Environment ... After Obama
won the presidency early last month, Gore publicly declined any role
in the administration as a climate change czar. -Sam Youngman. ...
briefingroom.thehill.com/category/energy-environment-campaigns/ - 100k
Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...

Darin Gilman

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #006


On Sun, 31 May 2009 17:14:20 -0600, Baron_Mind
<baron.von.mind@gmail.com> wrote:
>Unfortunately for you "pretty hard core" nut-cases, you're
>very much in the minority, and have marginalized much of
>the support you imagine that you thought you've had..

Wrong, Kuntie:

FOX News/Opinion Dynamics Poll. May 12-13, 2009. "On the issue of
abortion, would you say you are more pro-life or more pro-choice?"

Pro-life: 49%
Pro-choice: 43%
http://www.pollingreport.com/ab...

Gallup Poll. May 7-10, 2009. "With respect to the abortion issue,
would you consider yourself to be pro-choice or pro-life?"

Pro-Choice: 42%
Pro-Life: 51%
http://www.pollingreport.com/ab...

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...

Kristina Damien Jacobson

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #007


On Mon, 15 Dec 2008 11:13:08 -0600, Kurt_Lochner
<kurt_lochner@NOSPAMhotmail.com> wrote:
>"pet rat gametes" <booby.milby@tampabay.rr.com> whined impotently when:
>> > > > >Frauds are exposed
>> > > > Like yourself?
>> > >Prove it is
>> > --Your "software compiler" posting gave it away..
>>Really?

>>"Windows Interface Language: At the heart of WinBatch is our Windows
>>Interface Language (WIL). It?s a high-level programming language for
>>automating Windows; hundreds of Windows tasks are pre-coded for you.
>>Operations that require pages of code in other programming languages
>>are just a single function call in WinBatch."
>>http://www.winbatch.com/pro...
>>Feel free to PROVE that is NOT "software." FAILING TO DO SO PROVES
>>YOU ARE A LIAR.
>Feel free to prove you actually have programming skills..

You FAILED to PROVE that was NOT "software."

YOU are a PROVEN LIAR.

>>"WinBatch+Compiler uses our Windows Interface Language (WIL), a
>>full-featured programming language, and produces independent .EXE
>>files that you can distribute freely."
>>http://www.winbatch.com/wb-com...
>>Feel free to PROVE that is NOT a "compiler." FAILING TO DO SO PROVES
>>YOU ARE A LIAR.

You FAILED to PROVE that was NOT a "compiler."

YOU are a PROVEN LIAR.

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...

Keri Connie Souza

2/12/2013 11:44:00 PM

0

Kurt Lochner Is A Proven Liar - #008


On Mon, 15 Dec 2008 22:09:06 -0600, Kurt_Lochner
<kurt_lochner@NOSPAMhotmail.com> wrote:
>"pet rat gametes" <booby.milby@tampabay.rr.com> whimpered again:
>> > >YOU FAILED to PROVE that was NOT "software."
>You edited a script in a batch file

Prove it.

>Done any assembly language? I noticed that you avoided that
>part about M/ASM, entirely..

I didn't want to embarrass and humiliate you in public, again, for
trying to change the subject. Especially since I'd JUST SHIT IN YOUR
OPEN MOUTH TWICE IN PUBLIC.

So, as YOU REQUESTED, I will now SHIT IN YOUR OPEN MOUTH IN PUBLIC
again and allow you the opportunity to DEFEND your ATTEMPT to CHANGE
THE SUBJECT.

Begin here:________________________

>> > > > Feel free to prove you actually have programming skills..
>> > > > --Instead of just editing what was already written for you.. *>LOL!<*
>> > >Are you claiming somebody wrote this for me?
>> > Oh you edited a script that came with the program you downloaded..
>>Prove it.
>Don't have to

You CLAIMED I "edited a script that came with the program you
downloaded."

You were provided the URLs to PROVE THAT CLAIM.

You FAILED to PROVE THAT CLAIM.

You are a PROVEN LIAR.

This, then, represents the Total Internet Destruction of Kunt Lochner.

To celebrate Total Internet Destruction of Kunt Lochner I wrote a
short jingle for you:

(Sung to the tune of "Oh Where Has My Little Dog Gone?)

Oh where, oh where has my Pet Nigger gone?
Oh where, oh where can he be?

With his ass so spanked and his lack of brawn.
Oh where, oh where can he be?

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...