pa 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  Pa, a path libraray for Ruby
2
2
  ========================
3
3
 
4
- **Homepage**: [https://github.com/GutenLinux/pa](https://github.com/GutenLinux/pa) <br/>
4
+ **Homepage**: [https://github.com/GutenYe/pa](https://github.com/GutenYe/pa) <br/>
5
5
  **Author**: Guten <br/>
6
6
  **License**: MIT-LICENSE <br/>
7
7
  **Documentation**: [http://rubydoc.info/gems/pa/frames](http://rubydoc.info/gems/pa/frames) <br/>
8
- **Issue Tracker**: [https://github.com/GutenLinux/pa/issues](https://github.com/GutenLinux/pa/issues) <br/>
8
+ **Issue Tracker**: [https://github.com/GutenYe/pa/issues](https://github.com/GutenYe/pa/issues) <br/>
9
9
 
10
10
  Overview
11
11
  --------
data/lib/pa/cmd.rb CHANGED
@@ -335,6 +335,23 @@ module ClassMethods::Cmd
335
335
  end # _copy
336
336
  private :_copy
337
337
 
338
+ # a rename util
339
+ #
340
+ # @example
341
+ #
342
+ # Pa.rename('/home/guten.jpg') {|pa| pa.name+'_1'+pa.fext} # => '/home/guten_1.jpg'
343
+ # Pa('/home/guten.jpg').rename {|pa| pa.name+'_1'+pa.fext} # => <#Pa('/home/guten_1.jpg')>
344
+ #
345
+ # @param [String,Pa] src
346
+ # @yieldparam [Pa] pa
347
+ # @yieldreturn [String] fname
348
+ # @return [String,Pa] # Pa.rename return String. Pa#rename return Pa.
349
+ def rename src, &blk
350
+ src = Pa(src)
351
+ fname = blk.call(src)
352
+ src.dir_pa.join(fname).path
353
+ end
354
+
338
355
  # move, use rename for same device. and cp for cross device.
339
356
  # @see cp
340
357
  #
data/lib/pa/path.rb CHANGED
@@ -229,7 +229,15 @@ attribute absolute and dir return String, method absolute_path(), dirname() retu
229
229
  =end
230
230
  module Path
231
231
  # @return [String]
232
- attr_reader :absolute, :dir, :base, :name, :ext, :fext, :short
232
+ attr_reader :absolute, :dir, :base, :name, :short
233
+
234
+ # @return [String] ext "", "ogg"
235
+ attr_reader :ext
236
+
237
+ # @return [String] ext "", ".ogg"
238
+ attr_reader :fext
239
+
240
+ attr_reader :absolute_pa, :dir_pa, :base_pa, :name_pa, :ext_pa, :fext_pa, :short_pa
233
241
 
234
242
  def initialize_variables
235
243
  super
@@ -241,6 +249,14 @@ module Path
241
249
  @fext = @ext.empty? ? "" : "."+@ext
242
250
  end
243
251
 
252
+ def absolute_pa; @absolute_pa ||= Pa(@absolute) end
253
+ def dir_pa; @dir_pa ||= Pa(@dir) end
254
+ def base_pa; @base_pa ||= Pa(@base) end
255
+ def name_pa; @name_pa ||= Pa(@name) end
256
+ def ext_pa; @ext_pa ||= Pa(@ext) end
257
+ def fext_pa; @fext_pa ||= Pa(@fext) end
258
+ def short_pa; @short_pa ||= Pa(@short) end
259
+
244
260
  alias a absolute
245
261
  alias d dir
246
262
  alias b base
@@ -250,18 +266,19 @@ module Path
250
266
  alias e ext
251
267
  alias fe fext
252
268
 
269
+ alias a_pa absolute_pa
270
+ alias d_pa dir_pa
271
+ alias b_pa base_pa
272
+ alias n_pa name_pa
273
+ alias fname_pa base_pa
274
+ alias fn_pa fname_pa
275
+ alias e_pa ext_pa
276
+ alias fe_pa fext_pa
277
+
253
278
  def short
254
279
  @short ||= Pa.shorten(@path)
255
280
  end
256
281
 
257
- # @return [Pa] absolute path
258
- def absolute2() @absolute2 ||= Pa(absolute) end
259
-
260
- # @return [Pa] dirname
261
- # @example
262
- # Pa(__FILE__).dirname.join('.opts')
263
- def dir2() @dir2 ||= Pa(dir) end
264
-
265
282
  # add string to path
266
283
  #
267
284
  # @example
data/lib/pa/state.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  class Pa
2
2
  module ClassMethods::State
3
-
4
3
  # @see File.chmod
5
4
  def chmod(mode, *paths) paths.map!{|v|get(v)}; File.chmod(mode, *paths) end
6
5
 
@@ -16,7 +15,6 @@ module ClassMethods::State
16
15
  # @see File.utime
17
16
  def utime(atime, mtime, *paths) paths.map!{|v|get(v)}; File.utime(atime, mtime, *paths) end
18
17
 
19
-
20
18
  # get file type
21
19
  #
22
20
  # file types:
@@ -37,7 +35,6 @@ module ClassMethods::State
37
35
  end
38
36
  end # def type
39
37
 
40
-
41
38
  # is path a mountpoint?
42
39
  #
43
40
  # @param[String] path
data/lib/pa.rb CHANGED
@@ -15,6 +15,8 @@ Examples:
15
15
  pa.ext #=> 'vim'
16
16
  pa.fext #=> '.vim'
17
17
 
18
+ pa.dir_pa #=> Pa('/home') # similar, but return <#Pa>
19
+
18
20
  Filename parts:
19
21
  ---------
20
22
  /home/guten.ogg
@@ -75,10 +77,6 @@ class Pa
75
77
  initialize_variables
76
78
  end
77
79
 
78
- def ok
79
- initialize_variables
80
- end
81
-
82
80
  chainable = Module.new do
83
81
  def initialize_variables; end
84
82
  end
@@ -127,6 +125,19 @@ class Pa
127
125
 
128
126
  end
129
127
 
128
+ def <=> other
129
+ other_path = nil
130
+ other_path =
131
+ if other.respond_to?(:path)
132
+ other.path
133
+ elsif String === other
134
+ other
135
+ else
136
+ raise Error, "not support type -- #{other.class}"
137
+ end
138
+
139
+ path <=> other_path
140
+ end
130
141
 
131
142
  end
132
143
 
data/pa.gemspec CHANGED
@@ -1,6 +1,5 @@
1
1
  $: << "."
2
2
  require "version"
3
- require "bundler"
4
3
 
5
4
  Gem::Specification.new do |s|
6
5
  s.name = "pa"
@@ -12,11 +11,10 @@ a path library for Ruby
12
11
 
13
12
  s.author = "Guten"
14
13
  s.email = "ywzhaifei@Gmail.com"
15
- s.homepage = "http://github.com/GutenLinux/pa"
14
+ s.homepage = "http://github.com/GutenYe/pa"
16
15
  s.rubyforge_project = "xx"
17
16
 
18
17
  s.files = `git ls-files`.split("\n")
19
18
 
20
- s.add_bundler_dependencies
21
- #s.add_dependency "x"
19
+ s.add_dependency "tagen", "~>1.0.0"
22
20
  end
data/spec/pa/cmd_spec.rb CHANGED
@@ -128,7 +128,7 @@ describe Pa do
128
128
  end
129
129
 
130
130
  it "_copy file" do
131
- Pa._copy 'a', 'b', verbose: true
131
+ Pa._copy 'a', 'b'
132
132
  File.exists?('b').should be_true
133
133
  end
134
134
 
@@ -269,4 +269,21 @@ describe Pa do
269
269
  end
270
270
  end
271
271
 
272
+ describe ".rename" do
273
+ it "works" do
274
+ Pa.rename('/home/guten.jpg') {|pa|
275
+ pa.name+'_1'+pa.fext
276
+ }.should == '/home/guten_1.jpg'
277
+ end
278
+ end
279
+
280
+ describe "#rename" do
281
+ it "works" do
282
+ Pa('/home/guten.jpg').rename {|pa|
283
+ pa.name+'_1'+pa.fext
284
+ }.should == Pa('/home/guten_1.jpg')
285
+ end
286
+ end
287
+
288
+
272
289
  end
data/spec/pa/path_spec.rb CHANGED
@@ -137,5 +137,10 @@ describe Pa do
137
137
  end
138
138
  end
139
139
 
140
+ describe "#dir_pa" do
141
+ it "return Pa instance" do
142
+ Pa('/home/guten').dir_pa.should be_an_instance_of(Pa)
143
+ end
144
+ end
140
145
 
141
146
  end
data/spec/pa_spec.rb ADDED
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Pa do
4
+ describe "#<=>" do
5
+ it "runs ok" do
6
+ (Pa('/home/b') <=> Pa('/home/a')).should == 1
7
+ end
8
+ end
9
+ end
data/version.rb CHANGED
@@ -2,7 +2,7 @@ class Pa
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 2
5
+ PATCH = 3
6
6
 
7
7
  IS = [MAJOR, MINOR, PATCH].join(".")
8
8
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Guten
@@ -10,10 +10,11 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-09 00:00:00 Z
13
+ date: 2011-07-05 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: tagen
17
+ prerelease: false
17
18
  requirement: &id001 !ruby/object:Gem::Requirement
18
19
  none: false
19
20
  requirements:
@@ -21,63 +22,7 @@ dependencies:
21
22
  - !ruby/object:Gem::Version
22
23
  version: 1.0.0
23
24
  type: :runtime
24
- prerelease: false
25
25
  version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: pa
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: 1.0.0
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: thor
39
- requirement: &id003 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ~>
43
- - !ruby/object:Gem::Version
44
- version: 0.14.0
45
- type: :runtime
46
- prerelease: false
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
49
- name: rspec
50
- requirement: &id004 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: "0"
56
- type: :development
57
- prerelease: false
58
- version_requirements: *id004
59
- - !ruby/object:Gem::Dependency
60
- name: watchr
61
- requirement: &id005 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: "0"
67
- type: :development
68
- prerelease: false
69
- version_requirements: *id005
70
- - !ruby/object:Gem::Dependency
71
- name: yard
72
- requirement: &id006 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: "0"
78
- type: :development
79
- prerelease: false
80
- version_requirements: *id006
81
26
  description: |
82
27
  a path library for Ruby
83
28
 
@@ -107,9 +52,10 @@ files:
107
52
  - spec/pa/dir_spec.rb
108
53
  - spec/pa/path_spec.rb
109
54
  - spec/pa/state_spec.rb
55
+ - spec/pa_spec.rb
110
56
  - spec/spec_helper.rb
111
57
  - version.rb
112
- homepage: http://github.com/GutenLinux/pa
58
+ homepage: http://github.com/GutenYe/pa
113
59
  licenses: []
114
60
 
115
61
  post_install_message:
@@ -122,9 +68,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
68
  requirements:
123
69
  - - ">="
124
70
  - !ruby/object:Gem::Version
125
- hash: -3646462436078976361
126
- segments:
127
- - 0
128
71
  version: "0"
129
72
  required_rubygems_version: !ruby/object:Gem::Requirement
130
73
  none: false