epitools 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/epitools.gemspec +2 -2
  3. data/lib/epitools/path.rb +19 -16
  4. metadata +2 -2
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.2
1
+ 0.5.3
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "epitools"
8
- s.version = "0.5.2"
8
+ s.version = "0.5.3"
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 = "2012-04-05"
12
+ s.date = "2012-04-09"
13
13
  s.description = "Miscellaneous utility libraries to make my life easier."
14
14
  s.email = "chris@ill-logic.com"
15
15
  s.extra_rdoc_files = [
@@ -74,12 +74,12 @@ class Path
74
74
 
75
75
  if path =~ %r{^[a-z\-]+://}i # URL?
76
76
  Path::URL.new(path)
77
+
77
78
  elsif path =~ /^javascript:/
78
79
  Path::JS.new(path)
80
+
79
81
  else
80
-
81
82
  # todo: highlight backgrounds of codeblocks to show indent level & put boxes (or rules?) around (between?) double-spaced regions
82
-
83
83
  path = Path.expand_path(path)
84
84
  if path =~ /(^|[^\\])[\?\*\{\}]/ # contains unescaped glob chars?
85
85
  glob(path)
@@ -137,7 +137,10 @@ class Path
137
137
  end
138
138
 
139
139
  def dir=(newdir)
140
- @dirs = File.expand_path(newdir).split(File::SEPARATOR)[1..-1]
140
+ dirs = File.expand_path(newdir).split(File::SEPARATOR)
141
+ dirs = dirs[1..-1] if dirs.size > 0
142
+
143
+ @dirs = dirs
141
144
  end
142
145
 
143
146
  # TODO: Figure out how to fix the 'path.with(:ext=>ext+".other")' problem (when 'ext == nil')...
@@ -385,12 +388,16 @@ class Path
385
388
  ## modifying files
386
389
 
387
390
  #
388
- # Append
391
+ # Append data to this file (accepts a string, an IO, or it can yield the file handle to a block.)
389
392
  #
390
393
  def append(data=nil)
391
394
  self.open("ab") do |f|
392
395
  if data and not block_given?
393
- f.write(data)
396
+ if data.is_an? IO
397
+ IO.copy_stream(data, f)
398
+ else
399
+ f.write(data)
400
+ end
394
401
  else
395
402
  yield f
396
403
  end
@@ -400,12 +407,16 @@ class Path
400
407
  alias_method :<<, :append
401
408
 
402
409
  #
403
- # Write a string, truncating the file
410
+ # Overwrite the data in this file (accepts a string, an IO, or it can yield the file handle to a block.)
404
411
  #
405
412
  def write(data=nil)
406
413
  self.open("wb") do |f|
407
414
  if data and not block_given?
408
- f.write(data)
415
+ if data.is_an? IO
416
+ IO.copy_stream(data, f)
417
+ else
418
+ f.write(data)
419
+ end
409
420
  else
410
421
  yield f
411
422
  end
@@ -414,7 +425,7 @@ class Path
414
425
 
415
426
  #
416
427
  # Parse the file based on the file extension.
417
- # (Handles json, html, yaml, marshal.)
428
+ # (Handles json, html, yaml, xml, bson, and marshal.)
418
429
  #
419
430
  def parse
420
431
  case ext.downcase
@@ -715,14 +726,6 @@ raise "Broken!"
715
726
  self.path = gunzipped.path
716
727
  end
717
728
 
718
- #
719
- # Return the IO object for this file.
720
- #
721
- def io
722
- open
723
- end
724
- alias_method :stream, :io
725
-
726
729
  def =~(pattern)
727
730
  to_s =~ pattern
728
731
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: epitools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-05 00:00:00.000000000 Z
12
+ date: 2012-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec