Permalink
Browse files

add dir_pa

  • Loading branch information...
2 parents 8c88a8e + 6d91dd3 commit 4de028bb78374b9ff90a83afef680ea1ba81e0e1 @gutenye committed Mar 15, 2011
Showing with 26 additions and 12 deletions.
  1. +7 −2 Rakefile
  2. +1 −0 TODO
  3. +11 −8 lib/tagen/core/pa.rb
  4. +7 −2 lib/tagen/core/pa/path.rb
View
@@ -6,11 +6,16 @@ task :release do
sh "rm *.gem"
end
-desc "testing the library"
-task :test do
+desc "autotest with watchr"
+task :autotest do
sh "watchr tagen.watchr"
end
+desc "testing the libraray"
+task :test do
+ sh "rspec --color spec"
+end
+
def sh cmd
puts cmd
system cmd
View
1 TODO
@@ -0,0 +1 @@
+* Pa support home path. e.g. '~/.vimrc'
View
@@ -61,13 +61,6 @@ class Pa
attr_accessor :path
attr_reader :absolute, :dir, :base, :name, :ext, :fext
- alias p path
- alias a absolute
- alias d dir
- alias b base
- alias n name
- alias e ext
- alias fe fext
# @param [String,Pa,Pathname] path
# @api also used by replace
@@ -89,13 +82,23 @@ def initialize path
@fext = @ext.empty? ? "" : "."+@ext
end
+ alias p path
+ alias a absolute
+ alias d dir
+ alias b base
+ alias n name
+ alias e ext
+ alias fe fext
+
+ def absolute_pa() Pa(absolute) end
+ def dir_pa() Pa(dir) end
+
# @param [String,Pa,Pathname]
# @return [Pa] the same Pa object
def replace path
initialize path
end
-
# add string to path
#
# @example
@@ -124,13 +124,17 @@ def join *paths
File.join(*paths)
end
+ alias + join
# get parent path
#
# @param [String,Pa] path
+ # @param [Fixnum] n up level
# @return [String]
- def parent path
- join(get(path), "..")
+ def parent path, n=1
+ path = join(get(path), ([".."]*n).join('/'))
+ path2 = realpath(path)
+ path2 ? path2 : path
end
# link
@@ -195,6 +199,7 @@ def dangling? path
end
end # def dsymlink?
+ def realpath(path) File.realpath(get(path)) end
end
end

0 comments on commit 4de028b

Please sign in to comment.