Is there a "better" way to specify a default config file location than
this?
File.expand_path('~') + "/#{filename}"
···
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
Is there a "better" way to specify a default config file location than
this?
File.expand_path('~') + "/#{filename}"
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
Depending on the shell, '~' may not be defined. $HOME is a better choice generally.
Matt
On Sat, 18 Jun 2011, Chad Perrin wrote:
Is there a "better" way to specify a default config file location than
this?File.expand_path('~') + "/#{filename}"
Chad Perrin:
Is there a "better" way to specify
a default config file location than this?
File.expand_path('~') + "/#{filename}"
Depending on how ‘good’ you want to be with regards to
modern systems adhering to the FreeDesktop standard¹. ![]()
The last time I needed to take care of this (YAML ‘database’
with signatures for signore, a signature randomiser) I settled on
(ENV['XDG_DATA_HOME'] or File.expand_path '~/.local/share') + '/signore/signatures.yml'
– so for a config file I’d go with
(ENV['XDG_CONFIG_HOME'] or File.expand_path '~/.config') + "/#{appname}/#{configfilename}"
¹ XDG Base Directory Specification
— Piotr Szotkowski
--
We tried that One Encoding To Rule Them All in Java, and it was
a failure. We tried it again with a different encoding in Java 5,
and it was a failure. We tried it in .NET, and it was a failure. The
Python community is currently in the process of realizing it was a failure.
Five years of work on PHP 6 were completely destroyed because of this. (At
least they realized it *before* releasing it into the wild.)
[Jörg W Mittag, ruby-talk]
According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows. ![]()
I might simplify this just a tiny bit though:
File.expand_path("~/#{filename}")
-Jeremy
On 6/17/2011 14:45, Matthew K. Williams wrote:
On Sat, 18 Jun 2011, Chad Perrin wrote:
Is there a "better" way to specify a default config file location than
this?File.expand_path('~') + "/#{filename}"
Depending on the shell, '~' may not be defined. $HOME is a better
choice generally.
I take it you mean the above should be changed to this:
ENV['HOME'] + "/#{filename}"
Is that what you mean?
You make a good point about tilde expansion. Thank you.
On Sat, Jun 18, 2011 at 04:45:56AM +0900, Matthew K. Williams wrote:
On Sat, 18 Jun 2011, Chad Perrin wrote:
>
>Is there a "better" way to specify a default config file location than
>this?
>
> File.expand_path('~') + "/#{filename}"Depending on the shell, '~' may not be defined. $HOME is a better
choice generally.
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
That's for X Windows environments, like KDE or GNOME.
For all others, the FHS applies: FHS Referenced Specifications
In a nutshell: Configuration and user data go into ".#{appname}".
On Sat, Jun 18, 2011 at 10:26 PM, Piotr Szotkowski <chastell@chastell.net> wrote:
Depending on how ‘good’ you want to be with regards to
modern systems adhering to the FreeDesktop standard¹.The last time I needed to take care of this (YAML ‘database’
with signatures for signore, a signature randomiser) I settled on
--
Phillip Gawlowski
A method of solution is perfect if we can forsee from the start,
and even prove, that following that method we shall attain our aim.
-- Leibnitz
I use File.join for such situations due to separator differences. Is this
unnecessary for some reason?
Michael Edgar
adgar@carboni.ca
http://carboni.ca/
On Jun 17, 2011, at 3:49 PM, Jeremy Bopp wrote:
According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows.I might simplify this just a tiny bit though:
File.expand_path("~/#{filename}")
Thanks for that; I'll have to remember it!
Matt
On Sat, 18 Jun 2011, Jeremy Bopp wrote:
On 6/17/2011 14:45, Matthew K. Williams wrote:
On Sat, 18 Jun 2011, Chad Perrin wrote:
Is there a "better" way to specify a default config file location than
this?File.expand_path('~') + "/#{filename}"
Depending on the shell, '~' may not be defined. $HOME is a better
choice generally.According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows.
Do you know whether that's consistent across Ruby implementations (e.g,
Rubinius and JRuby)? I imagine it is for Rubinius, at least, given the
project's focus on API consistency. . . .
On Sat, Jun 18, 2011 at 04:49:24AM +0900, Jeremy Bopp wrote:
On 6/17/2011 14:45, Matthew K. Williams wrote:
> On Sat, 18 Jun 2011, Chad Perrin wrote:
>>
>> Is there a "better" way to specify a default config file location than
>> this?
>>
>> File.expand_path('~') + "/#{filename}"
>
> Depending on the shell, '~' may not be defined. $HOME is a better
> choice generally.According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows.
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
As people have pointed out, File.expand_path probably works.
I do find this a bit cleaner, though:
File.join(ENV['HOME'], filename)
On Friday, June 17, 2011 02:53:23 PM Chad Perrin wrote:
On Sat, Jun 18, 2011 at 04:45:56AM +0900, Matthew K. Williams wrote:
> On Sat, 18 Jun 2011, Chad Perrin wrote:
> >Is there a "better" way to specify a default config file location than
> >this?
> >
> > File.expand_path('~') + "/#{filename}"
>
> Depending on the shell, '~' may not be defined. $HOME is a better
> choice generally.I take it you mean the above should be changed to this:
ENV['HOME'] + "/#{filename}"
Is that what you mean?
> Depending on how ‘good’ you want to be with regards to
> modern systems adhering to the FreeDesktop standard¹.> The last time I needed to take care of this (YAML ‘database’
> with signatures for signore, a signature randomiser) I settled onThat's for X Windows environments, like KDE or GNOME.
The base directory standard does not limit it's use to X windows
environments. That's just how it originated. Any app can make use of
it.
One of the aims of freedesktop.org is "Integrate desktop-specific
standards into broader standards efforts".
For all others, the FHS applies:http://refspecs.linuxfoundation.org/fhs.shtml
In a nutshell: Configuration and user data go into ".#{appname}".
The XDG base directory standard has a few advantages --first and
foremost (IMHO) it helps unclutter the home directory.
On Jun 18, 5:49 pm, Phillip Gawlowski <cmdjackr...@googlemail.com> wrote:
On Sat, Jun 18, 2011 at 10:26 PM, Piotr Szotkowski > > <chast...@chastell.net> wrote:
It works on jruby (I checked 1.6.0)
Matt
On Sat, 18 Jun 2011, Chad Perrin wrote:
On Sat, Jun 18, 2011 at 04:49:24AM +0900, Jeremy Bopp wrote:
On 6/17/2011 14:45, Matthew K. Williams wrote:
On Sat, 18 Jun 2011, Chad Perrin wrote:
Is there a "better" way to specify a default config file location than
this?File.expand_path('~') + "/#{filename}"
Depending on the shell, '~' may not be defined. $HOME is a better
choice generally.According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows.Do you know whether that's consistent across Ruby implementations (e.g,
Rubinius and JRuby)? I imagine it is for Rubinius, at least, given the
project's focus on API consistency. . . .
I use File.join also -- well, actually, I look for opportunities to use the
Pathname library instead. But on modern Windows, forward slashes work, too.
I had to explain this to people writing a Java program in which they hardcoded
backslashes. Java's File library is a lot like Ruby's Pathname library, and
you have to create a File object eventually anyway, but even if you ignore all
that, forward slashes work fine!
On Friday, June 17, 2011 02:52:53 PM Michael Edgar wrote:
On Jun 17, 2011, at 3:49 PM, Jeremy Bopp wrote:
> According to the documentation for File.expand_path, all that is
> required is that $HOME is set correctly. It doesn't apparently use the
> shell to figure this out. Chad's method even works on Windows.
>
> I might simplify this just a tiny bit though:
>
> File.expand_path("~/#{filename}")I use File.join for such situations due to separator differences. Is this
unnecessary for some reason?
Ruby always uses '/' with File.join wherever I've tested it, even on
Windows. Fortunately, Windows will also accept that separator, and Ruby
on Windows will work with either just like other Windows applications.
However, it's possible that one day Ruby will be ported to an OS that
doesn't support it. Using File.join or something equivalent (see below)
should pretty much guarantee that your script won't trip over that problem.
I actually had the very problem you're concerned about in a large Perl
framework years ago that had to run on Windows, Unix, and MacOS 9. For
those too young to remember, MacOS 9 used ':' for the file separator
character, among other path-related differences. Since then, I tend to
use methods like File.join for long-lived or important projects.
The only real problem at the moment in Ruby is displaying Ruby-style
paths to a Windows user. Since they're used to seeing the '\'
separator, many may not understand the '/' or at least be uncomfortable
using it. In such cases where you need to show a path that was
generated internally to a user, it might be a good idea to use a
platform-aware filter to make the path more presentable/palatable.
BTW, another way to handle this separator issue is to use the Pathname
class from the pathname library for all your paths:
require 'pathname'
puts (Pathname.new('~') + filename).expand_path
-Jeremy
On 6/17/2011 14:52, Michael Edgar wrote:
On Jun 17, 2011, at 3:49 PM, Jeremy Bopp wrote:
According to the documentation for File.expand_path, all that is
required is that $HOME is set correctly. It doesn't apparently use the
shell to figure this out. Chad's method even works on Windows.I might simplify this just a tiny bit though:
File.expand_path("~/#{filename}")
I use File.join for such situations due to separator differences. Is this
unnecessary for some reason?
> > >Is there a "better" way to specify a default config file location than
> > >this?
> > >
> > > File.expand_path('~') + "/#{filename}"
> >
> > Depending on the shell, '~' may not be defined. $HOME is a better
> > choice generally.
>
> I take it you mean the above should be changed to this:
>
> ENV['HOME'] + "/#{filename}"
>
> Is that what you mean?As people have pointed out, File.expand_path probably works.
Yeah -- I started composing this before the other emails started showing
up in my inbox.
I do find this a bit cleaner, though:
File.join(ENV['HOME'], filename)
As do I, now that I've had time to think about it.
On Sat, Jun 18, 2011 at 07:29:58AM +0900, David Masover wrote:
On Friday, June 17, 2011 02:53:23 PM Chad Perrin wrote:
> On Sat, Jun 18, 2011 at 04:45:56AM +0900, Matthew K. Williams wrote:
> > On Sat, 18 Jun 2011, Chad Perrin wrote:
--
Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ]
JRuby has a focus on API consistency as well.
- Charlie
On Fri, Jun 17, 2011 at 2:56 PM, Chad Perrin <code@apotheon.net> wrote:
Do you know whether that's consistent across Ruby implementations (e.g,
Rubinius and JRuby)? I imagine it is for Rubinius, at least, given the
project's focus on API consistency. . . .