ruby_ex 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +177 -0
- data/NEWS +20 -11
- data/SPEC.dyn.yml +4 -4
- data/SPEC.gemspec +4 -4
- data/SPEC.yml +4 -1
- data/lib/cache.rb +2 -2
- data/lib/commands.rb +19 -1
- data/lib/commands/command.rb +5 -5
- data/lib/commands/datas/composite.rb +26 -4
- data/lib/commands/datas/data.rb +6 -5
- data/lib/commands/pipe.rb +55 -14
- data/lib/commands/runners/fork.rb +6 -2
- data/lib/commands/runners/{mock.rb → mockable.rb} +21 -22
- data/lib/commands/runners/runner.rb +13 -1
- data/lib/d_logger.rb +11 -5
- data/lib/diff_tools.rb +141 -0
- data/lib/drb/insecure_protected_methods.rb +2 -2
- data/lib/file_type.rb +29 -21
- data/lib/hookable.rb +17 -2
- data/lib/md5sum.rb +2 -2
- data/lib/module/autoload_tree.rb +2 -2
- data/lib/ordered_hash.rb +28 -1
- data/lib/regex_list.rb +192 -0
- data/lib/ruby_ex.rb +8 -5
- data/lib/sendmail.rb +8 -1
- data/lib/sym_tbl_gsub.rb +44 -18
- data/lib/uri/file.rb +2 -2
- data/lib/uri/ftp_ex.rb +2 -2
- data/lib/uri/http_ex.rb +2 -2
- data/lib/uri/ssh.rb +1 -1
- data/lib/uri/svn.rb +2 -2
- data/lib/uri_ex.rb +4 -7
- data/lib/yaml/chop_header.rb +1 -1
- data/test/check-pkg-ruby_ex.yml +5 -7
- data/test/check-ruby_ex.yml +6 -10
- data/test/{resources → fixtures}/autoload_tree/A.rb +0 -0
- data/test/{resources → fixtures}/autoload_tree/B.rb +0 -0
- data/test/{resources → fixtures}/autoload_tree/foo/C.rb +0 -0
- data/test/fixtures/foo.bz2 +0 -0
- data/test/fixtures/foo.gz.zip +0 -0
- data/test/fixtures/foo.rb.gz +0 -0
- data/test/fixtures/foo.tar +0 -0
- data/test/fixtures/foo.tar.bz2 +0 -0
- data/test/{resources → fixtures}/foo.tar.gz +0 -0
- data/test/{resources → fixtures}/foo.txt +0 -0
- data/test/fixtures/my_diff.patch +164 -0
- data/test/{resources → fixtures}/tar.gz.log +0 -0
- data/test/sanity/multiple-requires.yml +1 -1
- data/test/sanity/single-requires.yml +1 -1
- metadata +23 -16
    
        data/lib/hookable.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # Copyright:: Copyright (c) 2005  Nicolas Pouillard. All rights reserved.
         | 
| 2 2 | 
             
            # Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
         | 
| 3 3 | 
             
            # License::   Gnu General Public License.
         | 
| 4 | 
            -
            # Revision::  $Id: hookable.rb  | 
| 4 | 
            +
            # Revision::  $Id: hookable.rb 364 2005-09-24 17:18:48Z ertai $
         | 
| 5 5 |  | 
| 6 6 | 
             
            require 'hooker'
         | 
| 7 7 |  | 
| @@ -28,6 +28,8 @@ module Hookable | |
| 28 28 |  | 
| 29 29 |  | 
| 30 30 | 
             
                  def hook_trigger ( name, *args )
         | 
| 31 | 
            +
                    return if defined? @disabled_hooks and @disabled_hooks.include? name
         | 
| 32 | 
            +
                    return if defined? @@disabled_hooks and @@disabled_hooks.include? name
         | 
| 31 33 | 
             
                    self.class.hook_trigger(name, *args)
         | 
| 32 34 | 
             
                    return unless defined? @hookers
         | 
| 33 35 | 
             
                    @hookers.each do |hooker|
         | 
| @@ -38,6 +40,7 @@ module Hookable | |
| 38 40 |  | 
| 39 41 | 
             
                  def self.hook_trigger ( name, *args )
         | 
| 40 42 | 
             
                    raise ArgumentError, "Unknown hook #{name}" unless hooks.include? name
         | 
