Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Property files

Reply
Thread Tools

Property files

 
 
Ron Coutts
Guest
Posts: n/a
 
      12-23-2003
Is there a library class for handling common property files that have
the key=value syntax? Basically all I need to do is read some
properties from a properties file, perform succ! on some of them, and
write the property file back to disk. There were a couple of threads
about properties files earlier in December that mentioned use of
Config.rb but I'm having trouble finding documentation for this library,
if it is one. I'm using Ruby 1.8.0.

Ron



 
Reply With Quote
 
 
 
 
John W. Long
Guest
Posts: n/a
 
      12-24-2003
---- "Ron Coutts" wrote: ----
> Is there a library class for handling common property files that have
> the key=value syntax?


There are several. I'm working on one:

http://ruby-talk.org/88419
___________________
John Long
www.wiseheartdesign.com




 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      12-26-2003

"Ron Coutts" <(E-Mail Removed)> schrieb im Newsbeitrag
news:000b01c3c99e$ee53f040$(E-Mail Removed) m...
> Is there a library class for handling common property files that have
> the key=value syntax? Basically all I need to do is read some
> properties from a properties file, perform succ! on some of them, and
> write the property file back to disk. There were a couple of threads
> about properties files earlier in December that mentioned use of
> Config.rb but I'm having trouble finding documentation for this library,
> if it is one. I'm using Ruby 1.8.0.


I made a posting some time ago, maybe that helps. The class can work with
nested names "foo.bar.baz='hello'":

class Config
def initialize
@values = {}
end

def method_missing(sym,*args)
s = sym.to_s.freeze

if s[-1] == ?=
# setter
@values[s] = args.size == 1 ? args[0] : args
else
# getter
@values[s] ||= self.class.new
end
end

def load(file)
instance_eval File.readlines(file, nil).shift
end

def self.load(file)
conf = self.new
conf.load file
conf
end
end

conf = Config.new

conf.load "conf.rc"
p conf

conf = Config.load "conf.rc"
p conf

Cheers

robert


 
Reply With Quote
 
Andre Nathan
Guest
Posts: n/a
 
      12-26-2003
On Fri, 2003-12-26 at 09:06, Robert Klemme wrote:
> def method_missing(sym,*args)
> s = sym.to_s.freeze


Is there a need to freeze s here? If I don't freeze it, I can do this:

> if s[-1] == ?=
> # setter


s.sub!(/=$/, '')

> @values[s] = args.size == 1 ? args[0] : args
> else


This, way, if the property file looks like

foo.name = 'Foo'

I can access the value with

conf = Config.load "conf.rc"
puts conf.values['foo'].values['id']

as opposed to

puts conf.values['foo'].values['id=']

Regards,
Andre



 
Reply With Quote
 
Andre Nathan
Guest
Posts: n/a
 
      12-26-2003
On Fri, 2003-12-26 at 09:45, Andre Nathan wrote:
> Is there a need to freeze s here? If I don't freeze it, I can do this:


Well, i could also do

key = s.sub(/$=/, '')
@values[key] = args.size == 1 ? args[0] : args

Anyway... is the freeze needed?

Andre



 
Reply With Quote
 
jrb3@eidogen.com
Guest
Posts: n/a
 
      12-30-2003
Hi all!

>> Is there a library class for handling common property files that have
>> the key=value syntax?


I have a simple one accessible through acceptor.tigris.org/.
Download the initial tarball, and grab acceptor/lib/runtimeProps.rb
for your work.

Joseph Beckenbach
lead XP tester, Eidogen Inc.


 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      01-10-2004

"Andre Nathan" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) .br...
> On Fri, 2003-12-26 at 09:06, Robert Klemme wrote:
> > def method_missing(sym,*args)
> > s = sym.to_s.freeze

>
> Is there a need to freeze s here?


unfrozen Strings are dup'ed when put into a hash. That's why I put the
freeze there. But the freeze should be done later, when it's clear whether
it's a setter or a getter.

> If I don't freeze it, I can do this:
>
> > if s[-1] == ?=
> > # setter

>
> s.sub!(/=$/, '')
>
> > @values[s] = args.size == 1 ? args[0] : args
> > else

>
> This, way, if the property file looks like
>
> foo.name = 'Foo'
>
> I can access the value with
>
> conf = Config.load "conf.rc"
> puts conf.values['foo'].values['id']
>
> as opposed to
>
> puts conf.values['foo'].values['id=']


No. The idea of the whole thing is to be able to do

puts conf.foo.name

Cheers

robert

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding to property of property of object collection TS ASP .Net 3 08-31-2006 12:57 PM
TableCell: BackColor Property But No BackGround Property? Nathan Sokalski ASP .Net 1 04-29-2006 10:09 PM
DataBinder.Eval for an object's property property... like Eval(Container.DataItem,"Version.Major") Eric Newton ASP .Net 3 04-04-2005 10:11 PM
Set CSS property equal to another CSS property? Noozer HTML 10 10-13-2004 09:20 PM
Is there a way to set the a CSS property to be explicitly the same as another CSS property? Joshua Beall HTML 1 12-10-2003 07:21 PM



Advertisments