configuration 0.0.5 → 1.1.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/README +15 -68
- data/README.erb +69 -0
- data/Rakefile +241 -0
- data/config/e.rb +1 -1
- data/configuration.gemspec +28 -0
- data/lib/configuration.rb +32 -10
- metadata +10 -10
- data/gemspec.rb +0 -35
- data/gen_readme.rb +0 -37
- data/install.rb +0 -214
    
        data/README
    CHANGED
    
    | @@ -80,14 +80,6 @@ SAMPLES | |
| 80 80 |  | 
| 81 81 | 
             
                  p c.a + c.b - c.c
         | 
| 82 82 |  | 
| 83 | 
            -
              ~ > cat config/a.rb
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                Configuration.for('a'){
         | 
| 86 | 
            -
                  a 40
         | 
| 87 | 
            -
                  b 4
         | 
| 88 | 
            -
                  c 2
         | 
| 89 | 
            -
                }
         | 
| 90 | 
            -
             | 
| 91 83 | 
             
              ~ > ruby samples/a.rb
         | 
| 92 84 |  | 
| 93 85 | 
             
                42
         | 
| @@ -109,28 +101,6 @@ SAMPLES | |
| 109 101 | 
             
                  p c.db.url
         | 
| 110 102 | 
             
                  p c.mail.url
         | 
| 111 103 |  | 
| 112 | 
            -
              ~ > cat config/b.rb
         | 
| 113 | 
            -
             | 
| 114 | 
            -
                Configuration.for('b'){
         | 
| 115 | 
            -
                  host "codeforpeople.com"
         | 
| 116 | 
            -
                
         | 
| 117 | 
            -
                  www {
         | 
| 118 | 
            -
                    port 80
         | 
| 119 | 
            -
                    url "http://#{ host }:#{ port }"
         | 
| 120 | 
            -
                  }
         | 
| 121 | 
            -
                
         | 
| 122 | 
            -
                  db {
         | 
| 123 | 
            -
                    port 5342 
         | 
| 124 | 
            -
                    url "db://#{ host }:#{ port }"
         | 
| 125 | 
            -
                  }
         | 
| 126 | 
            -
                
         | 
| 127 | 
            -
                  mail {
         | 
| 128 | 
            -
                    host "gmail.com"
         | 
| 129 | 
            -
                    port 25 
         | 
| 130 | 
            -
                    url "mail://#{ host }:#{ port }"
         | 
| 131 | 
            -
                  }
         | 
| 132 | 
            -
                }
         | 
| 133 | 
            -
             | 
| 134 104 | 
             
              ~ > ruby samples/b.rb
         | 
| 135 105 |  | 
| 136 106 | 
             
                "http://codeforpeople.com:80"
         | 
| @@ -154,17 +124,6 @@ SAMPLES | |
| 154 124 | 
             
                  p Configuration.for('production').db
         | 
| 155 125 | 
             
                  p Configuration.for('testing').db
         | 
| 156 126 |  | 
| 157 | 
            -
              ~ > cat config/c.rb
         | 
| 158 | 
            -
             | 
| 159 | 
            -
                %w( development production testing ).each do |environment|
         | 
| 160 | 
            -
                
         | 
| 161 | 
            -
                  Configuration.for(environment){
         | 
| 162 | 
            -
                    adapter "sqlite3"
         | 
| 163 | 
            -
                    db "db/#{ environment }"
         | 
| 164 | 
            -
                  }
         | 
| 165 | 
            -
                
         | 
| 166 | 
            -
                end
         | 
| 167 | 
            -
             | 
| 168 127 | 
             
              ~ > ruby samples/c.rb
         | 
| 169 128 |  | 
| 170 129 | 
             
                "db/development"
         | 
| @@ -191,19 +150,22 @@ SAMPLES | |
| 191 150 | 
             
                  p c.inspect
         | 
| 192 151 | 
             
                  p c.p
         | 
| 193 152 |  | 
| 194 | 
            -
              ~ > cat config/d.rb
         | 
| 195 | 
            -
             | 
| 196 | 
            -
                Configuration.for('d'){
         | 
| 197 | 
            -
                  object_id 42
         | 
| 198 | 
            -
                  inspect 'forty-two'
         | 
| 199 | 
            -
                  p 42.0
         | 
| 200 | 
            -
                }
         | 
| 201 | 
            -
             | 
| 202 153 | 
             
              ~ > ruby samples/d.rb
         | 
| 203 154 |  | 
| 204 | 
            -
                 | 
| 205 | 
            -
             | 
| 206 | 
            -
             | 
| 155 | 
            +
                config/d.rb:2:in `object_id': wrong number of arguments (1 for 0) (ArgumentError)
         | 
| 156 | 
            +
                	from config/d.rb:2
         | 
| 157 | 
            +
                	from ./lib/configuration.rb:159:in `instance_eval'
         | 
| 158 | 
            +
                	from ./lib/configuration.rb:159:in `call'
         | 
| 159 | 
            +
                	from ./lib/configuration.rb:159:in `method_missing'
         | 
| 160 | 
            +
                	from ./lib/configuration.rb:105:in `evaluate'
         | 
| 161 | 
            +
                	from ./lib/configuration.rb:68:in `initialize'
         | 
| 162 | 
            +
                	from ./lib/configuration.rb:29:in `new'
         | 
| 163 | 
            +
                	from ./lib/configuration.rb:29:in `for'
         | 
| 164 | 
            +
                	from config/d.rb:1
         | 
| 165 | 
            +
                	from ./lib/configuration.rb:53:in `load'
         | 
| 166 | 
            +
                	from ./lib/configuration.rb:53:in `load'
         | 
