From 45475bda0fee5d75d228a4e117c27dc8ad77f472 Mon Sep 17 00:00:00 2001 From: Dag Odenhall Date: Mon, 28 Apr 2008 16:47:38 +0200 Subject: [PATCH] Employ File.expand_path as appropriate Any path in amazing will now understand tilde-syntax, and the code doesn't need to handle relative paths directly. --- lib/amazing/cli.rb | 2 +- lib/amazing/proc_file.rb | 2 +- lib/amazing/widgets/file.rb | 2 +- lib/amazing/widgets/maildir.rb | 2 +- lib/amazing/widgets/raggle.rb | 8 ++++---- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/amazing/cli.rb b/lib/amazing/cli.rb index 69ebaa7..36aba69 100644 --- a/lib/amazing/cli.rb +++ b/lib/amazing/cli.rb @@ -92,7 +92,7 @@ module Amazing def load_scripts scripts = @options[:include] @config["include"].each do |script| - script = "#{File.dirname(@options[:config])}/#{script}" if script[0] != ?/ + script = File.expand_path(script, File.dirname(@options[:config])) scripts << script end if @options[:autoinclude] diff --git a/lib/amazing/proc_file.rb b/lib/amazing/proc_file.rb index 1392e02..b0ededf 100644 --- a/lib/amazing/proc_file.rb +++ b/lib/amazing/proc_file.rb @@ -12,7 +12,7 @@ module Amazing include Enumerable def self.parse_file(file) - file = "/proc/#{file}" if file[0] != ?/ + file = File.expand_path(file, "/proc") new(File.new(file)) end diff --git a/lib/amazing/widgets/file.rb b/lib/amazing/widgets/file.rb index 39abf58..77a2eac 100644 --- a/lib/amazing/widgets/file.rb +++ b/lib/amazing/widgets/file.rb @@ -19,7 +19,7 @@ module Amazing default { @last } init do - @file = "#{ENV["HOME"]}/#@file" if @file[0] != ?/ + @file = ::File.expand_path(@file, "~") @lines = ::File.readlines(@file).map {|line| line.chomp } @first = @lines.first || "" @last = @lines.last || "" diff --git a/lib/amazing/widgets/maildir.rb b/lib/amazing/widgets/maildir.rb index 4a4c7f1..6f2737f 100644 --- a/lib/amazing/widgets/maildir.rb +++ b/lib/amazing/widgets/maildir.rb @@ -14,7 +14,7 @@ module Amazing init do raise WidgetError, "No directories configured" unless @directories @directories.each do |glob| - glob = "#{ENV["HOME"]}/#{glob}" if glob[0] != ?/ + glob = ::File.expand_Path(glob, "~") @count += Dir["#{glob}/*"].size end end diff --git a/lib/amazing/widgets/raggle.rb b/lib/amazing/widgets/raggle.rb index 0e9c2c6..67873aa 100644 --- a/lib/amazing/widgets/raggle.rb +++ b/lib/amazing/widgets/raggle.rb @@ -8,15 +8,15 @@ module Amazing class Raggle < Widget description "Unread posts in raggle" dependency "pstore", "Ruby standard library" - option :feed_list_path, "Path to feeds list", ".raggle/feeds.yaml" - option :feed_cache_path, "Path to feeds cache", ".raggle/feed_cache.store" + option :feed_list_path, "Path to feeds list", "~/.raggle/feeds.yaml" + option :feed_cache_path, "Path to feeds cache", "~/.raggle/feed_cache.store" field :count, "Ammount of unread posts", 0 default { @count } init do - @feed_list_path = "#{ENV["HOME"]}/#@feed_list_path" if @feed_list_path[0] != ?/ + @feed_list_path = ::File.expand_path(@feed_list_path, "~") feeds = YAML.load_file(@feed_list_path) - @feed_cache_path = "#{ENV["HOME"]}/#{@feed_cache_path}" if @feed_cache_path[0] != ?/ + @feed_cache_path = ::File.expand_path(@feed_cache_path, "~") cache = PStore.new(@feed_cache_path) cache.transaction(false) do feeds.each do |feed| -- 2.11.4.GIT