| 43 | 
            +
                    return if defined? @@disabled_hooks and @@disabled_hooks.include? name
         | 
| 41 44 | 
             
                    hookers.each do |hooker|
         | 
| 42 45 | 
             
                      @@hook_trigger_internal[hooker, name, *args]
         | 
| 43 46 | 
             
                    end
         | 
| @@ -65,6 +68,18 @@ module Hookable | |
| 65 68 | 
             
                  end
         | 
| 66 69 |  | 
| 67 70 |  | 
| 71 | 
            +
                  def disable_hook ( *hook_names )
         | 
| 72 | 
            +
                    @disabled_hooks ||= []
         | 
| 73 | 
            +
                    @disabled_hooks = @disabled_hooks + hook_names
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
             | 
| 77 | 
            +
                  def self.disable_hook ( *hook_names )
         | 
| 78 | 
            +
                    @@disabled_hooks ||= []
         | 
| 79 | 
            +
                    @@disabled_hooks = @@disabled_hooks + hook_names
         | 
| 80 | 
            +
                  end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
| 68 83 | 
             
                  def self.hook_declare ( name, *groups )
         | 
| 69 84 | 
             
                    hooks << name
         | 
| 70 85 | 
             
                  end
         | 
| @@ -95,7 +110,7 @@ module Hookable | |
| 95 110 | 
             
                end
         | 
| 96 111 | 
             
              end
         | 
| 97 112 |  | 
| 98 | 
            -
             | 
| 113 | 
            +
             | 
| 99 114 | 
             
              class HashWithRecursiveCloneDup < Hash
         | 
| 100 115 |  | 
| 101 116 | 
             
                def initialize_copy ( aHash )
         | 
    
        data/lib/md5sum.rb
    CHANGED
    
    | @@ -3,7 +3,7 @@ | |
| 3 3 | 
             
            # License: Gnu General Public License.
         | 
| 4 4 |  | 
| 5 5 | 
             
            # $LastChangedBy: ertai $
         | 
| 6 | 
            -
            # $Id: md5sum.rb  | 
| 6 | 
            +
            # $Id: md5sum.rb 376 2005-09-29 21:46:32Z ertai $
         | 
| 7 7 |  | 
| 8 8 |  | 
| 9 9 | 
             
            require 'md5'
         | 
| @@ -50,7 +50,7 @@ test_section __FILE__ do | |
| 50 50 | 
             
            class MD5SumTest < Test::Unit::TestCase
         | 
| 51 51 |  | 
| 52 52 | 
             
              def setup
         | 
| 53 | 
            -
                @source = __FILE__.to_path.dirname.parent + 'test/ | 
| 53 | 
            +
                @source = __FILE__.to_path.dirname.parent + 'test/fixtures/foo.txt'
         | 
| 54 54 | 
             
                @ref = '9508b4f53cff19cf42c5a0f0fc127602'
         | 
| 55 55 | 
             
              end
         | 
| 56 56 |  | 
    
        data/lib/module/autoload_tree.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # Copyright:: Copyright (c) 2004  Nicolas Despres. All rights reserved.
         | 
| 2 2 | 
             
            # Author::    Nicolas Despres  <polrop@lrde.epita.fr>.
         | 
| 3 3 | 
             
            # License::   Gnu General Public License.
         | 
| 4 | 
            -
            # Revision::  $Id: autoload_tree.rb  | 
| 4 | 
            +
            # Revision::  $Id: autoload_tree.rb 376 2005-09-29 21:46:32Z ertai $
         | 
| 5 5 |  | 
| 6 6 |  | 
| 7 7 | 
             
            module AutoloadTree
         | 
| @@ -42,7 +42,7 @@ module AutoloadTree | |
| 42 42 |  | 
| 43 43 | 
             
                class AutoloadTreeTest < Test::Unit::TestCase
         | 
| 44 44 |  | 
| 45 | 
            -
                  REPO_DIR = __FILE__.to_path.dirname.parent.parent + 'test/ | 
| 45 | 
            +
                  REPO_DIR = __FILE__.to_path.dirname.parent.parent + 'test/fixtures/autoload_tree'
         | 
| 46 46 |  | 
| 47 47 | 
             
                  module AutoloadTree; end
         | 
| 48 48 |  | 
    
        data/lib/ordered_hash.rb
    CHANGED
    
    | @@ -18,7 +18,7 @@ | |
