riel 1.1.17 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d9fec4fdc968d7eac63fc2e894a6bd3b2252d86f
4
+ data.tar.gz: 38b6c94c7045866f8fbf88fdd6ec7861a0bd0750
5
+ SHA512:
6
+ metadata.gz: 59546acde4a6fdf7d2716be86af60d2cc6c5a3a6fa389dede2790de02c2c251f6708510f59413c07c6f79604529c8c957cd4a5e48250f1007ecf3cae9740a10f
7
+ data.tar.gz: a2d02521a496858feb6d9d08dfb2fca21ec6bf7f97c9b381ef971554ad49a8c8bf9ec6f30ebeb1d0106e557b04a474a4b1c544ce928ea94b251810c44cb432f2
data/lib/riel/date.rb CHANGED
@@ -4,9 +4,17 @@
4
4
 
5
5
  require 'date'
6
6
 
7
- class Date
8
- # Returns the number of days in the given month.
9
- def self.days_in_month year, month
10
- (Date.new(year, 12, 31) << (12 - month)).day
7
+ module RIEL
8
+ module DateExt
9
+ def self.included base
10
+ base.extend ClassMethods
11
+ end
12
+
13
+ module ClassMethods
14
+ # Returns the number of days in the given month.
15
+ def days_in_month year, month
16
+ (Date.new(year, 12, 31) << (12 - month)).day
17
+ end
18
+ end
11
19
  end
12
20
  end
data/lib/riel/dir.rb CHANGED
@@ -3,90 +3,96 @@
3
3
 
4
4
  require 'pathname'
5
5
 
6
- class Dir
7
-
8
- # Returns the home directory, for both Unix and Windows.
9
- unless RUBY_VERSION.index('1.9')
10
- def self.home
11
- ENV["HOME"] || begin
12
- hd = ENV["HOMEDRIVE"]
13
- hp = ENV["HOMEPATH"]
14
- if hd || hp
15
- (hd || "") + (hp || "\\")
16
- end
17
- end
6
+ module RIEL
7
+ module DirExt
8
+ def self.included base
9
+ base.extend ClassMethods
18
10
  end
19
- end
20
11
 
21
- # Removes directories containing no files or files matching only those in
22
- # args[:deletable_files], which are basenames.
23
- def self.remove_if_empty(dir, args = Hash.new)
24
- deletable = args[:deletable] || Array.new
25
- verbose = args[:verbose]
26
- level = args[:level] || 0
12
+ module ClassMethods
13
+ # Returns the home directory, for both Unix and Windows.
14
+ unless RUBY_VERSION.index('1.9')
15
+ def home
16
+ ENV["HOME"] || begin
17
+ hd = ENV["HOMEDRIVE"]
18
+ hp = ENV["HOMEPATH"]
19
+ if hd || hp
20
+ (hd || "") + (hp || "\\")
21
+ end
22
+ end
23
+ end
24
+ end
27
25
 
28
- subargs = args.dup
29
- subargs[:level] = level + 1
26
+ # Removes directories containing no files or files matching only those in
27
+ # args[:deletable_files], which are basenames.
28
+ def remove_if_empty dir, args = Hash.new
29
+ deletable = args[:deletable] || Array.new
30
+ verbose = args[:verbose]
31
+ level = args[:level] || 0
30
32
 
31
- dir = Pathname.new(dir) unless dir.kind_of?(Pathname)
33
+ subargs = args.dup
34
+ subargs[:level] = level + 1
32
35
 
33
- if level <= 1 && verbose
34
- puts "dir: #{dir}"
35
- end
36
+ dir = Pathname.new(dir) unless dir.kind_of?(Pathname)
36
37
 
37
- if dir.readable?
38
- dir.children.sort.each do |child|
39
- if child.exist? && child.directory?
40
- self.remove_if_empty child, subargs
38
+ if level <= 1 && verbose
39
+ puts "dir: #{dir}"
41
40
  end
42
- end
43
-
44
- if dir.expand_path == Pathname.pwd.expand_path
45
- puts "skipping current directory: #{dir}" if verbose
46
- else
47
- can_delete = dir.children.all? do |x|
48
- bname = x.basename.to_s
49
- deletable.any? do |del|
50
- if del.kind_of? String
51
- bname == del
52
- elsif del.kind_of? Regexp
53
- del.match bname
54
- else
55
- false
41
+
42
+ if dir.readable?
43
+ dir.children.sort.each do |child|
44
+ if child.exist? && child.directory?
45
+ self.remove_if_empty child, subargs
56
46
  end
