windirs 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +35 -0
- data/lib/windirs.rb +126 -0
- data/spec/windirs_spec.rb +66 -0
- data/windirs.gemspec +13 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5ede397df9f93b22c6abf35efad482d3e8de646b
|
4
|
+
data.tar.gz: 548078b8a4861930c60b3706dbd620ca19b8a3ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0505406cf265dcec147cf39f1fced36ada1521faf799f507d091c197592476aafa67f6c6ddfd83c2d96a5ce35c71e271cb05e404a5e7566740884dc8a2db5263
|
7
|
+
data.tar.gz: 258965dfa43e982f8411bbe927033e1444c02e22c2d5651029f40819c09c8cc1ecc69e7b4d45381b16d94b488192200b1b055665e8dc7e036b3628619267de21
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
windirs
|
2
|
+
---------
|
3
|
+
A ruby gem to convert between Unix, Windows, and Cygwin paths.
|
4
|
+
|
5
|
+
Installation
|
6
|
+
---------
|
7
|
+
`gem install windirs`
|
8
|
+
|
9
|
+
or, if you want the latest and the greatest,
|
10
|
+
|
11
|
+
git clone https://github.com/windirs
|
12
|
+
cd windirs
|
13
|
+
rake install
|
14
|
+
|
15
|
+
(use `sudo` as necessary)
|
16
|
+
|
17
|
+
Runtime Requirements
|
18
|
+
---------
|
19
|
+
ruby
|
20
|
+
|
21
|
+
Build Requirements
|
22
|
+
---------
|
23
|
+
rake
|
24
|
+
|
25
|
+
Inspiration and History
|
26
|
+
---------
|
27
|
+
|
28
|
+
|
29
|
+
License
|
30
|
+
---------
|
31
|
+
© 2014 Noah Birnel
|
32
|
+
MIT license
|
33
|
+
|
34
|
+
[![Build Status](https://travis-ci.org/nbirnel/windirs.png?branch=master)](https://travis-ci.org/nbirnel/windirs)
|
35
|
+
[![Code Climate](https://codeclimate.com/github/nbirnel/windirs.png)](https://codeclimate.com/github/nbirnel/windirs)
|
data/lib/windirs.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
##
|
2
|
+
# Classes for representing directory paths in various formats.
|
3
|
+
|
4
|
+
module Windirs
|
5
|
+
|
6
|
+
##
|
7
|
+
# Represents a directory path, either absolute or relative.
|
8
|
+
#
|
9
|
+
# This Class is meant to be used when you are uncertain where your
|
10
|
+
# program will be running.
|
11
|
+
#
|
12
|
+
# For instance,
|
13
|
+
# if you want to make windows shortcuts with win32-shortcut
|
14
|
+
# http://rubygems.org/gems/win32-shortcut
|
15
|
+
# you will need a windows style path.
|
16
|
+
# But if you don't know the location until run-time,
|
17
|
+
# and you are uncertain if you are running in Cygwin or native Ruby,
|
18
|
+
# you could use:
|
19
|
+
# s.path = Windirs::Path.new(Dir.pwd).windows
|
20
|
+
#
|
21
|
+
# BUGS
|
22
|
+
# ----------------
|
23
|
+
# Does not dereference Cygwin mount points to Windows drives.
|
24
|
+
# This is arguably not a bug,
|
25
|
+
# but a feature not yet implemented.
|
26
|
+
#
|
27
|
+
# Ditto for dereferencing Windows network mounts to UNC paths.
|
28
|
+
#
|
29
|
+
|
30
|
+
|
31
|
+
class Path
|
32
|
+
|
33
|
+
##
|
34
|
+
# Create a new Path from +path+.
|
35
|
+
#
|
36
|
+
# > winpath = Windirs::Path.new 'C:\Users\noah\Desktop'
|
37
|
+
# > nixpath = Windirs::Path.new '/bin/ls'
|
38
|
+
# > cygpath = Windirs::Path.new '/cygdrive/c/Users/noah/Desktop'
|
39
|
+
#
|
40
|
+
# You probably don't need to know the rest of this:
|
41
|
+
# +cygdrive_prefix+ defaults to '/cygdrive/',
|
42
|
+
# and is used to extract drive letters from Cygwin-ish looking paths.
|
43
|
+
# If you know will not be using Cygwin paths,
|
44
|
+
# you may wish to assign this to ''.
|
45
|
+
# If your cygdrive path prefix is something else,
|
46
|
+
# you should assign this appropriately.
|
47
|
+
# See
|
48
|
+
# http://cygwin.com/cygwin-ug-net/using.html#cygdrive
|
49
|
+
# for details.
|
50
|
+
# Note that we are using a trailing slash,
|
51
|
+
# unlike the Cygwin documentation.
|
52
|
+
#
|
53
|
+
|
54
|
+
def initialize path, cygdrive_prefix = '/cygdrive/'
|
55
|
+
dirs = '(?<dirs>.*)$'
|
56
|
+
windrive = '((?<drive>[A-Z]):)'
|
57
|
+
cygdrive = "(#{cygdrive_prefix}(?<drive>[a-z]))"
|
58
|
+
drive = "(#{windrive}|#{cygdrive})?"
|
59
|
+
path_re = Regexp.new('^' + drive + dirs)
|
60
|
+
|
61
|
+
if path_re =~ path
|
62
|
+
m = Regexp.last_match
|
63
|
+
@drive = m[:drive]
|
64
|
+
@dirs = m[:dirs]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# Return a Cygwin style path String.
|
70
|
+
# See Windirs.Path.initialize documentation
|
71
|
+
# for more info on +cygdrive_prefix+.
|
72
|
+
#
|
73
|
+
# > winpath.cygwin
|
74
|
+
# => "/cygdrive/c/Users/noah/Desktop"
|
75
|
+
|
76
|
+
def cygwin cygdrive_prefix = '/cygdrive/'
|
77
|
+
fpath('/', cygdrive_prefix){|drive| "#{@drive.downcase}"}
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Return a *nix (Linux, Mac OS X, *BSD) style path String.
|
82
|
+
# +prefix+ will be used if a drive was detected in Path,
|
83
|
+
# but this is unlikely to be useful.
|
84
|
+
# You may want to assign it for certain Samba situations,
|
85
|
+
# but I have little opinion or knowledge on that.
|
86
|
+
#
|
87
|
+
# > winpath.nix
|
88
|
+
# => "/c/Users/noah/Desktop"
|
89
|
+
|
90
|
+
def nix prefix = '/'
|
91
|
+
fpath('/', prefix){|drive| "#{@drive.downcase}"}
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
# Return a Ruby on Windows style path String.
|
96
|
+
#
|
97
|
+
# > winpath.rubywin
|
98
|
+
# => "C:/Users/noah/Desktop"
|
99
|
+
|
100
|
+
def rubywin
|
101
|
+
fpath('/'){ |drive| "#{@drive.upcase}:"}
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Return a Windows style path String.
|
106
|
+
#
|
107
|
+
# > cygpath.windows
|
108
|
+
# => "C:\\Users\\noah\\Desktop"
|
109
|
+
# > puts cygpath.windows
|
110
|
+
# "C:\Users\noah\Desktop"
|
111
|
+
# => nil
|
112
|
+
|
113
|
+
def windows
|
114
|
+
fpath('\\'){ |drive| "#{@drive.upcase}:"}
|
115
|
+
end
|
116
|
+
|
117
|
+
private
|
118
|
+
|
119
|
+
def fpath del='/', prefix=''
|
120
|
+
drive = @drive ? "#{prefix}#{yield(@drive)}" : nil
|
121
|
+
"#{drive}#{@dirs}".gsub(/[\/\\\\]/, del)
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/../lib/windirs"
|
2
|
+
|
3
|
+
describe Windirs do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@relatives = {
|
7
|
+
:windows => '.\\somedir\\file',
|
8
|
+
:cygwin => './somedir/file',
|
9
|
+
:rubywin => './somedir/file',
|
10
|
+
:nix => './somedir/file',
|
11
|
+
}
|
12
|
+
@rpaths = Hash.new
|
13
|
+
@relatives.map{|k, v| @rpaths[k] = Windirs::Path.new(v)}
|
14
|
+
|
15
|
+
@drives = {
|
16
|
+
:cygwin => '/cygdrive/c/Users/joe/Desktop',
|
17
|
+
:windows => 'C:\Users\joe\Desktop',
|
18
|
+
:rubywin => 'C:/Users/joe/Desktop',
|
19
|
+
}
|
20
|
+
@dpaths = Hash.new
|
21
|
+
@drives.map{|k, v| @dpaths[k] = Windirs::Path.new(v)}
|
22
|
+
|
23
|
+
@uncs = {
|
24
|
+
:windows => '\\\\windomain\\somedir\\file',
|
25
|
+
:cygwin => '//windomain/somedir/file',
|
26
|
+
:rubywin => '//windomain/somedir/file',
|
27
|
+
:nix => '//windomain/somedir/file',
|
28
|
+
}
|
29
|
+
@upaths = Hash.new
|
30
|
+
@uncs.map{|k, v| @upaths[k] = Windirs::Path.new(v)}
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe Windirs::Path do
|
35
|
+
|
36
|
+
it 'converts any drive to any drive' do
|
37
|
+
@drives.keys.repeated_permutation(2).each do |from, to|
|
38
|
+
puts "converts from #{from} to #{to}"
|
39
|
+
@dpaths[from].method(to).call.should eq @drives[to]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'fakes a drive letter to *nix' do
|
44
|
+
@drives.keys.each do |from|
|
45
|
+
puts "fake drive letter from #{from} to *nix"
|
46
|
+
@dpaths[from].nix.should eq '/c/Users/joe/Desktop'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'converts any unc to any unc' do
|
51
|
+
@uncs.keys.repeated_permutation(2).each do |from, to|
|
52
|
+
puts "converts from #{from} to #{to}"
|
53
|
+
@upaths[from].method(to).call.should eq @uncs[to]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'converts relative paths' do
|
58
|
+
@relatives.keys.repeated_permutation(2).each do |from, to|
|
59
|
+
puts "converts from #{from} to #{to}"
|
60
|
+
@rpaths[from].method(to).call.should eq @relatives[to]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
data/windirs.gemspec
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'windirs'
|
3
|
+
s.version = '0.0.0'
|
4
|
+
s.date = '2014-03-21'
|
5
|
+
s.summary = "translate between Cygwin, Windows, and Unix file paths"
|
6
|
+
s.description = "#{s.summary}"
|
7
|
+
s.authors = ['Noah Birnel']
|
8
|
+
s.email = 'nbirnel@gmail.com'
|
9
|
+
s.homepage = 'http://github.com/nbirnel/windirs'
|
10
|
+
s.files = ['README.md', 'windirs.gemspec', 'lib/windirs.rb', 'spec/windirs_spec.rb']
|
11
|
+
s.has_rdoc = true
|
12
|
+
s.license = 'MIT'
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: windirs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Noah Birnel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: translate between Cygwin, Windows, and Unix file paths
|
14
|
+
email: nbirnel@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- README.md
|
20
|
+
- windirs.gemspec
|
21
|
+
- lib/windirs.rb
|
22
|
+
- spec/windirs_spec.rb
|
23
|
+
homepage: http://github.com/nbirnel/windirs
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 2.0.7
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: translate between Cygwin, Windows, and Unix file paths
|
47
|
+
test_files: []
|