| 18 18 | 
             
            #
         | 
| 19 19 |  | 
| 20 20 | 
             
            # $LastChangedBy: ertai $
         | 
| 21 | 
            -
            # $Id: ordered_hash.rb  | 
| 21 | 
            +
            # $Id: ordered_hash.rb 367 2005-09-24 19:53:40Z ertai $
         | 
| 22 22 |  | 
| 23 23 |  | 
| 24 24 | 
             
            module OrderedHash
         | 
| @@ -193,6 +193,27 @@ class OHash < Hash | |
| 193 193 | 
             
                hsh
         | 
| 194 194 | 
             
              end
         | 
| 195 195 |  | 
| 196 | 
            +
              have YamlExtension, :ordered_hash, :ohash, :o_hash
         | 
| 197 | 
            +
             | 
| 198 | 
            +
              def self.yaml_load ( val )
         | 
| 199 | 
            +
                case val
         | 
| 200 | 
            +
                when Hash
         | 
| 201 | 
            +
                  return OHash[val.to_a]
         | 
| 202 | 
            +
                when OHash
         | 
| 203 | 
            +
                  return val
         | 
| 204 | 
            +
                when Array
         | 
| 205 | 
            +
                  if val.all? { |x| x.is_a?(Hash) and x.size == 1 }
         | 
| 206 | 
            +
                    h = OHash.new
         | 
| 207 | 
            +
                    val.each do |x|
         | 
| 208 | 
            +
                      k, v = x
         | 
| 209 | 
            +
                      h[k] = v
         | 
| 210 | 
            +
                    end
         | 
| 211 | 
            +
                    return h
         | 
| 212 | 
            +
                  end
         | 
| 213 | 
            +
                end
         | 
| 214 | 
            +
                raise ArgumentError, "Cannot create a OHash with `#{val}'"
         | 
| 215 | 
            +
              end
         | 
| 216 | 
            +
             | 
| 196 217 | 
             
            end # class OHash
         | 
| 197 218 |  | 
| 198 219 |  | 
| @@ -283,6 +304,12 @@ test_section __FILE__ do | |
| 283 304 | 
             
                  assert_not_equal OHash[1,2,3,4], OHash[3,4,1,2]
         | 
| 284 305 | 
             
                end
         | 
| 285 306 |  | 
| 307 | 
            +
                def test_yaml_load ( aString, aClass, anObject=nil )
         | 
| 308 | 
            +
                end
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                def test_yaml_dump ( anObject, ref, options={} )
         | 
| 311 | 
            +
                end
         | 
| 312 | 
            +
             | 
| 286 313 | 
             
              end # OrderedHashTest
         | 
| 287 314 |  | 
| 288 315 | 
             
            end
         | 
    
        data/lib/regex_list.rb
    ADDED
    
    | @@ -0,0 +1,192 @@ | |
| 1 | 
            +
            # Copyright:: Copyright (c) 2005  Nicolas Pouillard. All rights reserved.
         | 
| 2 | 
            +
            # Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
         | 
| 3 | 
            +
            # License::   Gnu General Public License.
         | 
| 4 | 
            +
            # Revision::  $Id: regex_list.rb 379 2005-09-29 22:00:37Z ertai $
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class RegexList
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def initialize ( *args )
         | 
| 9 | 
            +
                @regexps = args.flatten
         | 
| 10 | 
            +
                @regexps.map! { |re| (re.is_a? Regexp)? re : Regexp.new(re) }
         | 
| 11 | 
            +
                @regexps.reverse!
         | 
| 12 | 
            +
                @scores = {}
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              if ENV['REGEXP_LIST_DEBUG']
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                @@h = HighLine.new
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def score ( aString )
         | 
| 20 | 
            +
                  if @scores.has_key? aString
         | 
| 21 | 
            +
                    result = @scores[aString]
         | 
| 22 | 
            +
                    action = '<%= color "Hit ", :green %>'
         | 
| 23 | 
            +
                  else
         | 
| 24 | 
            +
                    result = score_without_cache(aString)
         | 
| 25 | 
            +
                    action = '<%= color "Miss", :red %>'
         | 
| 26 | 
            +
                    @scores[aString] = result
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                  @@h.say "#{action}: #{aString} -> #{result.inspect}"
         | 