57
47
  end
58
- end
48
+
49
+ if dir.expand_path == Pathname.pwd.expand_path
50
+ puts "skipping current directory: #{dir}" if verbose
51
+ else
52
+ can_delete = dir.children.all? do |x|
53
+ bname = x.basename.to_s
54
+ deletable.any? do |del|
55
+ if del.kind_of? String
56
+ bname == del
57
+ elsif del.kind_of? Regexp
58
+ del.match bname
59
+ else
60
+ false
61
+ end
62
+ end
63
+ end
59
64
 
60
- if can_delete
61
- dir.children.each do |x|
62
- puts "removing file: #{x}" if verbose
63
- x.delete
64
- end
65
+ if can_delete
66
+ dir.children.each do |x|
67
+ puts "removing file: #{x}" if verbose
68
+ x.delete
69
+ end
65
70
 
66
- puts "removing directory: #{dir}" if verbose
71
+ puts "removing directory: #{dir}" if verbose
67
72
 
68
- dir.delete
69
- else
70
- # puts "#{dir} not empty"
73
+ dir.delete
74
+ else
75
+ # puts "#{dir} not empty"
76
+ end
77
+ end
78
+ elsif verbose
79
+ puts "#{dir} not readable"
71
80
  end
72
81
  end
73
- elsif verbose
74
- puts "#{dir} not readable"
75
- end
76
- end
77
82
 
78
- # Moves and copies files to the given directory, creating
79
- # it if it does not exist.
80
- def self.move_and_copy_files dir, move_files, copy_files
81
- dir.mkdir unless dir.exist?
83
+ # Moves and copies files to the given directory, creating
84
+ # it if it does not exist.
85
+ def move_and_copy_files dir, move_files, copy_files
86
+ dir.mkdir unless dir.exist?
82
87
 
83
- move_files.each do |mfile|
84
- File.move mfile.to_s, dir.to_s
85
- end
88
+ move_files.each do |mfile|
89
+ File.move mfile.to_s, dir.to_s
90
+ end
86
91
 
87
- copy_files.each do |cfile|
88
- File.copy cfile.to_s, dir.to_s
92
+ copy_files.each do |cfile|
93
+ File.copy cfile.to_s, dir.to_s
94
+ end
95
+ end
89
96
  end
90
97
  end
91
-
92
98
  end
@@ -1,64 +1,43 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- module Enumerable
5
- def collect_with_index &blk
6
- ary = []
7
- self.each_with_index do |item, idx|
8
- ary << blk.call(item, idx)
4
+ module RIEL
5
+ module EnumerableExt
6
+ def collect_with_index &blk
7
+ ary = []
8
+ self.each_with_index do |item, idx|
9
+ ary << blk.call(item, idx)
10
+ end
11
+ ary
9
12
  end
10
- ary
11
- end
12
-
13
- NOT_NIL = Object.new
14
-
15
- def select_with_index arg = NOT_NIL, &blk
16
- ary = []
17
- self.each_with_index do |item, idx|
18
- ary << item if _match?(arg, item, idx, &blk)
19
- end
20
- ary
21
- end
22
13
 
23
- def detect_with_index arg = NOT_NIL, &blk
24
- self.each_with_index do |item, idx|
25
- return item if _match?(arg, item, idx, &blk)
26
- end
27
- nil
28
- end
29
-
30
- alias :orig_select :select
31
- alias :orig_collect :collect
32
- alias :orig_detect :detect
33
- alias :orig_reject :reject
14
+ NOT_NIL = Object.new
34
15
 
35
- origw = $-w
36
- $-w = false
37
- def select arg = NOT_NIL, &blk
38
- ary = []
39
- self.each_with_index do |item, idx|
40
- ary << item if _match?(arg, item, idx, &blk)
16
+ def select_with_index arg = NOT_NIL, &blk
17
+ ary = []
18
+ self.each_with_index do |item, idx|
19
+ ary << item if _match?(arg, item, idx, &blk)
20
+ end
21
+ ary
41
22
  end
42
- ary
43
- end
44
23
 
45
- def detect arg = NOT_NIL, &blk
46
- self.each_with_index do |item, idx|
47
- return item if _match?(arg, item, idx, &blk)
24
+ def detect_with_index arg = NOT_NIL, &blk
25
+ self.each_with_index do |item, idx|
26
+ return item if _match?(arg, item, idx, &blk)
27
+ end
28
+ nil
48
29
  end
49
- nil
50
- end
51
- $-w = origw
52
30
 
