fspath 0.0.3-darwin → 0.1.0-darwin

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -2,6 +2,84 @@
2
2
 
3
3
  Better than Pathname
4
4
 
5
+ == Synopsis
6
+
7
+ User dir:
8
+
9
+ FSPath.~
10
+
11
+ Other user dir:
12
+
13
+ FSPath.~('other')
14
+
15
+ Common dir for paths:
16
+
17
+ FSPath.common_dir('/a/b/c/d/e/f', '/a/b/c/1/hello', '/a/b/c/2/world') # => FSPath('/a/b/c')
18
+
19
+ Join paths:
20
+
21
+ FSPath('a') / 'b' / 'c' # => FSPath('a/b/c')
22
+
23
+ Write data:
24
+
25
+ FSPath('a').write('data')
26
+
27
+ Append data:
28
+
29
+ FSPath('a').append('data')
30
+
31
+ Escape glob:
32
+
33
+ FSPath('trash?/stuff [a,b,c]').escape_glob # => FSPath('trash\?/stuff \[a,b,c\]')
34
+
35
+ Expand glob:
36
+
37
+ FSPath('trash').glob('**', '*')
38
+
39
+ Ascendants:
40
+
41
+ FSPath('a/b/c').ascend # => [FSPath('a/b/c'), FSPath('a/b'), FSPath('a')]
42
+
43
+ Descendants:
44
+
45
+ FSPath('a/b/c').descend # => [FSPath('a'), FSPath('a/b'), FSPath('a/b/c')]
46
+
47
+ Path parts:
48
+
49
+ FSPath('/a/b/c').parts # => ['/', 'a', 'b', 'c']
50
+
51
+ === Extended attributes (using xattr gem)
52
+
53
+ Get extended attribute:
54
+
55
+ FSPath('/a/b/c').xattr['com.macromates.caret']
56
+
57
+ Set extended attribute:
58
+
59
+ FSPath('/a/b/c').xattr['good'] = 'bad'
60
+
61
+ === OS X stuff
62
+
63
+ Move to trash:
64
+
65
+ FSPath('a').move_to_trash
66
+
67
+ Get finder label (one of :none, :orange, :red, :yellow, :blue, :purple, :green and :gray):
68
+
69
+ FSPath('a').finder_label
70
+
71
+ Set finder label (:grey is same as :gray, nil or false as :none):
72
+
73
+ FSPath('a').finder_label = :red
74
+
75
+ Get spotlight comment:
76
+
77
+ FSPath('a').spotlight_comment
78
+
79
+ Set spotlight comment:
80
+
81
+ FSPath('a').spotlight_comment = 'a file'
82
+
5
83
  == Copyright
6
84
 
7
85
  Copyright (c) 2010 Boba Fat. See LICENSE.txt for further details.
data/Rakefile CHANGED
@@ -1,52 +1,43 @@
1
- require 'bundler'
2
- begin
3
- Bundler.setup(:default, :development)
4
- rescue Bundler::BundlerError => e
5
- $stderr.puts e.message
6
- $stderr.puts "Run `bundle install` to install missing gems"
7
- exit e.status_code
8
- end
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'jeweler'
4
+ require 'rake/gem_ghost_task'
5
+ require 'rspec/core'
6
+ require 'rspec/core/rake_task'
9
7
 
10
8
  name = 'fspath'
11
- summary = 'Better than Pathname'
12
9
 
13
- require 'jeweler'
14
10
  [nil, 'darwin'].each do |platform|
15
11
  spec = Gem::Specification.new do |gem|
16
12
  gem.name = name
17
- gem.homepage = "http://github.com/toy/fspath"
18
- gem.summary = summary
19
- gem.authors = ["Boba Fat"]
13
+ gem.summary = %Q{Better than Pathname}
14
+ gem.homepage = "http://github.com/toy/#{name}"
15
+ gem.license = 'MIT'
16
+ gem.authors = ['Boba Fat']
20
17
  gem.platform = platform