| 29 | 
            +
                  result
         | 
| 30 | 
            +
                end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              else
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                # Perform a cache over +score_without_cache+
         | 
| 35 | 
            +
                def score ( aString )
         | 
| 36 | 
            +
                  return @scores[aString] if @scores.has_key? aString
         | 
| 37 | 
            +
                  return @scores[aString] = score_without_cache(aString)
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
              end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
              # Score represent a weighted sum of the match result with each regexp.
         | 
| 43 | 
            +
              #
         | 
| 44 | 
            +
              # 0: Not matched at all
         | 
| 45 | 
            +
              # 1: Just the last regexp matches (the Nth regexp)
         | 
| 46 | 
            +
              # 2: Just the (N - 1)th matches
         | 
| 47 | 
            +
              # 3: The Nth and the (N - 1)th
         | 
| 48 | 
            +
              # 2^(N - 1): Just the first one matches
         | 
| 49 | 
            +
              #
         | 
| 50 | 
            +
              # Formula:
         | 
| 51 | 
            +
              #   U(i <- 0 .. N - 1) is a vector with 1 when it matches and 0 otherwise
         | 
| 52 | 
            +
              #   Score = U(N - 1) * 2^(N - 1) + U(N - 2) * 2^(N - 2) + ... + U(0) * 2^0
         | 
| 53 | 
            +
              def score_without_cache ( aString )
         | 
| 54 | 
            +
                result = 0
         | 
| 55 | 
            +
                @regexps.each_with_index do |re, i|
         | 
| 56 | 
            +
                  result += 2 ** i if aString =~ re
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
                return result
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              def [] ( score )
         | 
| 62 | 
            +
                @regexps[score]
         | 
| 63 | 
            +
              end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
             | 
| 66 | 
            +
              module Assertions
         | 
| 67 | 
            +
                attr_accessor :regex_list
         | 
| 68 | 
            +
                def assert_regex_list_score ( input, ref, cache=true )
         | 
| 69 | 
            +
                  if cache
         | 
| 70 | 
            +
                    assert_equal ref, @regex_list.score(input)
         | 
| 71 | 
            +
                  else
         | 
| 72 | 
            +
                    assert_equal ref, @regex_list.score_without_cache(input)
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end # module Assertions
         | 
| 76 | 
            +
             | 
| 77 | 
            +
             | 
| 78 | 
            +
              # PathList Extension which gives sorting/filtering features to PathList
         | 
| 79 | 
            +
              module PathListExtension
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                def sort_with_regex_list! ( regex_list )
         | 
| 82 | 
            +
                  sort! { |x, y| regex_list.score(y.to_s) <=> regex_list.score(x.to_s) }
         | 
| 83 | 
            +
                end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                def grep_with_regex_list! ( regex_list )
         | 
| 86 | 
            +
                  reject! { |x| regex_list.score(x.to_s).zero? }
         | 
| 87 | 
            +
                  sort_with_regex_list! regex_list
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
             | 
| 90 | 
            +
                def grep_with_negative_regex_list! ( regex_list )
         | 
| 91 | 
            +
                  sort_with_regex_list! regex_list
         | 
| 92 | 
            +
                  reverse!
         | 
| 93 | 
            +
                end
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                def exclude_with_regex_list! ( regex_list )
         | 
| 96 | 
            +
                  reject! { |x| not regex_list.score(x.to_s).zero? }
         | 
| 97 | 
            +
                  self
         | 
| 98 | 
            +
                end
         | 
| 99 | 
            +
             | 
| 100 | 
            +
                def self.dup_based_method ( meth )
         | 
| 101 | 
            +
                  define_method(meth) { |regex_list| dup.send(meth.to_s + '!', regex_list) }
         | 
| 102 | 
            +
                end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                dup_based_method :sort_with_regex_list
         | 
| 105 | 
            +
                dup_based_method :grep_with_regex_list
         | 
| 106 | 
            +
                dup_based_method :grep_with_negative_regex_list
         | 
| 107 | 
            +
                dup_based_method :exclude_with_regex_list
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                module Assertions
         | 
| 110 | 
            +
                  attr_reader :path_list
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                  RegexList::PathListExtension.instance_methods.each do |meth|
         | 
| 113 | 
            +
                    define_method('assert_' + meth.to_s) do |ref, input|
         | 