53
- def _match? arg, item, idx, &blk
54
- if blk
55
- args = [ item ]
56
- args << idx if idx && blk.arity > 1
57
- blk.call(*args)
58
- elsif arg == NOT_NIL
59
- !item.nil?
60
- else
61
- arg == item
31
+ def _match? arg, item, idx, &blk
32
+ if blk
33
+ args = [ item ]
34
+ args << idx if idx && blk.arity > 1
35
+ blk.call(*args)
36
+ elsif arg == NOT_NIL
37
+ !item.nil?
38
+ else
39
+ arg == item
40
+ end
62
41
  end
63
42
  end
64
43
  end
data/lib/riel/pathname.rb CHANGED
@@ -9,7 +9,7 @@ class Pathname
9
9
  # a compliment to the +dirname+, +basename+, and +extname+ family, this returns
10
10
  # the basename without the extension, e.g. "foo" from "/usr/share/lib/foo.bar".
11
11
  def rootname
12
- basename.to_s - extname.to_s
12
+ basename.to_s.sub extname.to_s, ''
13
13
  end
14
14
 
15
15
  # Returns an array of the path split into its components.
data/lib/riel/rcfile.rb CHANGED
@@ -1,12 +1,10 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
-
5
4
  # Represents a resource file, where '#' is used to comment to end of lines, and
6
5
  # name/value pairs are separated by '=' or ':'.
7
6
 
8
7
  class RCFile
9
-
10
8
  attr_reader :settings
11
9
 
12
10
  # Reads the RC file, if it exists, and if a block is passed, calls the block
data/lib/riel/regexp.rb CHANGED
@@ -3,15 +3,12 @@
3
3
 
4
4
  # Negates the given expression.
5
5
  class NegatedRegexp < Regexp
6
-
7
6
  def match str
8
7
  !super
9
8
  end
10
-
11
9
  end
12
10
 
13
11
  class Regexp
14
-
15
12
  # shell expressions to Ruby regular expression sequences