| 167 | 
            +
                	from ./lib/configuration.rb:31:in `for'
         | 
| 168 | 
            +
                	from samples/d.rb:10
         | 
| 207 169 |  | 
| 208 170 |  | 
| 209 171 | 
             
              <========< samples/e.rb >========>
         | 
| @@ -223,22 +185,6 @@ SAMPLES | |
| 223 185 | 
             
                  p c.bar
         | 
| 224 186 | 
             
                  p c.foobar
         | 
| 225 187 |  | 
| 226 | 
            -
              ~ > cat config/e.rb
         | 
| 227 | 
            -
             | 
| 228 | 
            -
                Configuration.for('e'){
         | 
| 229 | 
            -
                  foo 42
         | 
| 230 | 
            -
                
         | 
| 231 | 
            -
                  if Send('respond_to?', 'foo')
         | 
| 232 | 
            -
                    bar 'forty-two'
         | 
| 233 | 
            -
                  end
         | 
| 234 | 
            -
                
         | 
| 235 | 
            -
                  respond_to = Method('bar')
         | 
| 236 | 
            -
                
         | 
| 237 | 
            -
                  if respond_to.call('bar')
         | 
| 238 | 
            -
                    foobar 42.0 
         | 
| 239 | 
            -
                  end
         | 
| 240 | 
            -
                }
         | 
| 241 | 
            -
             | 
| 242 188 | 
             
              ~ > ruby samples/e.rb
         | 
| 243 189 |  | 
| 244 190 | 
             
                42
         | 
| @@ -246,5 +192,6 @@ SAMPLES | |
| 246 192 | 
             
                42.0
         | 
| 247 193 |  | 
| 248 194 |  | 
| 195 | 
            +
             | 
| 249 196 | 
             
            AUTHOR
         | 
| 250 197 | 
             
              ara.t.howard@gmail.com
         | 
    
        data/README.erb
    ADDED
    
    | @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            NAME
         | 
| 2 | 
            +
              configuration.rb
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            SYNOPSIS
         | 
| 5 | 
            +
              pure ruby scoped configuration files
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            DESCRIPTION
         | 
| 8 | 
            +
              configuration.rb provides a mechanism for configuring ruby programs with
         | 
| 9 | 
            +
              ruby configuration files.  a configuration.rb file, for example
         | 
| 10 | 
            +
              'config/app.rb', can be written simply as
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  Configuration.for('app'){
         | 
| 13 | 
            +
                    key 'value'
         | 
| 14 | 
            +
                    foo 'bar'
         | 
| 15 | 
            +
                    port 42
         | 
| 16 | 
            +
                  }
         | 
| 17 | 
            +
              
         | 
| 18 | 
            +
              and loaded via the normal ruby require/load mechanism
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  Kernel.load 'config/app.rb'
         | 
| 21 | 
            +
              
         | 
| 22 | 
            +
              or with a slightly augmented loading mechnanism which simply searches an
         | 
| 23 | 
            +
              extra set of paths in *addition* to the standard ones
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  Configuration.path = %w( config configuration )
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  Configuration.load 'app'
         | 
| 28 | 
            +
             | 
| 29 | 
            +
              configurations are completely open
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  Configuration.for('app'){
         | 
| 32 | 
            +
                    object_id 'very open'
         | 
| 33 | 
            +
                  }
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              support arbitrarily nested values
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  Configuration.for('app'){
         | 
| 38 | 
            +
                    a { b { c { d 42 } } }
         | 
| 39 | 
            +
                  }
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  c = Configuration.for 'app'
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  p c.a.b.c.d #=> 42
         | 
| 44 | 
            +
             | 
| 45 | 
            +
              allow POLS scoped lookup of vars
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                Configuration.for('config'){
         | 
| 48 | 
            +
                  outer 'bar'
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  inner {
         | 
| 51 | 
            +
                    value 42
         | 
| 52 | 
            +
                  }
         | 
| 53 | 
            +
                }
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                c = Configuration.for 'config'
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                p c.outer       #=> 'bar'
         | 
| 58 | 
            +
                p c.inner.value #=> 42
         | 
| 59 | 
            +
                p c.inner.outer #=> 'bar' 
         | 
| 60 | 
            +
              
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              and not a whole lot else - configuration.rb is s very small library
         | 
| 63 | 
            +
              consisting of one file and < 150 loc
         | 
| 64 | 
            +
             | 
| 65 | 
            +
            SAMPLES
         | 
| 66 | 
            +
            <%= samples %>
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            AUTHOR
         | 
| 69 | 
            +
              ara.t.howard@gmail.com
         | 
    
        data/Rakefile
    ADDED
    
    | @@ -0,0 +1,241 @@ | |
| 1 | 
            +
            This.author = "Ara T. Howard"
         | 
| 2 | 
            +
            This.email = "ara.t.howard@gmail.com"
         | 
| 3 | 
            +
            This.homepage = "http://github.com/ahoward/#{ This.lib }/tree/master"
         | 
| 4 | 
            +
            This.rubyforge_project = 'codeforpeople'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            task :default do
         | 
| 7 | 
            +
              puts(Rake::Task.tasks.map{|task| task.name} - ['default'])
         | 
| 8 | 
            +
            end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
            task :spec do
         | 
| 11 | 
            +
              require 'spec/rake/spectask'
         | 
| 12 | 
            +
              Spec::Rake::SpecTask.new do |t|
         | 
| 13 | 
            +
                t.spec_files = FileList['spec/*_spec.rb']
         | 
| 14 | 
            +
              end
         | 
| 15 | 
            +
            end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            task :gemspec do
         | 
| 18 | 
            +
              ignore_extensions = 'git', 'svn', 'tmp', /sw./, 'bak', 'gem'
         | 
| 19 | 
            +
              ignore_directories = 'pkg'
         | 
| 20 | 
            +
              ignore_files = 'test/log'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              shiteless = 
         | 
| 23 | 
            +
                lambda do |list|
         | 
| 24 | 
            +
                  list.delete_if do |entry|
         | 
| 25 | 
            +
                    next unless test(?e, entry)
         | 
| 26 | 
            +
                    extension = File.basename(entry).split(%r/[.]/).last
         | 
| 27 | 
            +
                    ignore_extensions.any?{|ext| ext === extension}
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
                  list.delete_if do |entry|
         | 
| 30 | 
            +
                    next unless test(?d, entry)
         | 
| 31 | 
            +
                    dirname = File.expand_path(entry)
         | 
| 32 | 
            +
                    ignore_directories.any?{|dir| File.expand_path(dir) == dirname}
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
                  list.delete_if do |entry|
         | 
| 35 | 
            +
                    next unless test(?f, entry)
         | 
| 36 | 
            +
                    filename = File.expand_path(entry)
         | 
| 37 | 
            +
                    ignore_files.any?{|file| File.expand_path(file) == filename}
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              lib         = This.lib
         | 
| 42 | 
            +
              version     = This.version
         | 
| 43 | 
            +
              files       = shiteless[Dir::glob("**/**")]
         | 
| 44 | 
            +
              executables = shiteless[Dir::glob("bin/*")].map{|exe| File.basename(exe)}
         | 
| 45 | 
            +
              has_rdoc    = true #File.exist?('doc')
         | 
| 46 | 
            +
              test_files  = "test/#{ lib }.rb" if File.file?("test/#{ lib }.rb")
         | 
| 47 | 
            +
             | 
| 48 | 
            +
              extensions = This.extensions
         | 
| 49 | 
            +
              if extensions.nil?
         | 
| 50 | 
            +
                %w( Makefile configure extconf.rb ).each do |ext|
         | 
| 51 | 
            +
                  extensions << ext if File.exists?(ext)
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
              end
         | 
| 54 | 
            +
              extensions = [extensions].flatten.compact
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              template = 
         | 
| 57 | 
            +
                if test(?e, 'gemspec.erb')
         | 
| 58 | 
            +
                  Template{ IO.read('gemspec.erb') }
         | 
| 59 | 
            +
                else
         | 
| 60 | 
            +
                  Template {
         | 
| 61 | 
            +
                    <<-__
         | 
| 62 | 
            +
                      ## #{ lib }.gemspec
         | 
| 63 | 
            +
                      #
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                      Gem::Specification::new do |spec|
         | 
| 66 | 
            +
                        spec.name = #{ lib.inspect }
         | 
| 67 | 
            +
                        spec.version = #{ version.inspect }
         | 
| 68 | 
            +
                        spec.platform = Gem::Platform::RUBY
         | 
| 69 | 
            +
                        spec.summary = #{ lib.inspect }
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                        spec.files = #{ files.inspect }
         | 
| 72 | 
            +
                        spec.executables = #{ executables.inspect }
         | 
| 73 | 
            +
                        
         | 
| 74 | 
            +
                        <% if test(?d, 'lib') %>
         | 
| 75 | 
            +
                        spec.require_path = "lib"
         | 
| 76 | 
            +
                        <% end %>
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                        spec.has_rdoc = #{ has_rdoc.inspect }
         | 
| 79 | 
            +
                        spec.test_files = #{ test_files.inspect }
         | 
| 80 | 
            +
                        #spec.add_dependency 'lib', '>= version'
         | 
| 81 | 
            +
                        #spec.add_dependency 'fattr'
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                        spec.extensions.push(*#{ extensions.inspect })
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                        spec.rubyforge_project = #{ This.rubyforge_project.inspect }
         | 
| 86 | 
            +
                        spec.author = #{ This.author.inspect }
         | 
| 87 | 
            +
                        spec.email = #{ This.email.inspect }
         | 
| 88 | 
            +
                        spec.homepage = #{ This.homepage.inspect }
         | 
| 89 | 
            +
                      end
         | 
| 90 | 
            +
                    __
         | 
| 91 | 
            +
                  }
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              open("#{ lib }.gemspec", "w"){|fd| fd.puts template}
         | 
| 95 | 
            +
              This.gemspec = "#{ lib }.gemspec"
         | 
| 96 | 
            +
            end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
            task :gem => [:clean, :gemspec] do
         | 
| 99 | 
            +
              Fu.mkdir_p This.pkgdir
         | 
| 100 | 
            +
              before = Dir['*.gem']
         | 
| 101 | 
            +
              cmd = "gem build #{ This.gemspec }"
         | 
| 102 | 
            +
              `#{ cmd }`
         | 