| 114 | 
            +
                      input = RegexList.new(input) unless input.is_a? RegexList
         | 
| 115 | 
            +
                      ref = PathList.new(ref) unless ref.is_a? PathList
         | 
| 116 | 
            +
                      assert_nothing_raised { @result = @path_list.send(meth, input) }
         | 
| 117 | 
            +
                      assert_kind_of(PathList, @result)
         | 
| 118 | 
            +
                      assert_equal(ref.stringify, @result.stringify)
         | 
| 119 | 
            +
                    end
         | 
| 120 | 
            +
                  end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                end # module Assertions
         | 
| 123 | 
            +
             | 
| 124 | 
            +
              end # module PathListExtension
         | 
| 125 | 
            +
             | 
| 126 | 
            +
            end # class RegexList
         | 
| 127 | 
            +
             | 
| 128 | 
            +
            PathList.import!
         | 
| 129 | 
            +
            class PathList
         | 
| 130 | 
            +
              include RegexList::PathListExtension
         | 
| 131 | 
            +
            end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
             | 
| 134 | 
            +
            test_section __FILE__ do
         | 
| 135 | 
            +
             | 
| 136 | 
            +
              class TestRegexList < ::Test::Unit::TestCase
         | 
| 137 | 
            +
                include RegexList::Assertions
         | 
| 138 | 
            +
             | 
| 139 | 
            +
                def setup
         | 
| 140 | 
            +
                  assert_nothing_raised do
         | 
| 141 | 
            +
                    @regex_list = RegexList.new %w[ a/abc b/foo fg kb c/a a/bar f ]
         | 
| 142 | 
            +
                  end
         | 
| 143 | 
            +
                end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                def teardown
         | 
| 146 | 
            +
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                def test_0_initialize
         | 
| 149 | 
            +
                end
         | 
| 150 | 
            +
             | 
| 151 | 
            +
                def test_score_without_cache
         | 
| 152 | 
            +
                  assert_regex_list_score 'a', 0
         | 
| 153 | 
            +
                  assert_regex_list_score 'a/abc', 64
         | 
| 154 | 
            +
                  assert_regex_list_score 'kb', 8
         | 
| 155 | 
            +
                  assert_regex_list_score 'f', 1
         | 
| 156 | 
            +
                  assert_regex_list_score 'a/abc/fg', 81
         | 
| 157 | 
            +
                  assert_regex_list_score 'kb/foo', 41
         | 
| 158 | 
            +
                  assert_regex_list_score 'a/abc b/foo fg kb c/a a/bar f', 127
         | 
| 159 | 
            +
                  assert_regex_list_score 'a/abca/abca/abca/abc', 64
         | 
| 160 | 
            +
                end
         | 
| 161 | 
            +
             | 
| 162 | 
            +
              end # class TestRegexList
         | 
| 163 | 
            +
             | 
| 164 | 
            +
             | 
| 165 | 
            +
              class TestPathListRegexListExtension < ::Test::Unit::TestCase
         | 
| 166 | 
            +
                include RegexList::PathListExtension::Assertions
         | 
| 167 | 
            +
             | 
| 168 | 
            +
                def setup
         | 
| 169 | 
            +
                  @path_list = PathList.new %w[ a a/b a/c a/bc b/foo fg kb c/a a/bar f ]
         | 
| 170 | 
            +
                end
         | 
| 171 | 
            +
             | 
| 172 | 
            +
                def test_sort_with_regex_list
         | 
| 173 | 
            +
                  assert_sort_with_regex_list(%w[ f b/foo fg a/bc a/c a/b kb c/a a/bar a ], %w[ f ])
         | 
| 174 | 
            +
                end
         | 
| 175 | 
            +
             | 
| 176 | 
            +
                def test_grep_with_regex_list
         | 
| 177 | 
            +
                  assert_grep_with_regex_list(%w[ b/foo fg f ], %w[ f ])
         | 
| 178 | 
            +
                  assert_grep_with_regex_list(%w[ a/b a/bc b/foo kb a/bar ], %w[ b ])
         | 
| 179 | 
            +
                  assert_grep_with_regex_list(%w[ b/foo a/b a/bc a/bar kb fg f ], %w[ b f ])
         | 
| 180 | 
            +
                end
         | 
| 181 | 
            +
             | 
