epitools 0.5.39 → 0.5.41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +4 -0
- data/VERSION +1 -1
- data/lib/epitools/core_ext.rb +1 -0
- data/lib/epitools/core_ext/misc.rb +0 -22
- data/lib/epitools/core_ext/range.rb +35 -0
- data/lib/epitools/path.rb +91 -17
- data/lib/epitools/wm.rb +2 -0
- data/spec/core_ext_spec.rb +7 -0
- data/spec/path_spec.rb +46 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11d3c2b4e8f320ff75a614b617aa3571a8e4a89c
|
4
|
+
data.tar.gz: a33291591096efd021c4d8647d5e73e23dffa745
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 276e60d3e8028ebf5ebbac51ba8c33575f9c64bfc7997d828c13a8fd2a0a47d23a78e5f6f39b10d2de91cd16d8f7edb6435c842b3e274b0136604bbb9d45ff03
|
7
|
+
data.tar.gz: 284f2fa58e0fd4dc8e536b66515fce57a61a1fd7035623ea4360ebdf787c97c938f47eff235ca5ab47e4f424ea778e519fe8d0c306a372947a4aa4e3a1adca6f
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.41
|
data/lib/epitools/core_ext.rb
CHANGED
@@ -10,6 +10,7 @@ require 'epitools/core_ext/enumerable'
|
|
10
10
|
require 'epitools/core_ext/hash'
|
11
11
|
require 'epitools/core_ext/numbers'
|
12
12
|
require 'epitools/core_ext/truthiness'
|
13
|
+
require 'epitools/core_ext/range'
|
13
14
|
require 'epitools/core_ext/misc'
|
14
15
|
|
15
16
|
##############################################################################
|
@@ -169,28 +169,6 @@ end
|
|
169
169
|
|
170
170
|
|
171
171
|
|
172
|
-
class Range
|
173
|
-
|
174
|
-
#
|
175
|
-
# Pick a random number from the range.
|
176
|
-
#
|
177
|
-
def rand
|
178
|
-
Kernel.rand(self)
|
179
|
-
end
|
180
|
-
|
181
|
-
#
|
182
|
-
# The middle element of this range.
|
183
|
-
#
|
184
|
-
def middle
|
185
|
-
(min + max) / 2
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
|
193
|
-
|
194
172
|
class Struct
|
195
173
|
|
196
174
|
#
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Range
|
2
|
+
|
3
|
+
#
|
4
|
+
# Pick a random number from the range.
|
5
|
+
#
|
6
|
+
def rand
|
7
|
+
Kernel.rand(self)
|
8
|
+
end
|
9
|
+
|
10
|
+
#
|
11
|
+
# The middle element of this range.
|
12
|
+
#
|
13
|
+
def middle
|
14
|
+
(min + max) / 2
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Return a new range which is the intersection of the two ranges
|
19
|
+
#
|
20
|
+
def &(other)
|
21
|
+
mins, maxes = minmax.zip(other.minmax)
|
22
|
+
|
23
|
+
(mins.max..maxes.min)
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Return a new range which is the union of the two ranges
|
28
|
+
#
|
29
|
+
def |(other)
|
30
|
+
mins, maxes = minmax.zip(other.minmax)
|
31
|
+
|
32
|
+
(mins.min..maxes.max)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
data/lib/epitools/path.rb
CHANGED
@@ -175,8 +175,13 @@ class Path
|
|
175
175
|
def ext=(newext)
|
176
176
|
if newext.blank?
|
177
177
|
@ext = nil
|
178
|
-
|
179
|
-
|
178
|
+
return
|
179
|
+
end
|
180
|
+
|
181
|
+
newext = newext[1..-1] if newext.startswith('.')
|
182
|
+
|
183
|
+
if newext['.']
|
184
|
+
self.filename = basename + '.' + newext
|
180
185
|
else
|
181
186
|
@ext = newext
|
182
187
|
end
|
@@ -473,7 +478,7 @@ class Path
|
|
473
478
|
|
474
479
|
IO.popen(cmd, "rb", :err=>[:child, :out]) do |io|
|
475
480
|
result = io.each_line.to_a
|
476
|
-
error = {cmd
|
481
|
+
error = {:cmd => cmd, :result => result.to_s}.inspect
|
477
482
|
raise error if result.any?
|
478
483
|
end
|
479
484
|
end
|
@@ -692,34 +697,106 @@ class Path
|
|
692
697
|
Path.cd(path, &block)
|
693
698
|
end
|
694
699
|
|
700
|
+
#
|
701
|
+
# A private method for handling arguments to mv and rename.
|
702
|
+
#
|
703
|
+
def arg_to_path(arg)
|
704
|
+
case arg
|
705
|
+
when String, Path
|
706
|
+
Path[arg]
|
707
|
+
when Hash
|
708
|
+
self.with(arg)
|
709
|
+
else
|
710
|
+
raise "Error: argument must be a path (a String or a Path), or a hash of attributes to replace in the Path."
|
711
|
+
end
|
712
|
+
end
|
713
|
+
private :arg_to_path
|
714
|
+
|
715
|
+
#
|
716
|
+
# Renames the file, but doesn't change the current Path object, and returns a Path that points at the new filename.
|
695
717
|
#
|
696
718
|
# Examples:
|
719
|
+
# Path["file"].rename("newfile") #=> Path["newfile"]
|
697
720
|
# Path["SongySong.mp3"].rename(:basename=>"Songy Song")
|
698
721
|
# Path["Songy Song.mp3"].rename(:ext=>"aac")
|
699
722
|
# Path["Songy Song.aac"].rename(:dir=>"/music2")
|
700
723
|
# Path["/music2/Songy Song.aac"].exists? #=> true
|
701
724
|
#
|
702
|
-
def rename(
|
703
|
-
|
704
|
-
dest = self.with(options)
|
725
|
+
def rename(arg)
|
726
|
+
dest = arg_to_path(arg)
|
705
727
|
|
706
728
|
raise "Error: destination (#{dest.inspect}) already exists" if dest.exists?
|
729
|
+
raise "Error: can't rename #{self.inspect} because source location doesn't exist." unless exists?
|
730
|
+
|
707
731
|
File.rename(path, dest)
|
732
|
+
dest
|
733
|
+
end
|
734
|
+
alias_method :ren, :rename
|
708
735
|
|
709
|
-
|
736
|
+
#
|
737
|
+
# Works the same as "rename", but the destination can be on another disk.
|
738
|
+
#
|
739
|
+
def mv(arg)
|
740
|
+
dest = arg_to_path(arg)
|
710
741
|
|
711
|
-
self
|
742
|
+
raise "Error: can't move #{self.inspect} because source location doesn't exist." unless exists?
|
743
|
+
|
744
|
+
FileUtils.mv(path, dest)
|
745
|
+
dest
|
746
|
+
end
|
747
|
+
alias_method :move, :mv
|
748
|
+
|
749
|
+
#
|
750
|
+
# Rename the file and change this Path object so that it points to the destination file.
|
751
|
+
#
|
752
|
+
def rename!(arg)
|
753
|
+
update(rename(arg))
|
754
|
+
end
|
755
|
+
alias_method :ren!, :rename!
|
756
|
+
|
757
|
+
#
|
758
|
+
# Moves the file (overwriting the destination if it already exists). Also points the current Path object at the new destination.
|
759
|
+
#
|
760
|
+
def mv!(arg)
|
761
|
+
update(mv(arg))
|
762
|
+
end
|
763
|
+
alias_method :move!, :mv!
|
764
|
+
|
765
|
+
#
|
766
|
+
# Find a backup filename that doesn't exist yet by appending "(1)", "(2)", etc. to the current filename.
|
767
|
+
#
|
768
|
+
def numbered_backup_file
|
769
|
+
return self unless exists?
|
770
|
+
|
771
|
+
n = 1
|
772
|
+
loop do
|
773
|
+
new_file = with(:basename => "#{basename} (#{n})")
|
774
|
+
return new_file unless new_file.exists?
|
775
|
+
n += 1
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
#
|
780
|
+
# Return a copy of this Path with ".bak" at the end
|
781
|
+
#
|
782
|
+
def backup_file
|
783
|
+
with(:filename => filename+".bak")
|
712
784
|
end
|
713
785
|
|
714
786
|
#
|
715
|
-
#
|
787
|
+
# Rename this file, "filename.ext", to "filename (1).ext" (or (2), or (3), or whatever number is available.)
|
788
|
+
# (Does not modify this Path object.)
|
716
789
|
#
|
717
|
-
def
|
718
|
-
rename
|
790
|
+
def numbered_backup!
|
791
|
+
rename(numbered_backup_file)
|
719
792
|
end
|
720
793
|
|
721
|
-
|
722
|
-
|
794
|
+
#
|
795
|
+
# Rename this file, "filename.ext", to "filename.ext.bak".
|
796
|
+
# (Does not modify this Path object.)
|
797
|
+
#
|
798
|
+
def backup!
|
799
|
+
rename(backup_file)
|
723
800
|
end
|
724
801
|
|
725
802
|
#
|
@@ -748,10 +825,7 @@ class Path
|
|
748
825
|
|
749
826
|
def cp_r(dest)
|
750
827
|
FileUtils.cp_r(path, dest) #if Path[dest].exists?
|
751
|
-
|
752
|
-
|
753
|
-
def mv(dest)
|
754
|
-
FileUtils.mv(path, dest)
|
828
|
+
dest
|
755
829
|
end
|
756
830
|
|
757
831
|
def ln_s(dest)
|
data/lib/epitools/wm.rb
CHANGED
data/spec/core_ext_spec.rb
CHANGED
data/spec/path_spec.rb
CHANGED
@@ -55,6 +55,10 @@ describe Path do
|
|
55
55
|
path.ext.should == "mkv"
|
56
56
|
|
57
57
|
path.filename[-4..-1].should == ".mkv"
|
58
|
+
|
59
|
+
path.ext += ".extra"
|
60
|
+
path.filename.should == "hello.mkv.extra"
|
61
|
+
path.ext.should == "extra"
|
58
62
|
end
|
59
63
|
|
60
64
|
it "replaces filename" do
|
@@ -208,7 +212,7 @@ describe Path do
|
|
208
212
|
Path.pwd.should == start
|
209
213
|
end
|
210
214
|
|
211
|
-
it "renames" do
|
215
|
+
it "renames/mvs" do
|
212
216
|
path = Path.tmp
|
213
217
|
|
214
218
|
path.rm
|
@@ -218,10 +222,49 @@ describe Path do
|
|
218
222
|
|
219
223
|
old_name = path.to_s
|
220
224
|
|
221
|
-
path.rename(:ext=>".dat")
|
225
|
+
dest = path.rename(:ext=>".dat")
|
226
|
+
|
227
|
+
dest.to_s.should == old_name+".dat"
|
228
|
+
path.to_s.should == old_name
|
229
|
+
dest.to_s.should_not == old_name
|
230
|
+
|
231
|
+
dest.exists?.should == true
|
232
|
+
path.exists?.should == false
|
222
233
|
|
223
|
-
path.
|
234
|
+
path.touch
|
235
|
+
lambda { path.rename(:ext=>".dat") }.should raise_error
|
236
|
+
|
237
|
+
dest.rm
|
238
|
+
path.rename!(:ext=>".dat")
|
224
239
|
path.to_s.should_not == old_name
|
240
|
+
path.exists?.should == true
|
241
|
+
|
242
|
+
path.rm
|
243
|
+
end
|
244
|
+
|
245
|
+
it "backups" do
|
246
|
+
path = Path.tmp
|
247
|
+
path.rm
|
248
|
+
path.touch
|
249
|
+
|
250
|
+
dest = path.backup!
|
251
|
+
path.exists?.should == false
|
252
|
+
dest.exists?.should == true
|
253
|
+
|
254
|
+
dest.rm
|
255
|
+
|
256
|
+
path.touch
|
257
|
+
p path.numbered_backup_file
|
258
|
+
|
259
|
+
dest = path.numbered_backup!
|
260
|
+
path.touch
|
261
|
+
dest2 = path.numbered_backup!
|
262
|
+
|
263
|
+
dest.should_not == dest2
|
264
|
+
path.should_not == dest
|
265
|
+
|
266
|
+
dest.rm
|
267
|
+
dest2.rm
|
225
268
|
end
|
226
269
|
|
227
270
|
it "rms" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epitools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.41
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- epitron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11
|
11
|
+
date: 2013-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -58,6 +58,7 @@ files:
|
|
58
58
|
- lib/epitools/core_ext/misc.rb
|
59
59
|
- lib/epitools/core_ext/numbers.rb
|
60
60
|
- lib/epitools/core_ext/object.rb
|
61
|
+
- lib/epitools/core_ext/range.rb
|
61
62
|
- lib/epitools/core_ext/string.rb
|
62
63
|
- lib/epitools/core_ext/truthiness.rb
|
63
64
|
- lib/epitools/ezdb.rb
|