epitools 0.4.43 → 0.4.44

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.43
1
+ 0.4.44
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{epitools}
8
- s.version = "0.4.43"
8
+ s.version = "0.4.44"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["epitron"]
12
- s.date = %q{2011-06-12}
12
+ s.date = %q{2011-06-15}
13
13
  s.description = %q{Miscellaneous utility libraries to make my life easier.}
14
14
  s.email = %q{chris@ill-logic.com}
15
15
  s.extra_rdoc_files = [
@@ -46,6 +46,7 @@ Gem::Specification.new do |s|
46
46
  "lib/epitools/string_to_proc.rb",
47
47
  "lib/epitools/sys.rb",
48
48
  "lib/epitools/zopen.rb",
49
+ "spec/autoreq_spec.rb",
49
50
  "spec/basetypes_spec.rb",
50
51
  "spec/browser_spec.rb",
51
52
  "spec/clitools_spec.rb",
@@ -64,11 +65,10 @@ Gem::Specification.new do |s|
64
65
  s.homepage = %q{http://github.com/epitron/epitools}
65
66
  s.licenses = ["WTFPL"]
66
67
  s.require_paths = ["lib"]
67
- s.rubygems_version = %q{1.3.7}
68
+ s.rubygems_version = %q{1.6.2}
68
69
  s.summary = %q{NOT UTILS... METILS!}
69
70
 
70
71
  if s.respond_to? :specification_version then
71
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
72
72
  s.specification_version = 3
73
73
 
74
74
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -8,6 +8,7 @@ autoload :Zlib, 'zlib'
8
8
  autoload :FileUtils, 'fileutils'
9
9
  autoload :Tempfile, 'tempfile'
10
10
  autoload :BigDecimal, 'bigdecimal'
11
+ autoload :StringIO, 'stringio'
11
12
 
12
13
  module Digest
13
14
  autoload :SHA1, 'digest/sha1'
@@ -198,6 +198,37 @@ class String
198
198
  Digest::SHA1.hexdigest self
199
199
  end
200
200
 
201
+ #
202
+ # gzip the string
203
+ #
204
+ def gzip(level=nil)
205
+ zipped = StringIO.new
206
+ Zlib::GzipWriter.wrap(zipped, level) { |io| io.write(self) }
207
+ zipped.string
208
+ end
209
+
210
+ #
211
+ # gunzip the string
212
+ #
213
+ def gunzip
214
+ data = StringIO.new(self)
215
+ Zlib::GzipReader.new(data).read
216
+ end
217
+
218
+ #
219
+ # deflate the string
220
+ #
221
+ def deflate(level=nil)
222
+ Zlib::Deflate.deflate(self, level)
223
+ end
224
+
225
+ #
226
+ # inflate the string
227
+ #
228
+ def inflate
229
+ Zlib::Inflate.inflate(self)
230
+ end
231
+
201
232
  # `true` if this string starts with the substring
202
233
  #
203
234
  def startswith(substring)
@@ -329,6 +360,13 @@ class Array
329
360
  self[(size-1) / 2]
330
361
  end
331
362
 
363
+ #
364
+ # XOR operator
365
+ #
366
+ def ^(other)
367
+ (self | other) - (self & other)
368
+ end
369
+
332
370
  end
333
371
 
334
372
 
@@ -340,6 +378,11 @@ module Enumerable
340
378
  def blank?
341
379
  not any?
342
380
  end
381
+
382
+ #
383
+ # I enjoy typing ".all" more than ".to_a"
384
+ #
385
+ alias_method :all, :to_a
343
386
 
344
387
  #
345
388
  # Split this enumerable into an array of pieces given some
@@ -13,18 +13,25 @@ class Path
13
13
  end
14
14
 
15
15
  def self.[](path)
16
+
16
17
  case path
17
18
  when Path
18
19
  path
19
20
  when String
21
+
20
22
  if path =~ %r{^[a-z\-]+://}i # URL?
21
23
  Path::URL.new(path)
22
- elsif path =~ /[\?\*]/ and not path =~ /\\[\?\*]/ # contains glob chars? (unescaped)
23
- glob(path)
24
24
  else
25
- new(path)
25
+ path = expand_path path
26
+ if path =~ /(^|[^\\])[\?\*\{\}]/ # contains unescaped glob chars?
27
+ glob(path)
28
+ else
29
+ new(path)
30
+ end
26
31
  end
27
- end
32
+
33
+ end
34
+
28
35
  end
29
36
 
30
37
  ## setters
@@ -356,7 +363,7 @@ class Path
356
363
 
357
364
  # http://ruby-doc.org/stdlib/libdoc/zlib/rdoc/index.html
358
365
 
359
- def gzip
366
+ def gzip(level=nil)
360
367
  gz_filename = self.with(:filename=>filename+".gz")
361
368
 
362
369
  raise "#{gz_filename} already exists" if gz_filename.exists?
@@ -370,8 +377,8 @@ class Path
370
377
  gz_filename
371
378
  end
372
379
 
373
- def gzip!
374
- gzipped = self.gzip
380
+ def gzip!(level=nil)
381
+ gzipped = self.gzip(level)
375
382
  self.rm
376
383
  self.path = gzipped.path
377
384
  end
@@ -459,6 +466,15 @@ class Path
459
466
  ############################################################################
460
467
  ## Class Methods
461
468
 
469
+ #
470
+ # Same as File.expand_path, except preserves the trailing '/'.
471
+ #
472
+ def self.expand_path(orig_path)
473
+ new_path = File.expand_path orig_path
474
+ new_path << "/" if orig_path.endswith "/"
475
+ new_path
476
+ end
477
+
462
478
  #
463
479
  # TODO: Remove the tempfile when the Path object is garbage collected or freed.
464
480
  #
@@ -474,7 +490,7 @@ class Path
474
490
  end
475
491
 
476
492
  def self.pwd
477
- File.expand_path Dir.pwd
493
+ Path.new expand_path(Dir.pwd)
478
494
  end
479
495
 
480
496
  def self.pushd
@@ -0,0 +1,37 @@
1
+ require 'epitools'
2
+
3
+ describe "autoreq" do
4
+
5
+ it "should have MimeMagic and Units installed" do
6
+ gems = Gem.source_index.to_a.map{|name, spec| spec.name}.uniq
7
+ gems.include?("mimemagic").should == true
8
+ gems.include?("units").should == true
9
+ end
10
+
11
+ it "autoreqs a gem" do
12
+ defined?(MimeMagic).should == nil
13
+
14
+ autoreq :MimeMagic, 'mimemagic'
15
+ lambda { MimeMagic }.should_not raise_error
16
+ end
17
+
18
+ it "autoreqs a regular ruby file" do
19
+ defined?(Net).should == nil
20
+
21
+ module Net
22
+ autoreq :HTTP, 'net/http'
23
+ end
24
+ lambda { Net::HTTP }.should_not raise_error
25
+ end
26
+
27
+ it "autoreqs a gem with a block" do
28
+ defined?(Units).should == nil
29
+
30
+ autoreq :Units do
31
+ gem 'units', '~> 1.0'
32
+ require 'units'
33
+ end
34
+ lambda { Units }.should_not raise_error
35
+ end
36
+
37
+ end
@@ -164,6 +164,18 @@ describe String do
164
164
  s.sha1.should_not == s
165
165
  s.sha1.should_not == s.md5
166
166
  end
167
+
168
+ it "gzips/gunzips/delfates/inflates" do
169
+ s = "asdklfjasdfjaeh"
170
+ s.deflate.should_not == s
171
+ s.deflate.inflate.should == s
172
+
173
+ s.gzip.should_not == s
174
+ s.gzip.gunzip.should == s
175
+
176
+ s.gzip(9).size.should < s.gzip(0).size
177
+ s.deflate(9).size.should < s.deflate(0).size
178
+ end
167
179
 
168
180
  it "starts/endswith" do
169
181
  "blahblahblah".startswith("blah").should == true
@@ -259,4 +259,16 @@ describe Path do
259
259
  Path[path].path.should == path.path
260
260
  end
261
261
 
262
+ it "uses advanced glob features" do
263
+ # ruby-1.9.2-p180 :001 > Path["~/.ssh/id_{dsa,rsa}.pub"]
264
+ # => /home/epi/.ssh/id_{dsa,rsa}.pub
265
+ # ruby-1.9.2-p180 :002 > Dir["~/.ssh/id_{dsa,rsa}.pub"]
266
+ # => []
267
+ # ruby-1.9.2-p180 :003 > Dir["../../.ssh/id_{dsa,rsa}.pub"]
268
+ # => ["../../.ssh/id_rsairb.pub"]
269
+
270
+ Path["~/.ssh/id_{dsa,rsa}.pub"].size.should > 0
271
+
272
+ end
273
+
262
274
  end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 89
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 4
9
- - 43
10
- version: 0.4.43
4
+ prerelease:
5
+ version: 0.4.44
11
6
  platform: ruby
12
7
  authors:
13
8
  - epitron
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2011-06-12 00:00:00 -04:00
13
+ date: 2011-06-15 00:00:00 -04:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,11 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ~>
28
23
  - !ruby/object:Gem::Version
29
- hash: 7
30
- segments:
31
- - 2
32
- - 2
33
- - 0
34
24
  version: 2.2.0
35
25
  type: :development
36
26
  version_requirements: *id001
@@ -42,11 +32,6 @@ dependencies:
42
32
  requirements:
43
33
  - - ~>
44
34
  - !ruby/object:Gem::Version
45
- hash: 23
46
- segments:
47
- - 1
48
- - 0
49
- - 0
50
35
  version: 1.0.0
51
36
  type: :development
52
37
  version_requirements: *id002
@@ -58,9 +43,6 @@ dependencies:
58
43
  requirements:
59
44
  - - ">="
60
45
  - !ruby/object:Gem::Version
61
- hash: 3
62
- segments:
63
- - 0
64
46
  version: "0"
65
47
  type: :development
66
48
  version_requirements: *id003
@@ -103,6 +85,7 @@ files:
103
85
  - lib/epitools/string_to_proc.rb
104
86
  - lib/epitools/sys.rb
105
87
  - lib/epitools/zopen.rb
88
+ - spec/autoreq_spec.rb
106
89
  - spec/basetypes_spec.rb
107
90
  - spec/browser_spec.rb
108
91
  - spec/clitools_spec.rb
@@ -131,23 +114,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
114
  requirements:
132
115
  - - ">="
133
116
  - !ruby/object:Gem::Version
134
- hash: 3
135
- segments:
136
- - 0
137
117
  version: "0"
138
118
  required_rubygems_version: !ruby/object:Gem::Requirement
139
119
  none: false
140
120
  requirements:
141
121
  - - ">="
142
122
  - !ruby/object:Gem::Version
143
- hash: 3
144
- segments:
145
- - 0
146
123
  version: "0"
147
124
  requirements: []
148
125
 
149
126
  rubyforge_project:
150
- rubygems_version: 1.3.7
127
+ rubygems_version: 1.6.2
151
128
  signing_key:
152
129
  specification_version: 3
153
130
  summary: NOT UTILS... METILS!