| 182 | 
            +
                def test_grep_with_negative_regex_list
         | 
| 183 | 
            +
                  assert_grep_with_negative_regex_list(%w[f a/bar a/b kb a b/foo fg a/bc c/a a/c ], %w[ c ])
         | 
| 184 | 
            +
                end
         | 
| 185 | 
            +
             | 
| 186 | 
            +
                def test_exclude_with_regex_list
         | 
| 187 | 
            +
                  assert_exclude_with_regex_list(%w[ a a/b a/c a/bc kb c/a a/bar ], %w[ f ])
         | 
| 188 | 
            +
                end
         | 
| 189 | 
            +
             | 
| 190 | 
            +
              end # class TestPathListRegexListExtension
         | 
| 191 | 
            +
             | 
| 192 | 
            +
            end
         | 
    
        data/lib/ruby_ex.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # Copyright:: Copyright (c) 2005  Nicolas Pouillard. All rights reserved.
         | 
| 2 2 | 
             
            # Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
         | 
| 3 3 | 
             
            # License::   Gnu General Public License.
         | 
| 4 | 
            -
            # Revision::  $Id: ruby_ex.rb  | 
| 4 | 
            +
            # Revision::  $Id: ruby_ex.rb 385 2005-10-02 17:05:35Z ertai $
         | 
| 5 5 |  | 
| 6 6 | 
             
            require 'pathname'
         | 
| 7 7 |  | 
| @@ -35,13 +35,16 @@ module RubyEx | |
| 35 35 |  | 
| 36 36 |  | 
| 37 37 | 
             
              unless defined? CoreEx
         | 
| 38 | 
            -
                 | 
| 39 | 
            -
                 | 
| 38 | 
            +
                vendor = dir.parent + 'vendor'
         | 
| 39 | 
            +
                $CORE_EX_VENDORS ||= []
         | 
| 40 | 
            +
                $CORE_EX_VENDORS << vendor
         | 
| 41 | 
            +
                file = vendor + 'core_ex' + 'lib' + 'core_ex'
         | 
| 42 | 
            +
                if file.exist?
         | 
| 43 | 
            +
                  require file.to_s
         | 
| 44 | 
            +
                else
         | 
| 40 45 | 
             
                  require 'rubygems'
         | 
| 41 46 | 
             
                  require_gem 'core_ex'
         | 
| 42 47 | 
             
                  require 'core_ex'
         | 
| 43 | 
            -
                else
         | 
| 44 | 
            -
                  require file
         | 
| 45 48 | 
             
                end
         | 
| 46 49 | 
             
              end
         | 
| 47 50 | 
             
              suppress(LoadError) { core_ex_require 'highline' }
         | 
    
        data/lib/sendmail.rb
    CHANGED
    
    | @@ -23,6 +23,7 @@ class Sendmail | |
| 23 23 | 
             
                  :from => email,
         | 
| 24 24 | 
             
                  :to => [],
         | 
| 25 25 | 
             
                  :server => ENV['SMTPSERVER'] || 'localhost:25',
         | 
| 26 | 
            +
                  :header => {},
         | 
| 26 27 | 
             
                  :body => STDIN
         | 
| 27 28 | 
             
                )
         | 
| 28 29 | 
             
                string_args, hash_args = args.partition { |x| x.is_a?(String) }
         | 
| @@ -59,6 +60,9 @@ class Sendmail | |
| 59 60 | 
             
                  opts.on('--comment STRING', 'Choose a comment for GPG') do |aComment|
         | 
| 60 61 | 
             
                    options.comment = aComment
         | 
| 61 62 | 
             
                  end
         | 
| 63 | 
            +
                  opts.on('--header STRING', 'Add some header fields (Yaml syntax)') do |s|
         | 
| 64 | 
            +
                    options.header = YAML.load(s)
         | 
| 65 | 
            +
                  end
         | 
| 62 66 | 
             
                  opts.on('-m', '--[no-]mime', 'Choose the mime protocole') do |mime|
         | 
| 63 67 | 
             
                    options.mime = mime
         | 
| 64 68 | 
             
                  end
         | 
| @@ -107,7 +111,7 @@ class Sendmail | |
| 107 111 | 
             
                    |Send a mail, with this subject: #{opts.subject}
         | 
| 108 112 | 
             
                    |  to #{opts.to.join(', ')}
         | 