| 103 | 
            +
              after = Dir['*.gem']
         | 
| 104 | 
            +
              gem = ((after - before).first || after.first) or abort('no gem!')
         | 
| 105 | 
            +
              Fu.mv gem, This.pkgdir
         | 
| 106 | 
            +
              This.gem = File.basename(gem)
         | 
| 107 | 
            +
            end
         | 
| 108 | 
            +
             | 
| 109 | 
            +
            task :readme do
         | 
| 110 | 
            +
              samples = ''
         | 
| 111 | 
            +
              prompt = '~ > '
         | 
| 112 | 
            +
              lib = This.lib
         | 
| 113 | 
            +
              version = This.version
         | 
| 114 | 
            +
             | 
| 115 | 
            +
              Dir['sample*/*'].sort.each do |sample|
         | 
| 116 | 
            +
                samples << "\n" << "  <========< #{ sample } >========>" << "\n\n"
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                cmd = "cat #{ sample }"
         | 
| 119 | 
            +
                samples << Util.indent(prompt + cmd, 2) << "\n\n"
         | 
| 120 | 
            +
                samples << Util.indent(`#{ cmd }`, 4) << "\n"
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                cmd = "ruby #{ sample }"
         | 
| 123 | 
            +
                samples << Util.indent(prompt + cmd, 2) << "\n\n"
         | 
| 124 | 
            +
             | 
| 125 | 
            +
                cmd = "ruby -e'STDOUT.sync=true; exec %(ruby -Ilib -Iconfig #{ sample })'"
         | 
| 126 | 
            +
                samples << Util.indent(`#{ cmd } 2>&1`, 4) << "\n"
         | 
| 127 | 
            +
              end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
              template = 
         | 
| 130 | 
            +
                if test(?e, 'readme.erb')
         | 
| 131 | 
            +
                  Template{ IO.read('readme.erb') }
         | 
| 132 | 
            +
                else
         | 
| 133 | 
            +
                  Template {
         | 
| 134 | 
            +
                    <<-__
         | 
| 135 | 
            +
                      NAME
         | 
| 136 | 
            +
                        #{ lib }
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                      DESCRIPTION
         | 
| 139 | 
            +
             | 
| 140 | 
            +
                      INSTALL
         | 
| 141 | 
            +
                        gem install #{ lib }
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                      SAMPLES
         | 
| 144 | 
            +
                        #{ samples }
         | 
| 145 | 
            +
                    __
         | 
| 146 | 
            +
                  }
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
              open("README", "w"){|fd| fd.puts template}
         | 
| 150 | 
            +
            end
         | 
| 151 | 
            +
             | 
| 152 | 
            +
             | 
| 153 | 
            +
            task :clean do
         | 
| 154 | 
            +
              Dir[File.join(This.pkgdir, '**/**')].each{|entry| Fu.rm_rf(entry)}
         | 
| 155 | 
            +
            end
         | 
| 156 | 
            +
             | 
| 157 | 
            +
             | 
| 158 | 
            +
            task :release => [:clean, :gemspec, :gem] do
         | 
| 159 | 
            +
              gems = Dir[File.join(This.pkgdir, '*.gem')].flatten
         | 
| 160 | 
            +
              raise "which one? : #{ gems.inspect }" if gems.size > 1
         | 
| 161 | 
            +
              raise "no gems?" if gems.size < 1
         | 