18
+ gem.add_dependency 'xattr'
21
19
  if platform == 'darwin'
22
20
  gem.add_dependency 'rb-appscript'
23
21
  end
22
+ gem.add_development_dependency 'jeweler', '~> 1.5.1'
23
+ gem.add_development_dependency 'rake-gem-ghost'
24
+ gem.add_development_dependency 'rspec'
24
25
  end
25
26
  Jeweler::RubygemsDotOrgTasks.new do |rubygems_tasks|
26
27
  rubygems_tasks.jeweler = Jeweler::Tasks.new(spec).jeweler
27
28
  end
29
+ Rake::GemGhostTask.new
28
30
  end
29
31
 
30
- desc "Replace system gem with symlink to this folder"
31
- task 'ghost' do
32
- gem_path = Gem.searcher.find(name).full_gem_path
33
- current_path = File.expand_path('.')
34
- system('rm', '-r', gem_path)
35
- system('ln', '-s', current_path, gem_path)
36
- end
37
-
38
- require 'rspec/core'
39
- require 'rspec/core/rake_task'
40
32
  RSpec::Core::RakeTask.new(:spec) do |spec|
41
33
  spec.rspec_opts = ['--colour --format progress']
42
- spec.pattern = FileList['spec/**/*_spec.rb']
34
+ spec.pattern = 'spec/**/*_spec.rb'
43
35
  end
44
36
 
45
37
  RSpec::Core::RakeTask.new(:rcov) do |spec|
46
38
  spec.rspec_opts = ['--colour --format progress']
47
39
  spec.pattern = 'spec/**/*_spec.rb'
48
40
  spec.rcov = true
49
- spec.rcov_opts = ['--exclude', 'spec']
50
41
  end
51
42
 
52
43
  task :spec_with_rcov_and_open => :rcov do
data/TODO ADDED
@@ -0,0 +1,40 @@
1
+ class Pathname
2
+ def non_existing
3
+ dir = dirname
4
+ ext = extname
5
+ name = basename(ext)
6
+ postfix = nil
7
+ while (path = dir + "#{name}#{postfix}#{ext}").exist?
8
+ postfix = postfix ? postfix.succ : '-a'
9
+ end
10
+ path
11
+ # begin
12
+ # FSPath('abc').open(Fcntl::O_WRONLY | Fcntl::O_CREAT | Fcntl::O_EXCL) do |f|
13
+ # end
14
+ # rescue => e
15
+ # p e
16
+ # end
17
+
18
+ end
19
+
20
+ def lock(options = {}, &block)
21
+ File.lock(@path, options, &block)
22
+ # class File
23
+ # def self.lock(path, options = {})
24
+ # if lock = File.open(path, options[:mode] || 'r')
25
+ # begin
26
+ # if lock.flock(options[:no_block] ? (File::LOCK_EX | File::LOCK_NB) : (File::LOCK_EX))
27
+ # yield
28
+ # end
29
+ # ensure
30
+ # lock.flock(File::LOCK_UN)
31
+ # lock.close
32
+ # end
33
+ # end
34
+ # end
35
+ # end
36
+ # Fcntl::O_RDONLY | Fcntl::O_CREAT
37
+ # Fcntl::O_SHLOCK
38
+ # Fcntl::O_EXLOCK
39
+ end
40
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.1.0
data/fspath.gemspec CHANGED
@@ -5,33 +5,40 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fspath}
8
- s.version = "0.0.3"
8
+ s.version = "0.1.0"
9
9
  s.platform = %q{darwin}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Boba Fat"]
13
- s.date = %q{2010-12-12}
13
+ s.date = %q{2010-12-14}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE.txt",
16
- "README.rdoc"
16
+ "README.rdoc",
17
+ "TODO"
17
18
  ]