| 109 113 | 
             
                    |  from #{opts.from_name}
         | 
| 110 | 
            -
                    |  #{(opts.signed | 
| 114 | 
            +
                    |  #{(opts.signed)? 'signed by ' + opts.from : 'not signed !'}
         | 
| 111 115 | 
             
                    |Are you sure? (y/n)].head_cut!
         | 
| 112 116 | 
             
                  raise 'Aborting' unless HighLine.new.agree question, true
         | 
| 113 117 | 
             
                end
         | 
| @@ -118,6 +122,9 @@ class Sendmail | |
| 118 122 | 
             
                    f.print %Q[From: #{opts.from_name}
         | 
| 119 123 | 
             
                              |Subject: #{opts.subject}
         | 
| 120 124 | 
             
                              |To: #{opts.to.join(', ')}\n].head_cut!
         | 
| 125 | 
            +
                    opts.header.each do |k, v|
         | 
| 126 | 
            +
                      f.puts "#{k}: #{v}"
         | 
| 127 | 
            +
                    end
         | 
| 121 128 | 
             
                    if opts.signed
         | 
| 122 129 | 
             
                      TempPath.new do |mail_body|
         | 
| 123 130 | 
             
                        mail_body.open('w') do |out|
         | 
    
        data/lib/sym_tbl_gsub.rb
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            # Author::    Nicolas Pouillard  <ertai@lrde.epita.fr>.
         | 
| 2 2 | 
             
            # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
         | 
| 3 3 | 
             
            # License::   Ruby License
         | 
| 4 | 
            -
            # Revision::  $Id: sym_tbl_gsub.rb  | 
| 4 | 
            +
            # Revision::  $Id: sym_tbl_gsub.rb 376 2005-09-29 21:46:32Z ertai $
         | 
| 5 5 |  | 
| 6 6 | 
             
            require 'sym_tbl'
         | 
| 7 7 |  | 
| @@ -139,18 +139,30 @@ end # class String | |
| 139 139 |  | 
| 140 140 | 
             
            PathList.import!
         | 
| 141 141 | 
             
            class PathList
         | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
               | 
| 145 | 
            -
             | 
| 142 | 
            +
              attr_accessor :symtbl
         | 
| 143 | 
            +
             | 
| 144 | 
            +
              alias_method :add_matching_without_expand, :add_matching
         | 
| 145 | 
            +
              def add_matching (pattern )
         | 
| 146 | 
            +
                @pending_reject ||= []
         | 
| 147 | 
            +
                if defined? @symtbl and @symtbl
         | 
| 148 | 
            +
                  pattern = pattern.do_symtbl_gsub(@symtbl)
         | 
| 149 | 
            +
                else
         | 
| 150 | 
            +
                  if pattern.to_s =~ /<<.*>>/ and not @pending_reject.include? pattern
         | 
| 151 | 
            +
                    @pending_reject << pattern
         | 
| 152 | 
            +
                    return
         | 
| 153 | 
            +
                  end
         | 
| 154 | 
            +
                end
         | 
| 146 155 | 
             
                add_matching_without_expand pattern
         | 
| 147 156 | 
             
              end
         | 
| 148 157 | 
             
              protected :add_matching
         | 
| 149 158 |  | 
| 150 159 | 
             
              def symtbl_gsub! ( symtbl )
         | 
| 151 | 
            -
                @ | 
| 160 | 
            +
                @pending_add += @pending_reject if defined? @pending_reject
         | 
| 161 | 
            +
                @pending_reject = []
         | 
| 162 | 
            +
                @pending = ! @pending_add.empty?
         | 
| 163 | 
            +
                @symtbl = symtbl
         | 
| 152 164 | 
             
                map! { |path| path.do_symtbl_gsub(symtbl) }
         | 
| 153 | 
            -
                @ | 
| 165 | 
            +
                @symtbl = nil
         | 
| 154 166 | 
             
                self
         | 
| 155 167 | 
             
              end
         | 
| 156 168 |  | 
| @@ -168,12 +180,13 @@ module SymTblGsub | |
| 168 180 | 
             
                class SymTblGsubTest < Test::Unit::TestCase
         | 
| 169 181 | 
             
                  def setup
         | 
| 170 182 | 
             
                    @s = SymTbl.new(
         | 
| 171 | 
            -
                      :foo | 
| 172 | 
            -
                      :bar | 
| 173 | 
            -
             | 
| 174 | 
            -
                      :i | 
| 175 | 
            -
                      :j | 
| 176 | 
            -
                      :pwd | 
| 183 | 
            +
                      :foo  => :bar,
         | 
| 184 | 
            +
                      :bar  => [1, 2],
         | 
| 185 | 
            +
                       3    => 'foo',
         | 
| 186 | 
            +
                      :i    => '<<j>>',
         | 
| 187 | 
            +
                      :j    => '<<3>>',
         | 
| 188 | 
            +
                      :pwd  => __FILE__.to_path.dirname.to_s,
         | 
| 189 | 
            +
                      :test => '<<pwd>>/../test'
         | 
| 177 190 | 
             
                    )
         | 
| 178 191 | 
             
                  end
         | 
| 179 192 | 
             
                  def assert_symtbl ( my, ref=nil )
         | 
| @@ -213,15 +226,28 @@ module SymTblGsub | |
| 213 226 | 
             
                  end
         | 
| 214 227 | 
             
                  def test_pathlist
         | 
| 215 228 | 
             
                    pathlist = ['<<foo>>', '<<i>>'.to_path]
         | 
| 216 | 
            -
                    ls1 = '<<bing>>/../test'.to_path + ' | 
| 217 | 
            -
                    ls2 = '<<pwd>>/../test'.to_path + ' | 
| 218 | 
            -
                     | 
| 229 | 
            +
                    ls1 = '<<bing>>/../test'.to_path + 'fixtures/autoload_tree/*.rb'
         | 
| 230 | 
            +
                    ls2 = '<<pwd>>/../test'.to_path + 'fixtures/autoload_tree/*.rb'
         | 
| 231 | 
            +
                    ls3 = '<<test>>'.to_path + 'fixtures/foo.{tar*,bz*}'
         | 
| 232 | 
            +
                    pathlist << ls2 << ls1 << ls3
         | 
| 219 233 | 
             
                    my = PathList[pathlist].symtbl_gsub(@s).map! { |x| x.basename }
         | 
| 220 234 | 
             
                    my.all? { |x| assert_kind_of(Pathname, x) }
         | 
| 221 | 
            -
                    ref = %w[ bar foo A.rb B.rb ]
         | 
| 235 | 
            +
                    ref = %w[ bar foo A.rb B.rb foo.bz2 foo.tar foo.tar.bz2 foo.tar.gz ]
         | 
| 236 | 
            +
                    assert_equal ref.to_set, my.map!{ |x| x.to_s }.to_set
         | 
| 237 | 
            +
                  end
         | 
| 238 | 
            +
                  def test_pathlist_keep_pending
         | 
| 239 | 
            +
                    pathlist = ['<<foo>>', '<<i>>'.to_path]
         | 
| 240 | 
            +
                    pathlist << '<<bing>>/../test'.to_path + 'fixtures/autoload_tree/*.rb'
         | 
| 241 | 
            +
                    pathlist << '<<pwd>>/../test'.to_path + 'fixtures/autoload_tree/*.rb'
         | 
| 242 | 
            +
                    pathlist << '<<test>>'.to_path + 'fixtures/foo.{tar*,bz*}'
         | 
| 243 | 
            +
                    pathlist = PathList[pathlist]
         | 
| 244 | 
            +
                    assert_equal(['<<foo>>'.to_path, '<<i>>'.to_path], pathlist)
         | 
| 245 | 
            +
                    my = pathlist.symtbl_gsub(@s).map! { |x| x.basename }
         | 
| 246 | 
            +
                    my.all? { |x| assert_kind_of(Pathname, x) }
         | 
| 247 | 
            +
                    ref = %w[ bar foo A.rb B.rb foo.bz2 foo.tar foo.tar.bz2 foo.tar.gz ]
         | 
| 222 248 | 
             
                    assert_equal ref.to_set, my.map!{ |x| x.to_s }.to_set
         | 
| 223 249 | 
             
                  end
         | 
| 224 250 | 
             
                end # class SymTblGsubTest
         | 
| 225 251 | 
             
              end
         | 
| 226 252 |  | 
| 227 | 
            -
            end # module SymTblGsub
         | 
| 253 | 
            +
            end # module SymTblGsub
         |