| 162 | 
            +
              cmd = "rubyforge login && rubyforge add_release #{ This.rubyforge_project } #{ This.lib } #{ This.version } #{ This.pkgdir }/#{ This.gem }"
         | 
| 163 | 
            +
              puts cmd
         | 
| 164 | 
            +
              system cmd
         | 
| 165 | 
            +
            end
         | 
| 166 | 
            +
             | 
| 167 | 
            +
             | 
| 168 | 
            +
             | 
| 169 | 
            +
             | 
| 170 | 
            +
             | 
| 171 | 
            +
            BEGIN {
         | 
| 172 | 
            +
              $VERBOSE = nil
         | 
| 173 | 
            +
             | 
| 174 | 
            +
              require 'ostruct'
         | 
| 175 | 
            +
              require 'erb'
         | 
| 176 | 
            +
              require 'fileutils'
         | 
| 177 | 
            +
             | 
| 178 | 
            +
              Fu = FileUtils
         | 
| 179 | 
            +
             | 
| 180 | 
            +
              This = OpenStruct.new
         | 
| 181 | 
            +
             | 
| 182 | 
            +
              This.file = File.expand_path(__FILE__)
         | 
| 183 | 
            +
              This.dir = File.dirname(This.file)
         | 
| 184 | 
            +
              This.pkgdir = File.join(This.dir, 'pkg')
         | 
| 185 | 
            +
             | 
| 186 | 
            +
              lib = ENV['LIB']
         | 
| 187 | 
            +
              unless lib
         | 
| 188 | 
            +
                lib = File.basename(Dir.pwd)
         | 
| 189 | 
            +
              end
         | 
| 190 | 
            +
              This.lib = lib
         | 
| 191 | 
            +
             | 
| 192 | 
            +
              version = ENV['VERSION']
         | 
| 193 | 
            +
              unless version
         | 
| 194 | 
            +
                name = lib.capitalize
         | 
| 195 | 
            +
                library = "./lib/#{ lib }.rb"
         | 
| 196 | 
            +
                program = "./bin/#{ lib }"
         | 
| 197 | 
            +
                if test(?e, library)
         | 
| 198 | 
            +
                  require library
         | 
| 199 | 
            +
                  version = eval(name).send(:version)
         | 
| 200 | 
            +
                elsif test(?e, program)
         | 
| 201 | 
            +
                  version = `#{ program } --version`.strip
         | 
| 202 | 
            +
                end
         | 
| 203 | 
            +
                abort('no version') if(version.nil? or version.empty?)
         | 
| 204 | 
            +
              end
         | 
| 205 | 
            +
              This.version = version
         | 
| 206 | 
            +
             | 
| 207 | 
            +
              abort('no lib') unless This.lib
         | 
| 208 | 
            +
              abort('no version') unless This.version
         | 
| 209 | 
            +
             | 
| 210 | 
            +
              module Util
         | 
| 211 | 
            +
                def indent(s, n = 2)
         | 
| 212 | 
            +
                  s = unindent(s)
         | 
| 213 | 
            +
                  ws = ' ' * n
         | 
| 214 | 
            +
                  s.gsub(%r/^/, ws)
         | 
| 215 | 
            +
                end
         | 
| 216 | 
            +
             | 
| 217 | 
            +
                def unindent(s)
         | 
| 218 | 
            +
                  indent = nil
         | 
| 219 | 
            +
                  s.each do |line|
         | 
| 220 | 
            +
                  next if line =~ %r/^\s*$/
         | 
| 221 | 
            +
                  indent = line[%r/^\s*/] and break
         | 
| 222 | 
            +
                end
         | 
| 223 | 
            +
                indent ? s.gsub(%r/^#{ indent }/, "") : s
         | 
| 224 | 
            +
              end
         | 
| 225 | 
            +
                extend self
         | 
| 226 | 
            +
              end
         | 
| 227 | 
            +
             | 
| 228 | 
            +
              class Template
         | 
| 229 | 
            +
                def initialize(&block)
         | 
| 230 | 
            +
                  @block = block
         | 
| 231 | 
            +
                  @template = block.call.to_s
         | 
| 232 | 
            +
                end
         | 
| 233 | 
            +
                def expand(b=nil)
         | 
| 234 | 
            +
                  ERB.new(Util.unindent(@template)).result(b||@block)
         | 
| 235 | 
            +
                end
         | 
| 236 | 
            +
                alias_method 'to_s', 'expand'
         | 
| 237 | 
            +
              end
         | 
| 238 | 
            +
              def Template(*args, &block) Template.new(*args, &block) end
         | 
| 239 | 
            +
             | 
| 240 | 
            +
              Dir.chdir(This.dir)
         | 
| 241 | 
            +
            }
         | 
    
        data/config/e.rb
    CHANGED
    
    
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            ## configuration.gemspec
         | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            Gem::Specification::new do |spec|
         | 
| 5 | 
            +
              spec.name = "configuration"
         | 
| 6 | 
            +
              spec.version = "1.1.0"
         | 
| 7 | 
            +
              spec.platform = Gem::Platform::RUBY
         | 
| 8 | 
            +
              spec.summary = "configuration"
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              spec.files = ["config", "config/a.rb", "config/b.rb", "config/c.rb", "config/d.rb", "config/e.rb", "configuration.gemspec", "lib", "lib/configuration.rb", "Rakefile", "README", "README.erb", "samples", "samples/a.rb", "samples/b.rb", "samples/c.rb", "samples/d.rb", "samples/e.rb"]
         | 
| 11 | 
            +
              spec.executables = []
         | 
| 12 | 
            +
              
         | 
| 13 | 
            +
              
         | 
| 14 | 
            +
              spec.require_path = "lib"
         | 
| 15 | 
            +
              
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              spec.has_rdoc = true
         | 
| 18 | 
            +
              spec.test_files = nil
         | 
| 19 | 
            +
              #spec.add_dependency 'lib', '>= version'
         | 
| 20 | 
            +
              #spec.add_dependency 'fattr'
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              spec.extensions.push(*[])
         | 
| 23 | 
            +
             | 
| 24 | 
            +
              spec.rubyforge_project = "codeforpeople"
         | 
| 25 | 
            +
              spec.author = "Ara T. Howard"
         | 
| 26 | 
            +
              spec.email = "ara.t.howard@gmail.com"
         | 
| 27 | 
            +
              spec.homepage = "http://github.com/ahoward/configuration/tree/master"
         | 
| 28 | 
            +
            end
         | 
    
        data/lib/configuration.rb
    CHANGED
    
    | @@ -1,7 +1,6 @@ | |
| 1 | 
            -
             | 
| 2 1 | 
             
            class Configuration
         | 
| 3 | 
            -
              Version = ' | 
| 4 | 
            -
              def Configuration.version() Version end
         | 
| 2 | 
            +
              Configuration::Version = '1.1.0'
         | 
| 3 | 
            +
              def Configuration.version() Configuration::Version end
         | 
| 5 4 |  | 
| 6 5 | 
             
              Path = [
         | 
| 7 6 | 
             
                if defined? CONFIGURATION_PATH
         | 
| @@ -76,14 +75,15 @@ class Configuration | |
| 76 75 | 
             
              end
         | 
| 77 76 | 
             
              send :include, InstanceMethods
         | 
| 78 77 |  | 
| 79 | 
            -
             | 
| 80 78 | 
             
              class DSL
         | 
| 79 | 
            +
                Protected = %r/^__|^object_id$/
         | 
| 80 | 
            +
             | 
| 81 81 | 
             
                instance_methods.each do |m|
         | 
| 82 | 
            -
                  undef_method m unless m[ | 
| 82 | 
            +
                  undef_method m unless m[Protected]
         | 
| 83 83 | 
             
                end 
         | 
| 84 84 |  | 
| 85 85 | 
             
                Kernel.methods.each do |m|
         | 
| 86 | 
            -
                  next if m[ | 
| 86 | 
            +
                  next if m[Protected]
         | 
| 87 87 | 
             
                  module_eval <<-code
         | 
| 88 88 | 
             
                    def #{ m }(*a, &b)
         | 
| 89 89 | 
             
                      method_missing '#{ m }', *a, &b
         | 
| @@ -101,7 +101,7 @@ class Configuration | |
| 101 101 |  | 
| 102 102 | 
             
                def self.evaluate configuration, options = {}, &block
         | 
| 103 103 | 
             
                  dsl = new configuration
         | 
| 104 | 
            -
                  Pure[dsl].instance_eval | 
| 104 | 
            +
                  Pure[dsl].instance_eval(&block) if block
         | 
| 105 105 | 
             
                  options.each{|key, value| Pure[dsl].send key, value}
         | 
| 106 106 | 
             
                  Pure[dsl].instance_eval{ @__configuration }
         | 
| 107 107 | 
             
                end
         | 
| @@ -118,7 +118,8 @@ class Configuration | |
| 118 118 | 
             
                  @__configuration
         | 
| 119 119 | 
             
                end
         | 
| 120 120 |  | 
| 121 | 
            -
                 | 
| 121 | 
            +
                undef_method(:method_missing) rescue nil
         | 
| 122 | 
            +
                def method_missing(m, *a, &b)
         | 
| 122 123 | 
             
                  if(a.empty? and b.nil?)
         | 
| 123 124 | 
             
                    return Pure[@__configuration].send(m, *a, &b)
         | 
| 124 125 | 
             
                  end
         | 
| @@ -143,14 +144,35 @@ class Configuration | |
| 143 144 | 
             
                    define_method(m){ value }
         | 
| 144 145 | 
             
                  end
         | 
| 145 146 | 
             
                end
         | 
| 147 | 
            +
             | 
| 148 | 
            +
                verbose = $VERBOSE
         | 
| 149 | 
            +
                begin
         | 
| 150 | 
            +
                  $VERBOSE = nil
         | 
| 151 | 
            +
                  def object_id(*args)
         | 
| 152 | 
            +
                    unless args.empty?
         | 
| 153 | 
            +
                      verbose = $VERBOSE
         | 
| 154 | 
            +
                      begin
         | 
| 155 | 
            +
                        $VERBOSE = nil
         | 
| 156 | 
            +
                        define_method(:object_id){ args.first }
         | 
| 157 | 
            +
                      ensure
         | 
| 158 | 
            +
                        $VERBOSE = verbose
         | 
| 159 | 
            +
                      end
         | 
| 160 | 
            +
                    else
         | 
| 161 | 
            +
                      return Pure[@__configuration].object_id
         | 
| 162 | 
            +
                    end
         | 
| 163 | 
            +
                  end
         | 
| 164 | 
            +
                ensure
         | 
| 165 | 
            +
                  $VERBOSE = verbose
         | 
| 166 | 
            +
                end
         | 
| 146 167 | 
             
              end
         | 
| 147 168 |  | 
| 148 | 
            -
              class Pure | 
| 169 | 
            +
              class Pure
         | 
| 149 170 | 
             
                Instance_Methods = Hash.new
         | 
| 171 | 
            +
                Protected = %r/^__|^object_id$/
         | 
| 150 172 |  | 
| 151 173 | 
             
                ::Object.instance_methods.each do |m|
         | 
| 152 174 | 
             
                  Instance_Methods[m.to_s] = ::Object.instance_method m
         | 
| 153 | 
            -
                  undef_method m unless m[ | 
| 175 | 
            +
                  undef_method m unless m[Protected]
         | 
| 154 176 | 
             
                end 
         | 
| 155 177 |  | 
| 156 178 | 
             
                def method_missing m, *a, &b
         | 
    
        metadata
    CHANGED
    
    | @@ -1,15 +1,15 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: configuration
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Ara T. Howard
         | 
| 8 | 
            -
            autorequire:  | 
| 8 | 
            +
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date:  | 
| 12 | 
            +
            date: 2009-09-23 00:00:00 -06:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: []
         | 
| 15 15 |  | 
| @@ -28,20 +28,20 @@ files: | |
| 28 28 | 
             
            - config/c.rb
         | 
| 29 29 | 
             
            - config/d.rb
         | 
| 30 30 | 
             
            - config/e.rb
         | 
| 31 | 
            -
            - gemspec | 
| 32 | 
            -
            - gen_readme.rb
         | 
| 33 | 
            -
            - install.rb
         | 
| 31 | 
            +
            - configuration.gemspec
         | 
| 34 32 | 
             
            - lib
         | 
| 35 33 | 
             
            - lib/configuration.rb
         | 
| 34 | 
            +
            - Rakefile
         | 
| 36 35 | 
             
            - README
         | 
| 36 | 
            +
            - README.erb
         | 
| 37 37 | 
             
            - samples
         | 
| 38 38 | 
             
            - samples/a.rb
         | 
| 39 39 | 
             
            - samples/b.rb
         | 
| 40 40 | 
             
            - samples/c.rb
         | 
| 41 41 | 
             
            - samples/d.rb
         | 
| 42 42 | 
             
            - samples/e.rb
         | 
| 43 | 
            -
            has_rdoc:  | 
| 44 | 
            -
            homepage: http:// | 
| 43 | 
            +
            has_rdoc: true
         | 
| 44 | 
            +
            homepage: http://github.com/ahoward/configuration/tree/master
         | 
| 45 45 | 
             
            post_install_message: 
         | 
| 46 46 | 
             
            rdoc_options: []
         | 
| 47 47 |  | 
| @@ -61,8 +61,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 61 61 | 
             
              version: 
         | 
| 62 62 | 
             
            requirements: []
         | 
| 63 63 |  | 
| 64 | 
            -
            rubyforge_project: 
         | 
| 65 | 
            -
            rubygems_version: 1. | 
| 64 | 
            +
            rubyforge_project: codeforpeople
         | 
| 65 | 
            +
            rubygems_version: 1.3.1
         | 
| 66 66 | 
             
            signing_key: 
         | 
| 67 67 | 
             
            specification_version: 2
         | 
| 68 68 | 
             
            summary: configuration
         | 
    
        data/gemspec.rb
    DELETED
    
    | @@ -1,35 +0,0 @@ | |
| 1 | 
            -
            lib, version = File::basename(File::dirname(File::expand_path(__FILE__))).split %r/-/, 2
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            require 'rubygems'
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            Gem::Specification::new do |spec|
         | 
| 6 | 
            -
              $VERBOSE = nil
         | 
| 7 | 
            -
             | 
| 8 | 
            -
              shiteless = lambda do |list|
         | 
| 9 | 
            -
                list.delete_if do |file|
         | 
| 10 | 
            -
                  file =~ %r/\.svn/ or
         | 
| 11 | 
            -
                  file =~ %r/\.tmp/
         | 
| 12 | 
            -
                end
         | 
| 13 | 
            -
              end
         | 
| 14 | 
            -
             | 
| 15 | 
            -
              spec.name = lib 
         | 
| 16 | 
            -
              spec.version = version 
         | 
| 17 | 
            -
              spec.platform = Gem::Platform::RUBY
         | 
| 18 | 
            -
              spec.summary = lib 
         | 
| 19 | 
            -
             | 
| 20 | 
            -
              spec.files = shiteless[Dir::glob("**/**")]
         | 
| 21 | 
            -
              spec.executables = shiteless[Dir::glob("bin/*")].map{|exe| File::basename exe}
         | 
| 22 | 
            -
              
         | 
| 23 | 
            -
              spec.require_path = "lib" 
         | 
| 24 | 
            -
              spec.autorequire = lib
         | 
| 25 | 
            -
             | 
| 26 | 
            -
              spec.has_rdoc = File::exist? "doc" 
         | 
| 27 | 
            -
              spec.test_suite_file = "test/#{ lib }.rb" if File::directory? "test"
         | 
| 28 | 
            -
              #spec.add_dependency 'lib', '>= version'
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              spec.extensions << "extconf.rb" if File::exists? "extconf.rb"
         | 
| 31 | 
            -
             | 
| 32 | 
            -
              spec.author = "Ara T. Howard"
         | 
| 33 | 
            -
              spec.email = "ara.t.howard@gmail.com"
         | 
| 34 | 
            -
              spec.homepage = "http://codeforpeople.com/lib/ruby/#{ lib }/"
         | 
| 35 | 
            -
            end
         | 
    
        data/gen_readme.rb
    DELETED
    
    | @@ -1,37 +0,0 @@ | |
| 1 | 
            -
            require 'pathname'
         | 
| 2 | 
            -
             | 
| 3 | 
            -
            $VERBOSE=nil
         | 
| 4 | 
            -
             | 
| 5 | 
            -
            def indent s, n = 2
         | 
| 6 | 
            -
              ws = ' ' * n
         | 
| 7 | 
            -
              s.gsub %r/^/, ws 
         | 
| 8 | 
            -
            end
         | 
| 9 | 
            -
             | 
| 10 | 
            -
            template = IO::read 'README.tmpl'
         | 
| 11 | 
            -
             | 
| 12 | 
            -
            samples = ''
         | 
| 13 | 
            -
            prompt = '~ > '
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            Dir['sample*/*'].sort.each do |sample|
         | 
| 16 | 
            -
              config = sample.gsub(%r/samples?/, 'config') 
         | 
| 17 | 
            -
              samples << "\n" << "  <========< #{ sample } >========>" << "\n\n"
         | 
| 18 | 
            -
             | 
| 19 | 
            -
              cmd = "cat #{ sample }" 
         | 
| 20 | 
            -
              samples << indent(prompt + cmd, 2) << "\n\n" 
         | 
| 21 | 
            -
              samples << indent(`#{ cmd }`, 4) << "\n" 
         | 
| 22 | 
            -
             | 
| 23 | 
            -
              cmd = "cat #{ config }" 
         | 
| 24 | 
            -
              samples << indent(prompt + cmd, 2) << "\n\n" 
         | 
| 25 | 
            -
              samples << indent(`#{ cmd }`, 4) << "\n" 
         | 
| 26 | 
            -
             | 
| 27 | 
            -
              cmd = "ruby #{ sample }" 
         | 
| 28 | 
            -
              samples << indent(prompt + cmd, 2) << "\n\n" 
         | 
| 29 | 
            -
             | 
| 30 | 
            -
              cmd = "ruby -Ilib -Iconfig #{ sample }" 
         | 
| 31 | 
            -
              samples << indent(`#{ cmd } 2>&1`, 4) << "\n" 
         | 
| 32 | 
            -
            end
         | 
| 33 | 
            -
             | 
| 34 | 
            -
            #samples.gsub! %r/^/, '  '
         | 
| 35 | 
            -
             | 
| 36 | 
            -
            readme  = template.gsub %r/^\s*@samples\s*$/, samples
         | 
| 37 | 
            -
            print readme 
         | 
    
        data/install.rb
    DELETED
    
    | @@ -1,214 +0,0 @@ | |
| 1 | 
            -
            #!/usr/bin/env ruby
         | 
| 2 | 
            -
            require 'rbconfig'
         | 
| 3 | 
            -
            require 'find'
         | 
| 4 | 
            -
            require 'ftools'
         | 
| 5 | 
            -
            require 'tempfile'
         | 
| 6 | 
            -
            include Config
         | 
| 7 | 
            -
             | 
| 8 | 
            -
            LIBDIR      = "lib"
         | 
| 9 | 
            -
            LIBDIR_MODE = 0644
         | 
| 10 | 
            -
             | 
| 11 | 
            -
            BINDIR      = "bin"
         | 
| 12 | 
            -
            BINDIR_MODE = 0755
         | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
            $srcdir            = CONFIG["srcdir"]
         | 
| 16 | 
            -
            $version           = CONFIG["MAJOR"]+"."+CONFIG["MINOR"]
         | 
| 17 | 
            -
            $libdir            = File.join(CONFIG["libdir"], "ruby", $version)
         | 
| 18 | 
            -
            $archdir           = File.join($libdir, CONFIG["arch"])
         | 
| 19 | 
            -
            $site_libdir       = $:.find {|x| x =~ /site_ruby$/}
         | 
| 20 | 
            -
            $bindir            = CONFIG["bindir"] || CONFIG['BINDIR']
         | 
| 21 | 
            -
            $ruby_install_name = CONFIG['ruby_install_name'] || CONFIG['RUBY_INSTALL_NAME'] || 'ruby'
         | 
| 22 | 
            -
            $ruby_ext          = CONFIG['EXEEXT'] || ''
         | 
| 23 | 
            -
            $ruby              = File.join($bindir, ($ruby_install_name + $ruby_ext))
         | 
| 24 | 
            -
             | 
| 25 | 
            -
            if !$site_libdir
         | 
| 26 | 
            -
              $site_libdir = File.join($libdir, "site_ruby")
         | 
| 27 | 
            -
            elsif $site_libdir !~ %r/#{Regexp.quote($version)}/
         | 
| 28 | 
            -
              $site_libdir = File.join($site_libdir, $version)
         | 
| 29 | 
            -
            end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
            def install_rb(srcdir=nil, destdir=nil, mode=nil, bin=nil)
         | 
| 32 | 
            -
            #{{{
         | 
| 33 | 
            -
              path   = []
         | 
| 34 | 
            -
              dir    = []
         | 
| 35 | 
            -
              Find.find(srcdir) do |f|
         | 
| 36 | 
            -
                next unless FileTest.file?(f)
         | 
| 37 | 
            -
                next if (f = f[srcdir.length+1..-1]) == nil
         | 
| 38 | 
            -
                next if (/CVS$/ =~ File.dirname(f))
         | 
| 39 | 
            -
                next if (/\.svn/ =~ File.dirname(f))
         | 
| 40 | 
            -
                next if f =~ %r/\.lnk/
         | 
| 41 | 
            -
                next if f =~ %r/\.svn/
         | 
| 42 | 
            -
                next if f =~ %r/\.swp/
         | 
| 43 | 
            -
                next if f =~ %r/\.svn/
         | 
| 44 | 
            -
                path.push f
         | 
| 45 | 
            -
                dir |= [File.dirname(f)]
         | 
| 46 | 
            -
              end
         | 
| 47 | 
            -
              for f in dir
         | 
| 48 | 
            -
                next if f == "."
         | 
| 49 | 
            -
                next if f == "CVS"
         | 
| 50 | 
            -
                File::makedirs(File.join(destdir, f))
         | 
| 51 | 
            -
              end
         | 
| 52 | 
            -
              for f in path
         | 
| 53 | 
            -
                next if (/\~$/ =~ f)
         | 
| 54 | 
            -
                next if (/^\./ =~ File.basename(f))
         | 
| 55 | 
            -
                unless bin
         | 
| 56 | 
            -
                  File::install(File.join(srcdir, f), File.join(destdir, f), mode, true)
         | 
| 57 | 
            -
                else
         | 
| 58 | 
            -
                  from = File.join(srcdir, f)
         | 
| 59 | 
            -
                  to = File.join(destdir, f)
         | 
| 60 | 
            -
                  shebangify(from) do |sf|
         | 
| 61 | 
            -
                    $deferr.print from, " -> ", File::catname(from, to), "\n"
         | 
| 62 | 
            -
                    $deferr.printf "chmod %04o %s\n", mode, to 
         | 
| 63 | 
            -
                    File::install(sf, to, mode, false)
         | 
| 64 | 
            -
                  end
         | 
| 65 | 
            -
                end
         | 
| 66 | 
            -
              end
         | 
| 67 | 
            -
            #}}}
         | 
| 68 | 
            -
            end
         | 
| 69 | 
            -
            def shebangify f
         | 
| 70 | 
            -
            #{{{
         | 
| 71 | 
            -
              open(f) do |fd|
         | 
| 72 | 
            -
                buf = fd.read 42 
         | 
| 73 | 
            -
                if buf =~ %r/^\s*#\s*!.*ruby/o
         | 
| 74 | 
            -
                  ftmp = Tempfile::new("#{ $$ }_#{ File::basename(f) }")
         | 
| 75 | 
            -
                  begin
         | 
| 76 | 
            -
                    fd.rewind
         | 
| 77 | 
            -
                    ftmp.puts "#!#{ $ruby  }"
         | 
| 78 | 
            -
                    while((buf = fd.read(8192)))
         | 
| 79 | 
            -
                      ftmp.write buf
         | 
| 80 | 
            -
                    end
         | 
| 81 | 
            -
                    ftmp.close
         | 
| 82 | 
            -
                    yield ftmp.path
         | 
| 83 | 
            -
                  ensure
         | 
| 84 | 
            -
                    ftmp.close!
         | 
| 85 | 
            -
                  end
         | 
| 86 | 
            -
                else
         | 
| 87 | 
            -
                  yield f
         | 
| 88 | 
            -
                end
         | 
| 89 | 
            -
              end
         | 
| 90 | 
            -
            #}}}
         | 
| 91 | 
            -
            end
         | 
| 92 | 
            -
            def ARGV.switch
         | 
| 93 | 
            -
            #{{{
         | 
| 94 | 
            -
              return nil if self.empty?
         | 
| 95 | 
            -
              arg = self.shift
         | 
| 96 | 
            -
              return nil if arg == '--'
         | 
| 97 | 
            -
              if arg =~ /^-(.)(.*)/
         | 
| 98 | 
            -
                return arg if $1 == '-'
         | 
| 99 | 
            -
                raise 'unknown switch "-"' if $2.index('-')
         | 
| 100 | 
            -
                self.unshift "-#{$2}" if $2.size > 0
         | 
| 101 | 
            -
                "-#{$1}"
         | 
| 102 | 
            -
              else
         | 
| 103 | 
            -
                self.unshift arg
         | 
| 104 | 
            -
                nil
         | 
| 105 | 
            -
              end
         | 
| 106 | 
            -
            #}}}
         | 
| 107 | 
            -
            end
         | 
| 108 | 
            -
            def ARGV.req_arg
         | 
| 109 | 
            -
            #{{{
         | 
| 110 | 
            -
              self.shift || raise('missing argument')
         | 
| 111 | 
            -
            #}}}
         | 
| 112 | 
            -
            end
         | 
| 113 | 
            -
            def linkify d, linked = []
         | 
| 114 | 
            -
            #--{{{
         | 
| 115 | 
            -
              if test ?d, d
         | 
| 116 | 
            -
                versioned = Dir[ File::join(d, "*-[0-9].[0-9].[0-9].rb") ]
         | 
| 117 | 
            -
                versioned.each do |v| 
         | 
| 118 | 
            -
                  src, dst = v, v.gsub(%r/\-[\d\.]+\.rb$/, '.rb')
         | 
| 119 | 
            -
                  lnk = nil
         | 
| 120 | 
            -
                  begin
         | 
| 121 | 
            -
                    if test ?l, dst
         | 
| 122 | 
            -
                      lnk = "#{ dst }.lnk"
         | 
| 123 | 
            -
                      puts "#{ dst } -> #{ lnk }"
         | 
| 124 | 
            -
                      File::rename dst, lnk
         | 
| 125 | 
            -
                    end
         | 
| 126 | 
            -
                    unless test ?e, dst
         | 
| 127 | 
            -
                      puts "#{ src } -> #{ dst }"
         | 
| 128 | 
            -
                      File::copy src, dst 
         | 
| 129 | 
            -
                      linked << dst
         | 
| 130 | 
            -
                    end
         | 
| 131 | 
            -
                  ensure
         | 
| 132 | 
            -
                    if lnk
         | 
| 133 | 
            -
                      at_exit do
         | 
| 134 | 
            -
                        puts "#{ lnk } -> #{ dst }"
         | 
| 135 | 
            -
                        File::rename lnk, dst
         | 
| 136 | 
            -
                      end
         | 
| 137 | 
            -
                    end
         | 
| 138 | 
            -
                  end
         | 
| 139 | 
            -
                end
         | 
| 140 | 
            -
              end
         | 
| 141 | 
            -
              linked
         | 
| 142 | 
            -
            #--}}}
         | 
| 143 | 
            -
            end
         | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
            #
         | 
| 147 | 
            -
            # main program
         | 
| 148 | 
            -
            #
         | 
| 149 | 
            -
             | 
| 150 | 
            -
            libdir = $site_libdir
         | 
| 151 | 
            -
            bindir = $bindir
         | 
| 152 | 
            -
            no_linkify = false
         | 
| 153 | 
            -
            linked = nil
         | 
| 154 | 
            -
            help = false
         | 
| 155 | 
            -
             | 
| 156 | 
            -
            usage = <<-usage
         | 
| 157 | 
            -
              #{ File::basename $0 }
         | 
| 158 | 
            -
                -d, --destdir    <destdir>
         | 
| 159 | 
            -
                -l, --libdir     <libdir>
         | 
| 160 | 
            -
                -b, --bindir     <bindir>
         | 
| 161 | 
            -
                -r, --ruby       <ruby>
         | 
| 162 | 
            -
                -n, --no_linkify
         | 
| 163 | 
            -
                -s, --sudo
         | 
| 164 | 
            -
                -h, --help
         | 
| 165 | 
            -
            usage
         | 
| 166 | 
            -
             | 
| 167 | 
            -
            begin
         | 
| 168 | 
            -
              while switch = ARGV.switch
         | 
| 169 | 
            -
                case switch
         | 
| 170 | 
            -
                when '-d', '--destdir'
         | 
| 171 | 
            -
                  libdir = ARGV.req_arg
         | 
| 172 | 
            -
                when '-l', '--libdir'
         | 
| 173 | 
            -
                  libdir = ARGV.req_arg
         | 
| 174 | 
            -
                when '-b', '--bindir'
         | 
| 175 | 
            -
                  bindir = ARGV.req_arg
         | 
| 176 | 
            -
                when '-r', '--ruby'
         | 
| 177 | 
            -
                  $ruby = ARGV.req_arg
         | 
| 178 | 
            -
                when '-n', '--no_linkify'
         | 
| 179 | 
            -
                  no_linkify = true
         | 
| 180 | 
            -
                when '-s', '--sudo'
         | 
| 181 | 
            -
                  sudo = 'sudo' 
         | 
| 182 | 
            -
                when '-h', '--help'
         | 
| 183 | 
            -
                  help = true
         | 
| 184 | 
            -
                else
         | 
| 185 | 
            -
                  raise "unknown switch #{switch.dump}"
         | 
| 186 | 
            -
                end
         | 
| 187 | 
            -
              end
         | 
| 188 | 
            -
            rescue
         | 
| 189 | 
            -
              STDERR.puts $!.to_s
         | 
| 190 | 
            -
              STDERR.puts usage
         | 
| 191 | 
            -
              exit 1
         | 
| 192 | 
            -
            end    
         | 
| 193 | 
            -
             | 
| 194 | 
            -
            if help
         | 
| 195 | 
            -
              STDOUT.puts usage
         | 
| 196 | 
            -
              exit
         | 
| 197 | 
            -
            end
         | 
| 198 | 
            -
             | 
| 199 | 
            -
            system "#{ sudo } #{ $ruby } pre-install.rb" if test(?s, 'pre-install.rb')
         | 
| 200 | 
            -
             | 
| 201 | 
            -
            unless no_linkify
         | 
| 202 | 
            -
              linked = linkify('lib') + linkify('bin')
         | 
| 203 | 
            -
            end
         | 
| 204 | 
            -
             | 
| 205 | 
            -
            system "#{ $ruby } extconf.rb && make && #{ sudo } make install" if test(?s, 'extconf.rb')
         | 
| 206 | 
            -
             | 
| 207 | 
            -
            install_rb(LIBDIR, libdir, LIBDIR_MODE)
         | 
| 208 | 
            -
            install_rb(BINDIR, bindir, BINDIR_MODE, bin=true)
         | 
| 209 | 
            -
             | 
| 210 | 
            -
            if linked
         | 
| 211 | 
            -
              linked.each{|path| File::rm_f path}
         | 
| 212 | 
            -
            end
         | 
| 213 | 
            -
             | 
| 214 | 
            -
            system "#{ sudo } #{ $ruby } post-install.rb" if test(?s, 'post-install.rb')
         |