16
13
  SH2RE = Hash[
17
14
  '*' => '.*',
@@ -103,7 +100,7 @@ class Regexp
103
100
  else
104
101
  pattern.sub!(%r{ ^\/ (.*[^\\]) \/ $ }x) { $1 }
105
102
  end
106
-
103
+
107
104
  if wholewords
108
105
  # sanity check:
109
106
 
@@ -116,7 +113,7 @@ class Regexp
116
113
  end.compact
117
114
 
118
115
  if errs.length > 0
119
- Log.warn "pattern '#{pattern}' does not " + errs.join(" and ") + " on a word boundary"
116
+ raise RuntimeError.new("pattern '#{pattern}' does not " + errs.join(" and ") + " on a word boundary")
120
117
  end
121
118
  pattern = '\b' + pattern + '\b'
122
119
  elsif wholelines
@@ -148,5 +145,4 @@ class Regexp
148
145
  # applies Perl-style substitution (s/foo/bar/).
149
146
  def self.perl_subst pat
150
147
  end
151
-
152
148
  end
data/lib/riel/setdiff.rb CHANGED
@@ -8,8 +8,6 @@ class SetDiff
8
8
  def self.new a, b
9
9
  allitems = a | b
10
10
 
11
- diff_type = :identical
12
-
13
11
  a_and_b = Array.new
14
12
  a_not_in_b = Array.new
15
13
  b_not_in_a = Array.new
data/lib/riel/string.rb CHANGED
@@ -10,98 +10,93 @@
10
10
  # Documentation:: Author
11
11
  #
12
12
 
13
- class String
14
- #
15
- # Returns whether the string ends with the given substring.
16
- #
17
- def ends_with substr
18
- return rindex(substr) == length - substr.length
19
- end
20
-
21
- #
22
- # Returns the string, as a number if it is one, and nil otherwise,
23
- #
24
- def num
25
- begin
26
- Integer self
27
- rescue ArgumentError
28
- nil
13
+ module RIEL
14
+ module StringExt
15
+ #
16
+ # Returns whether the string ends with the given substring.
17
+ #
18
+ def ends_with substr
19
+ return rindex(substr) == length - substr.length
29
20
  end
30
- end
31
21
 
32
- #
33
- # Returns a string based on this instance, with the first occurrance of
34
- # +other+ removed. +other+ may be a string or regular expression.
35
- #
36
- def - other
37
- sub other, ''
38
- end
22
+ #
23
+ # Returns the string, as a number if it is one, and nil otherwise,
24
+ #
25
+ def num
26
+ begin
27
+ Integer self
28
+ rescue ArgumentError
29
+ nil
30
+ end
31
+ end
39
32
 
40
- #
41
- # Represents infinity, for the +to_ranges+ function.
42
- #
43
- Infinity = (1.0 / 0)
33
+ #
34
+ # Returns a string based on this instance, with the first occurrance of
35
+ # +other+ removed. +other+ may be a string or regular expression.
36
+ #
37
+ def - other
38
+ sub other, ''
39
+ end
44
40
 
45
- # :stopdoc:
46
- # from (maybe to this)
47
- RANGE_REGEXP = %r{^ \s* (\d*) (?: \s* (\-|\.\.) \s* (\d*) )? \s* $ }x
48
- # :startdoc:
41
+ #
42
+ # Represents infinity, for the +to_ranges+ function.
43
+ #
44
+ Infinity = (1.0 / 0)
49
45
 
50
- #
51
- # A class method for +to_ranges+. Deprecated in favor of the instance method.
52
- #
53
- def self.to_ranges str, args = Hash.new
54
- str.to_ranges args
55
- end
46
+ # :stopdoc:
47
+ # from (maybe to this)
48
+ RANGE_REGEXP = %r{^ \s* (\d*) (?: \s* (\-|\.\.) \s* (\d*) )? \s* $ }x
49
+ # :startdoc:
56
50
 
57
- #
58
- # Splits num into array of ranges, limiting itself to +args[:min]+ and +args[:max]+,
59
- # if specified. The +args[:collapse]+, if true, results in sequential values put
60
- # into the same range.
61
- #
62
- # Examples:
63
- #
64
- # "1,2".to_ranges # [ 1 .. 1, 2 .. 2 ]
65
- # "1,2".to_ranges :collapse => true # [ 1 .. 2 ]
66
- # "1-4".to_ranges # [ 1 .. 4 ]
67
- # "1-3,5-6,10,11,12,".to_ranges :collapse => true # [ 1 .. 3, 5 .. 6, 10 .. 12 ]
68
- # "1-3,5-6,10,11,12,".to_ranges # [ 1 .. 3, 5 .. 6, 10 .. 10, 11 .. 11, 12 .. 12 ]
69
- # "-4".to_ranges # [ -String::Infinity .. 4 ]
70
- # "4-".to_ranges # [ 4 .. String::Infinity ]
71
- # "1-".to_ranges :min => 0, :max => 8 # [ 1 .. 8 ]
72
- #
73
- def to_ranges args = Hash.new
74
- min = args[:min] || -Infinity
75
- max = args[:max] || Infinity
76
- collapse = args[:collapse]
77
-
78
- ranges = Array.new
79
- self.split(%r{\s*,\s*}).each do |section|
80
- md = section.match(RANGE_REGEXP)
81
- next unless md
51
+ #
52
+ # Splits num into array of ranges, limiting itself to +args[:min]+ and +args[:max]+,
53
+ # if specified. The +args[:collapse]+, if true, results in sequential values put
54
+ # into the same range.
55
+ #
56
+ # Examples:
57
+ #
58
+ # "1,2".to_ranges # [ 1 .. 1, 2 .. 2 ]
59
+ # "1,2".to_ranges :collapse => true # [ 1 .. 2 ]
60
+ # "1-4".to_ranges # [ 1 .. 4 ]
61
+ # "1-3,5-6,10,11,12,".to_ranges :collapse => true # [ 1 .. 3, 5 .. 6, 10 .. 12 ]
62
+ # "1-3,5-6,10,11,12,".to_ranges # [ 1 .. 3, 5 .. 6, 10 .. 10, 11 .. 11, 12 .. 12 ]
63
+ # "-4".to_ranges # [ -String::Infinity .. 4 ]
64
+ # "4-".to_ranges # [ 4 .. String::Infinity ]
65
+ # "1-".to_ranges :min => 0, :max => 8 # [ 1 .. 8 ]
66
+ #
67
+ def to_ranges args = Hash.new
68
+ min = args[:min] || -Infinity
69
+ max = args[:max] || Infinity
70
+ collapse = args[:collapse]
82
71
 
83
- from = String._matchdata_to_number md, 1, min
84
- to = String._has_matchdata?(md, 2) ? String._matchdata_to_number(md, 3, max) : from
72
+ ranges = Array.new
73
+ self.split(%r{\s*,\s*}).each do |section|
74
+ md = section.match(RANGE_REGEXP)
75
+ next unless md
76
+
77
+ from = _matchdata_to_number md, 1, min
78
+ to = _has_matchdata?(md, 2) ? _matchdata_to_number(md, 3, max) : from
85
79
 
86
- prevrange = ranges[-1]
80
+ prevrange = ranges[-1]
87
81
 
88
- if collapse && prevrange && prevrange.include?(from - 1) && prevrange.include?(to - 1)
89
- ranges[-1] = (prevrange.first .. to)
90
- else
91
- ranges << (from .. to)
82
+ if collapse && prevrange && prevrange.include?(from - 1) && prevrange.include?(to - 1)
83
+ ranges[-1] = (prevrange.first .. to)
84
+ else
85
+ ranges << (from .. to)
86
+ end
92
87
  end
93
- end
94
88
 
95
- ranges
96
- end
89
+ ranges
90
+ end
97
91
 
98
- # :stopdoc:
99
- def self._has_matchdata? md, idx
100
- md && md[idx] && !md[idx].empty?
101
- end
92
+ # :stopdoc:
93
+ def _has_matchdata? md, idx
94
+ md && md[idx] && !md[idx].empty?
95
+ end
102
96
 
103
- def self._matchdata_to_number md, idx, default
104
- _has_matchdata?(md, idx) ? md[idx].to_i : default
97
+ def _matchdata_to_number md, idx, default
98
+ _has_matchdata?(md, idx) ? md[idx].to_i : default
99
+ end
100
+ # :startdoc:
105
101
  end
106
- # :startdoc:
107
102
  end
data/lib/riel/timer.rb CHANGED
@@ -1,17 +1,16 @@
1
1
  #!/usr/bin/ruby -w
2
2
  # -*- ruby -*-
3
3
 
4
- require 'riel/log'
4
+ require 'logue/log'
5
5
 
6
6
  class Timer
7
-
8
7
  def initialize what, args = Hash.new
9
8
  if args.kind_of? Fixnum
10
9
  args = { :level => args }
11
10
  end
12
11
 
13
12
  @io = args[:io] || $stdout
14
- @level = args[:level] || Log::DEBUG
13
+ @level = args[:level] || Logue::Log::DEBUG
15
14
 
16
15
  stmsg = args.include?(:startmsg) ? args[:startmsg] : "#{what} start time"
17
16
  endmsg = args.include?(:endmsg) ? args[:endmsg] : "#{what} end time"
@@ -34,19 +33,18 @@ class Timer
34
33
  if @io
35
34
  @io.puts "#{msg}: #{value}"
36
35
  else
37
- Log.log "#{msg}: #{value}", @level
36
+ Logue::Logue::Log.log "#{msg}: #{value}", @level
38
37
  end
39
38
  end
40
39
  end
41
-
42
40
  end
43
41
 
44
42
  def timethis what
45
43
  sttime = Time.new
46
- Log.log "#{what} start time: #{sttime}"
44
+ Logue::Log.log "#{what} start time: #{sttime}"
47
45
  yield
48
46
  endtime = Time.new
49
- Log.log "#{what} start time: #{sttime}"
50
- Log.log "#{what} end time : #{endtime}"
51
- Log.log "#{what} elapsed : #{endtime - sttime}"
47
+ Logue::Log.log "#{what} start time: #{sttime}"
48
+ Logue::Log.log "#{what} end time : #{endtime}"
49
+ Logue::Log.log "#{what} elapsed : #{endtime - sttime}"
52
50
  end
data/lib/riel.rb CHANGED
@@ -4,5 +4,5 @@ $:.unshift(riellibdir) unless
4
4
  $:.include?(riellibdir) || $:.include?(File.expand_path(riellibdir))
5
5
 
6
6
  module RIEL
7
- VERSION = '1.1.17'
7
+ VERSION = '1.2.0'
8
8
  end
@@ -4,6 +4,10 @@
4
4
  require 'test/unit'
5
5
  require 'riel/date'
6
6
 
7
+ class Date
8
+ include RIEL::DateExt
9
+ end
10
+
7
11
  class DateTestCase < Test::Unit::TestCase
8
12
  def run_date_test expected, year, month
9
13
  dim = Date.days_in_month(year, month)
@@ -6,6 +6,10 @@ require 'pathname'
6
6
  require 'riel/dir'
7
7
  require 'riel/file'
8
8
 
9
+ class Dir
10
+ include RIEL::DirExt
11
+ end
12
+
9
13
  class DirTestCase < Test::Unit::TestCase
10
14
  def test_home
11
15
  assert_equal ENV["HOME"], Dir.home