18
19
  s.files = [
19
- "Gemfile",
20
- "Gemfile.lock",
21
20
  "LICENSE.txt",
22
21
  "README.rdoc",
23
22
  "Rakefile",
23
+ "TODO",
24
24
  "VERSION",
25
25
  "fspath.gemspec",
26
26
  "lib/fspath.rb",
27
+ "lib/fspath/darwin.rb",
28
+ "lib/fspath/xattr.rb",
29
+ "spec/fspath/darwin_spec.rb",
30
+ "spec/fspath/xattr_spec.rb",
27
31
  "spec/fspath_spec.rb",
28
32
  "spec/spec_helper.rb"
29
33
  ]
30
34
  s.homepage = %q{http://github.com/toy/fspath}
35
+ s.licenses = ["MIT"]
31
36
  s.require_paths = ["lib"]
32
37
  s.rubygems_version = %q{1.3.7}
33
38
  s.summary = %q{Better than Pathname}
34
39
  s.test_files = [
40
+ "spec/fspath/darwin_spec.rb",
41
+ "spec/fspath/xattr_spec.rb",
35
42
  "spec/fspath_spec.rb",
36
43
  "spec/spec_helper.rb"
37
44
  ]
@@ -41,24 +48,24 @@ Gem::Specification.new do |s|
41
48
  s.specification_version = 3
42
49
 
43
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
51
+ s.add_runtime_dependency(%q<xattr>, [">= 0"])
44
52
  s.add_runtime_dependency(%q<rb-appscript>, [">= 0"])
45
- s.add_development_dependency(%q<rspec>, ["~> 2.1.0"])
46
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
47
53
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"])
48
- s.add_development_dependency(%q<rcov>, [">= 0"])
54
+ s.add_development_dependency(%q<rake-gem-ghost>, [">= 0"])
55
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
56
  else
57
+ s.add_dependency(%q<xattr>, [">= 0"])
50
58
  s.add_dependency(%q<rb-appscript>, [">= 0"])
51
- s.add_dependency(%q<rspec>, ["~> 2.1.0"])
52
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
59
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
54
- s.add_dependency(%q<rcov>, [">= 0"])
60
+ s.add_dependency(%q<rake-gem-ghost>, [">= 0"])
61
+ s.add_dependency(%q<rspec>, [">= 0"])
55
62
  end
56
63
  else
64
+ s.add_dependency(%q<xattr>, [">= 0"])
57
65
  s.add_dependency(%q<rb-appscript>, [">= 0"])
58
- s.add_dependency(%q<rspec>, ["~> 2.1.0"])
59
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
60
66
  s.add_dependency(%q<jeweler>, ["~> 1.5.1"])
61
- s.add_dependency(%q<rcov>, [">= 0"])
67
+ s.add_dependency(%q<rake-gem-ghost>, [">= 0"])
68
+ s.add_dependency(%q<rspec>, [">= 0"])
62
69
  end
63
70
  end
64
71
 
@@ -0,0 +1,52 @@
1
+ require 'appscript'
2
+
3
+ class FSPath < Pathname
4
+ # Move to trash using finder
5
+ def move_to_trash
6
+ mac_finder_alias.delete
7
+ end
8
+
9
+ FINDER_LABEL_COLORS = [:none, :orange, :red, :yellow, :blue, :purple, :green, :gray].freeze
10
+ FINDER_LABEL_COLOR_ALIASES = {:grey => :gray}.freeze
11
+ # Get finder label (one of :none, :orange, :red, :yellow, :blue, :purple, :green and :gray)
12
+ def finder_label
13
+ FINDER_LABEL_COLORS[mac_finder_alias.label_index.get]
14
+ end
15
+ # Set finder label (:grey is same as :gray, nil or false as :none)
16
+ def finder_label=(color)
17
+ color = FINDER_LABEL_COLOR_ALIASES[color] || color || :none
18
+ index = FINDER_LABEL_COLORS.index(color)
19
+ raise "Unknown label #{color.inspect}" unless index
20
+ mac_finder_alias.label_index.set(index)
21
+ end
22
+
23
+ # Get spotlight comment
24
+ def spotlight_comment
25
+ mac_finder_alias.comment.get
26
+ end
27
+
28
+ # Set spotlight comment
29
+ def spotlight_comment=(comment)
30
+ mac_finder_alias.comment.set(comment.to_s)
31
+ end
32
+
33
+ # MacTypes::Alias for path
34
+ def mac_alias
35
+ MacTypes::Alias.path(@path)
36
+ end
37
+
38
+ # MacTypes::FileURL for path
39
+ def mac_file_url
40
+ MacTypes::FileURL.path(@path)
41
+ end
42
+
43
+ # Finder item for path through mac_alias
44
+ def mac_finder_alias
45
+ Appscript.app('Finder').items[mac_alias]
46
+ end
47
+
48
+ # Finder item for path through mac_alias
49
+ def mac_finder_file_url
50
+ Appscript.app('Finder').items[mac_file_url]
51
+ end
52
+ end
@@ -0,0 +1,23 @@
1
+ require 'xattr'
2
+
3
+ Xattr.class_eval do
4
+ # Accept follow_symlinks as second attribute
5
+ def initialize(path, follow_symlinks = true)
6
+ @path = path
7
+ @follow_symlinks = follow_symlinks
8
+ end
9
+ alias_method :[], :get
10
+ alias_method :[]=, :set
11
+ end
12
+
13
+ class FSPath < Pathname
14
+ # Xattr instance for path
15
+ def xattr
16
+ Xattr.new(@path)
17
+ end
18
+
19
+ # Xattr instance for path which doesn't follow symlinks
20
+ def lxattr
21
+ Xattr.new(@path, false)
22
+ end
23
+ end
data/lib/fspath.rb CHANGED
@@ -7,6 +7,13 @@ class FSPath < Pathname
7
7
  def ~(name = nil)
8
8
  new(File.expand_path("~#{name}"))
9
9
  end
10
+
11
+ # Returns common dir for paths
12
+ def common_dir(*paths)
13
+ paths.map do |path|
14
+ new(path).dirname.ascend
15
+ end.inject(:&).first
16
+ end
10
17
  end
11
18
 
12
19
  # Join paths using File.join
@@ -48,7 +55,34 @@ class FSPath < Pathname
48
55
  self.class.glob(*args, &block)
49
56
  end
50
57
 
51
- if RUBY_PLATFORM.downcase.include?('darwin')
58
+ # Iterates over and yields each element in the given path in ascending order
59
+ def ascend(&block)
60
+ ascendants = []
61
+ path = @path
62
+ ascendants << self
63
+ while r = chop_basename(path)
64
+ path, name = r
65
+ break if path.empty?
66
+ ascendants << self.class.new(del_trailing_separator(path))
67
+ end
68
+ if block
69
+ ascendants.each(&block)
70
+ end
71
+ ascendants
72
+ end
73
+
74
+ # Iterates over and yields each element in the given path in descending order
75
+ def descend(&block)
76
+ descendants = ascend.reverse
77
+ if block
78
+ descendants.each(&block)
79
+ end
80
+ descendants
81
+ end
82
+
83
+ # Returns path parts
84
+ def parts(&block)
85
+ split_names(@path).flatten
52
86
  end
53
87
  end
54
88
 
@@ -59,3 +93,8 @@ module Kernel
59
93
  end
60
94
  private :Pathname
61
95
  end
96
+
97
+ require 'fspath/xattr'
98
+ if RUBY_PLATFORM.downcase.include?('darwin')
99
+ require 'fspath/darwin'
100
+ end
@@ -0,0 +1,174 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe FSPath do
4
+ if RUBY_PLATFORM.downcase.include?('darwin')
5
+ describe "mac related" do
6
+ describe "move_to_trash" do
7
+ it "should call delete on mac_finder_alias" do
8
+ @path = FSPath('to_delete')
9
+ @finder_alias = mock(:finder_alias)
10
+
11
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
12
+ @finder_alias.should_receive(:delete)
13
+
14
+ @path.move_to_trash
15
+ end
16
+ end
17
+
18
+ describe "finder labels" do
19
+ describe "getting" do
20
+ it "should call label_index.get on mac_finder_alias" do
21
+ @path = FSPath('to_label')
22
+ @finder_alias = mock(:finder_alias)
23
+ @label_index = mock(:label_index)
24
+
25
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
26
+ @finder_alias.should_receive(:label_index).and_return(@label_index)
27
+ @label_index.should_receive(:get).and_return(0)
28
+
29
+ @path.finder_label
30
+ end
31
+
32
+ it "should return apporitate label" do
33
+ @path = FSPath('to_label')
34
+ @finder_alias = mock(:finder_alias)
35
+ @label_index = mock(:label_index)
36
+
37
+ @path.stub!(:mac_finder_alias).and_return(@finder_alias)
38
+ @finder_alias.stub!(:label_index).and_return(@label_index)
39
+
40
+ FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
41
+ @label_index.stub!(:get).and_return(index)
42
+ @path.finder_label.should == label
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "setting" do
48
+ it "should call label_index.set on mac_finder_alias" do
49
+ @path = FSPath('to_label')
50
+ @finder_alias = mock(:finder_alias)
51
+ @label_index = mock(:label_index)
52
+
53
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
54
+ @finder_alias.should_receive(:label_index).and_return(@label_index)
55
+ @label_index.should_receive(:set)
56
+
57
+ @path.finder_label = nil
58
+ end
59
+
60
+ describe "index" do
61
+ before do
62
+ @path = FSPath('to_label')
63
+ @finder_alias = mock(:finder_alias)
64
+ @label_index = mock(:label_index)
65
+
66
+ @path.stub!(:mac_finder_alias).and_return(@finder_alias)
67
+ @finder_alias.stub!(:label_index).and_return(@label_index)
68
+ end
69
+
70
+ it "should call label_index.set with apporitate index" do
71
+ FSPath::FINDER_LABEL_COLORS.each_with_index do |label, index|
72
+ @label_index.should_receive(:set).with(index).ordered
73
+ @path.finder_label = label
74
+ end
75
+ end
76
+
77
+ it "should accept aliases" do
78
+ FSPath::FINDER_LABEL_COLOR_ALIASES.each do |label_alias, label|
79
+ index = FSPath::FINDER_LABEL_COLORS.index(label)
80
+ @label_index.should_receive(:set).with(index).ordered
81
+ @path.finder_label = label_alias
82
+ end
83
+ end
84
+
85
+ it "should set to none when called with nil or false" do
86
+ [nil, false].each do |label|
87
+ @label_index.should_receive(:set).with(0).ordered
88
+ @path.finder_label = label
89
+ end
90
+ end
91
+
92
+ it "should raise when called with something else" do
93
+ [true, :shitty, 'hello'].each do |label|
94
+ proc do
95
+ @path.finder_label = label
96
+ end.should raise_error("Unknown label #{label.inspect}")
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "spotlight comments" do
104
+ describe "getting" do
105
+ it "should call comment.get on mac_finder_alias" do
106
+ @path = FSPath(__FILE__)
107
+ @finder_alias = mock(:finder_alias)
108
+ @comment = mock(:comment)
109
+ @comment_text = mock(:comment_text)
110
+
111
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
112
+ @finder_alias.should_receive(:comment).and_return(@comment)
113
+ @comment.should_receive(:get).and_return(@comment_text)
114
+
115
+ @path.spotlight_comment.should == @comment_text
116
+ end
117
+ end
118
+
119
+ describe "setting" do
120
+ it "should call comment.set on mac_finder_alias" do
121
+ @path = FSPath(__FILE__)
122
+ @finder_alias = mock(:finder_alias)
123
+ @comment = mock(:comment)
124
+ @comment_text = mock(:comment_text)
125
+
126
+ @path.should_receive(:mac_finder_alias).and_return(@finder_alias)
127
+ @finder_alias.should_receive(:comment).and_return(@comment)
128
+ @comment.should_receive(:set).with(@comment_text.to_s)
129
+
130
+ @path.spotlight_comment = @comment_text
131
+ end
132
+ end
133
+ end
134
+
135
+ describe "appscript objects" do
136
+ before do
137
+ @file_path = File.expand_path(__FILE__)
138
+ end
139
+
140
+ describe "mac_alias" do
141
+ it "should return instance of MacTypes::Alias" do
142
+ FSPath(@file_path).mac_alias.should be_kind_of(MacTypes::Alias)
143
+ end
144
+
145
+ it "should point to same path" do
146
+ FSPath(@file_path).mac_alias.path.should == @file_path
147
+ end
148
+ end
149
+
150
+ describe "mac_file_url" do
151
+ it "should return instance of MacTypes::FileURL" do
152
+ FSPath(@file_path).mac_file_url.should be_kind_of(MacTypes::FileURL)
153
+ end
154
+
155
+ it "should point to same path" do
156
+ FSPath(@file_path).mac_file_url.path.should == @file_path
157
+ end
158
+ end
159
+
160
+ describe "mac_finder_alias" do
161
+ it "should return same ref" do
162
+ FSPath(@file_path).mac_finder_alias.should == Appscript.app('Finder').items[FSPath(@file_path).mac_alias]
163
+ end
164
+ end
165
+
166
+ describe "mac_finder_file_url" do
167
+ it "should return same ref" do
168
+ FSPath(@file_path).mac_finder_file_url.should == Appscript.app('Finder').items[FSPath(@file_path).mac_file_url]
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
174
+ end
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Xattr do
4
+ describe "new" do
5
+ it "should accept follow_symlinks as second attribute" do
6
+ Xattr.new('a', true).follow_symlinks.should == true
7
+ Xattr.new('a', false).follow_symlinks.should == false
8
+ end
9
+
10
+ it "should alias get/set as []" do
11
+ Xattr.instance_method(:[]).should == Xattr.instance_method(:get)
12
+ Xattr.instance_method(:[]=).should == Xattr.instance_method(:set)
13
+ end
14
+ end
15
+ end
16
+
17
+ describe FSPath do
18
+ before do
19
+ @file_path = 'with_xattr'
20
+ end
21
+
22
+ describe "xattr" do
23
+ before do
24
+ @xattr = FSPath(@file_path).xattr
25
+ end
26
+
27
+ it "should return instance of Xattr" do
28
+ @xattr.should be_kind_of(Xattr)
29
+ end
30
+
31
+ it "should follow_symlinks" do
32
+ @xattr.follow_symlinks.should be_true
33
+ end
34
+
35
+ it "should point to same path" do
36
+ @xattr.instance_variable_get(:@path).should == @file_path
37
+ end
38
+ end
39
+
40
+ describe "lxattr" do
41
+ before do
42
+ @lxattr = FSPath(@file_path).lxattr
43
+ end
44
+
45
+ it "should return instance of Xattr" do
46
+ @lxattr.should be_kind_of(Xattr)
47
+ end
48
+
49
+ it "should not follow_symlinks" do
50
+ @lxattr.follow_symlinks.should be_false
51
+ end
52
+
53
+ it "should point to same path" do
54
+ @lxattr.instance_variable_get(:@path).should == @file_path
55
+ end
56
+ end
57
+ end
data/spec/fspath_spec.rb CHANGED
@@ -19,6 +19,20 @@ describe FSPath do
19
19
  end
20
20
  end
21
21
 
22
+ describe "common_dir" do
23
+ it "should return dirname if called with one path" do
24
+ FSPath.common_dir('/a/b/c').should == FSPath('/a/b')
25
+ end
26
+
27
+ it "should return common path if called with mulpitle paths" do
28
+ FSPath.common_dir('/a/b/c/d/e', '/a/b/c/d/f', '/a/b/c/z').should == FSPath('/a/b/c')
29
+ end
30
+
31
+ it "should return nil if there is no common path" do
32
+ FSPath.common_dir('../a', './b').should be_nil
33
+ end
34
+ end
35
+
22
36
  describe "/" do
23
37
  it "should join path with string" do
24
38
  (FSPath('a') / 'b').should == FSPath('a/b')
@@ -101,4 +115,50 @@ describe FSPath do
101
115
  FSPath('a/b/c').glob('**', '*', @flags)
102
116
  end
103
117
  end
118
+
119
+ describe "path parts" do
120
+ describe "ascend" do
121
+ before do
122
+ @path = FSPath('/a/b/c')
123
+ @ascendants = %w[/a/b/c /a/b /a /].map(&method(:FSPath))
124
+ end
125
+
126
+ it "should return list of ascendants" do
127
+ @path.ascend.should == @ascendants
128
+ end
129
+
130
+ it "should yield and return list of ascendants if called with block" do
131
+ ascendants = []
132
+ @path.ascend do |path|
133
+ ascendants << path
134
+ end.should == @ascendants
135
+ ascendants.should == @ascendants
136
+ end
137
+ end
138
+
139
+ describe "descend" do
140
+ before do
141
+ @path = FSPath('/a/b/c')
142
+ @descendants = %w[/ /a /a/b /a/b/c].map(&method(:FSPath))
143
+ end
144
+
145
+ it "should return list of descendants" do
146
+ @path.descend.should == @descendants
147
+ end
148
+
149
+ it "should yield and return list of descendants if called with block" do
150
+ descendants = []
151
+ @path.descend do |path|
152
+ descendants << path
153
+ end.should == @descendants
154
+ descendants.should == @descendants
155
+ end
156
+ end
157
+
158
+ describe "parts" do
159
+ it "should return path parts as strings" do
160
+ FSPath('/a/b/c').parts.should == %w[/ a b c]
161
+ end
162
+ end
163
+ end
104
164
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fspath
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 3
10
- version: 0.0.3
10
+ version: 0.1.0
11
11
  platform: darwin
12
12
  authors:
13
13
  - Boba Fat
@@ -15,12 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-12-12 00:00:00 +03:00
18
+ date: 2010-12-14 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: xattr
22
23
  prerelease: false
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ requirement: &id001 !ruby/object:Gem::Requirement
24
25
  none: false
25
26
  requirements:
26
27
  - - ">="
@@ -29,60 +30,56 @@ dependencies:
29
30
  segments:
30
31
  - 0
31
32
  version: "0"
32
- name: rb-appscript
33
- requirement: *id001
34
33
  type: :runtime
34
+ version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
+ name: rb-appscript
36
37
  prerelease: false
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ requirement: &id002 !ruby/object:Gem::Requirement
38
39
  none: false
39
40
  requirements:
40
- - - ~>
41
+ - - ">="
41
42
  - !ruby/object:Gem::Version
42
- hash: 11
43
+ hash: 3
43
44
  segments:
44
- - 2
45
- - 1
46
45
  - 0
47
- version: 2.1.0
48
- name: rspec
49
- requirement: *id002
50
- type: :development
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
51
49
  - !ruby/object:Gem::Dependency
50
+ name: jeweler
52
51
  prerelease: false
53
- version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ requirement: &id003 !ruby/object:Gem::Requirement
54
53
  none: false
55
54
  requirements:
56
55
  - - ~>
57
56
  - !ruby/object:Gem::Version
58
- hash: 23
57
+ hash: 1
59
58
  segments:
60
59
  - 1
61
- - 0
62
- - 0
63
- version: 1.0.0
64
- name: bundler
65
- requirement: *id003
60
+ - 5
61
+ - 1
62
+ version: 1.5.1
66
63
  type: :development
64
+ version_requirements: *id003
67
65
  - !ruby/object:Gem::Dependency
66
+ name: rake-gem-ghost
68
67
  prerelease: false
69
- version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
70
69
  none: false
71
70
  requirements:
72
- - - ~>
71
+ - - ">="
73
72
  - !ruby/object:Gem::Version
74
- hash: 1
73
+ hash: 3
75
74
  segments:
76
- - 1
77
- - 5
78
- - 1
79
- version: 1.5.1
80
- name: jeweler
81
- requirement: *id004
75
+ - 0
76
+ version: "0"
82
77
  type: :development
78
+ version_requirements: *id004
83
79
  - !ruby/object:Gem::Dependency
80
+ name: rspec
84
81
  prerelease: false
85
- version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ requirement: &id005 !ruby/object:Gem::Requirement
86
83
  none: false
87
84
  requirements:
88
85
  - - ">="
@@ -91,9 +88,8 @@ dependencies:
91
88
  segments:
92
89
  - 0
93
90
  version: "0"
94
- name: rcov
95
- requirement: *id005
96
91
  type: :development
92
+ version_requirements: *id005
97
93
  description:
98
94
  email:
99
95
  executables: []
@@ -103,21 +99,25 @@ extensions: []
103
99
  extra_rdoc_files:
104
100
  - LICENSE.txt
105
101
  - README.rdoc
102
+ - TODO
106
103
  files:
107
- - Gemfile
108
- - Gemfile.lock
109
104
  - LICENSE.txt
110
105
  - README.rdoc
111
106
  - Rakefile
107
+ - TODO
112
108
  - VERSION
113
109
  - fspath.gemspec
114
110
  - lib/fspath.rb
111
+ - lib/fspath/darwin.rb
112
+ - lib/fspath/xattr.rb
113
+ - spec/fspath/darwin_spec.rb
114
+ - spec/fspath/xattr_spec.rb
115
115
  - spec/fspath_spec.rb
116
116
  - spec/spec_helper.rb
117
117
  has_rdoc: true
118
118
  homepage: http://github.com/toy/fspath
119
- licenses: []
120
-
119
+ licenses:
120
+ - MIT
121
121
  post_install_message:
122
122
  rdoc_options: []
123
123
 
@@ -149,5 +149,7 @@ signing_key:
149
149
  specification_version: 3
150
150
  summary: Better than Pathname
151
151
  test_files:
152
+ - spec/fspath/darwin_spec.rb
153
+ - spec/fspath/xattr_spec.rb
152
154
  - spec/fspath_spec.rb
153
155
  - spec/spec_helper.rb
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- group :development do
4
- gem "rspec", "~> 2.1.0"
5
- gem "bundler", "~> 1.0.0"
6
- gem "jeweler", "~> 1.5.1"
7
- gem "rcov", ">= 0"
8
- end
data/Gemfile.lock DELETED
@@ -1,28 +0,0 @@
1
- GEM
2
- remote: http://rubygems.org/
3
- specs:
4
- diff-lcs (1.1.2)
5
- git (1.2.5)
6
- jeweler (1.5.1)
7
- bundler (~> 1.0.0)
8
- git (>= 1.2.5)
9
- rake
10
- rake (0.8.7)
11
- rcov (0.9.9)
12
- rspec (2.1.0)
13
- rspec-core (~> 2.1.0)
14
- rspec-expectations (~> 2.1.0)
15
- rspec-mocks (~> 2.1.0)
16
- rspec-core (2.1.0)
17
- rspec-expectations (2.1.0)
18
- diff-lcs (~> 1.1.2)
19
- rspec-mocks (2.1.0)
20
-
21
- PLATFORMS
22
- ruby
23
-
24
- DEPENDENCIES
25
- bundler (~> 1.0.0)
26
- jeweler (~> 1.5.1)
27
- rcov
28
- rspec (~> 2.1.0)