derailed-mole 1.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. data/History.txt +17 -0
  2. data/Manifest.txt +137 -0
  3. data/README.txt +216 -0
  4. data/Rakefile +46 -0
  5. data/bin/molify +64 -0
  6. data/config/database.yml +21 -0
  7. data/config/test_database.yml +69 -0
  8. data/lib/mole.rb +260 -0
  9. data/lib/mole/db/migrate.rb +90 -0
  10. data/lib/mole/e_mole.rb +75 -0
  11. data/lib/mole/e_mole_helper.rb +2 -0
  12. data/lib/mole/logger.rb +134 -0
  13. data/lib/mole/models/mole_feature.rb +58 -0
  14. data/lib/mole/models/mole_log.rb +31 -0
  15. data/lib/mole/module.rb +292 -0
  16. data/lib/mole/moler.rb +71 -0
  17. data/lib/mole/utils/frameworks.rb +53 -0
  18. data/lib/mole/version.rb +15 -0
  19. data/mole.gemspec +37 -0
  20. data/samples/merbapp/README +14 -0
  21. data/samples/merbapp/Rakefile +124 -0
  22. data/samples/merbapp/app/controllers/application.rb +3 -0
  23. data/samples/merbapp/app/controllers/exceptions.rb +13 -0
  24. data/samples/merbapp/app/controllers/moled.rb +25 -0
  25. data/samples/merbapp/app/helpers/global_helper.rb +5 -0
  26. data/samples/merbapp/app/mailers/views/layout/application.html.erb +1 -0
  27. data/samples/merbapp/app/mailers/views/layout/application.text.erb +1 -0
  28. data/samples/merbapp/app/parts/views/layout/application.html.erb +1 -0
  29. data/samples/merbapp/app/views/exceptions/internal_server_error.html.erb +216 -0
  30. data/samples/merbapp/app/views/exceptions/not_acceptable.html.erb +38 -0
  31. data/samples/merbapp/app/views/exceptions/not_found.html.erb +40 -0
  32. data/samples/merbapp/app/views/layout/application.html.erb +11 -0
  33. data/samples/merbapp/app/views/moled/index.html.erb +5 -0
  34. data/samples/merbapp/app/views/moled/result.html.erb +5 -0
  35. data/samples/merbapp/config/boot.rb +11 -0
  36. data/samples/merbapp/config/dependencies.rb +41 -0
  37. data/samples/merbapp/config/environments/development.rb +1 -0
  38. data/samples/merbapp/config/environments/production.rb +1 -0
  39. data/samples/merbapp/config/environments/test.rb +1 -0
  40. data/samples/merbapp/config/merb.yml +82 -0
  41. data/samples/merbapp/config/merb_init.rb +26 -0
  42. data/samples/merbapp/config/mole_config.rb +33 -0
  43. data/samples/merbapp/config/router.rb +38 -0
  44. data/samples/merbapp/config/upload.conf +0 -0
  45. data/samples/merbapp/public/images/merb.jpg +0 -0
  46. data/samples/merbapp/public/merb.fcgi +6 -0
  47. data/samples/merbapp/public/stylesheets/master.css +119 -0
  48. data/samples/merbapp/script/destroy +32 -0
  49. data/samples/merbapp/script/generate +32 -0
  50. data/samples/merbapp/script/stop_merb +13 -0
  51. data/samples/merbapp/spec/spec_helper.rb +15 -0
  52. data/samples/merbapp/test/test_helper.rb +14 -0
  53. data/samples/railsapp/README +14 -0
  54. data/samples/railsapp/Rakefile +10 -0
  55. data/samples/railsapp/app/controllers/application.rb +13 -0
  56. data/samples/railsapp/app/controllers/moled_controller.rb +24 -0
  57. data/samples/railsapp/app/helpers/application_helper.rb +3 -0
  58. data/samples/railsapp/app/views/moled/index.html.erb +5 -0
  59. data/samples/railsapp/app/views/moled/result.html.erb +5 -0
  60. data/samples/railsapp/config/boot.rb +109 -0
  61. data/samples/railsapp/config/database.yml +13 -0
  62. data/samples/railsapp/config/environment.rb +59 -0
  63. data/samples/railsapp/config/environments/development.rb +18 -0
  64. data/samples/railsapp/config/environments/production.rb +20 -0
  65. data/samples/railsapp/config/environments/test.rb +22 -0
  66. data/samples/railsapp/config/initializers/inflections.rb +10 -0
  67. data/samples/railsapp/config/initializers/mime_types.rb +5 -0
  68. data/samples/railsapp/config/initializers/mole.rb +10 -0
  69. data/samples/railsapp/config/moles/mole_config.rb +44 -0
  70. data/samples/railsapp/config/routes.rb +35 -0
  71. data/samples/railsapp/doc/README_FOR_APP +2 -0
  72. data/samples/railsapp/public/.htaccess +40 -0
  73. data/samples/railsapp/public/404.html +30 -0
  74. data/samples/railsapp/public/422.html +30 -0
  75. data/samples/railsapp/public/500.html +30 -0
  76. data/samples/railsapp/public/dispatch.cgi +10 -0
  77. data/samples/railsapp/public/dispatch.fcgi +24 -0
  78. data/samples/railsapp/public/dispatch.rb +10 -0
  79. data/samples/railsapp/public/favicon.ico +0 -0
  80. data/samples/railsapp/public/images/rails.png +0 -0
  81. data/samples/railsapp/public/javascripts/application.js +2 -0
  82. data/samples/railsapp/public/javascripts/controls.js +963 -0
  83. data/samples/railsapp/public/javascripts/dragdrop.js +972 -0
  84. data/samples/railsapp/public/javascripts/effects.js +1120 -0
  85. data/samples/railsapp/public/javascripts/prototype.js +4225 -0
  86. data/samples/railsapp/public/robots.txt +5 -0
  87. data/samples/railsapp/script/about +3 -0
  88. data/samples/railsapp/script/console +3 -0
  89. data/samples/railsapp/script/destroy +3 -0
  90. data/samples/railsapp/script/generate +3 -0
  91. data/samples/railsapp/script/performance/benchmarker +3 -0
  92. data/samples/railsapp/script/performance/profiler +3 -0
  93. data/samples/railsapp/script/performance/request +3 -0
  94. data/samples/railsapp/script/plugin +3 -0
  95. data/samples/railsapp/script/process/inspector +3 -0
  96. data/samples/railsapp/script/process/reaper +3 -0
  97. data/samples/railsapp/script/process/spawner +3 -0
  98. data/samples/railsapp/script/runner +3 -0
  99. data/samples/railsapp/script/server +3 -0
  100. data/samples/railsapp/test/test_helper.rb +38 -0
  101. data/samples/rubyapp/README +22 -0
  102. data/samples/rubyapp/bin/ruby_app +35 -0
  103. data/samples/rubyapp/config/mole_conf.rb +31 -0
  104. data/samples/rubyapp/lib/fred.rb +22 -0
  105. data/spec/config/auto_mole_config.rb +26 -0
  106. data/spec/config/mole_config.rb +0 -0
  107. data/spec/config/moles/fred_config.rb +0 -0
  108. data/spec/data/blee.rb +64 -0
  109. data/spec/db/migrate_spec.rb +19 -0
  110. data/spec/emole_spec.rb +43 -0
  111. data/spec/logger_spec.rb +56 -0
  112. data/spec/models/mole_feature_spec.rb +48 -0
  113. data/spec/models/mole_log_spec.rb +62 -0
  114. data/spec/module_spec.rb +229 -0
  115. data/spec/mole_spec.rb +135 -0
  116. data/spec/moler_spec.rb +77 -0
  117. data/spec/spec_helper.rb +76 -0
  118. data/spec/utils/framework_spec.rb +99 -0
  119. data/tasks/ann.rake +76 -0
  120. data/tasks/annotations.rake +22 -0
  121. data/tasks/doc.rake +48 -0
  122. data/tasks/gem.rake +110 -0
  123. data/tasks/manifest.rake +49 -0
  124. data/tasks/mole.rake +115 -0
  125. data/tasks/post_load.rake +26 -0
  126. data/tasks/rubyforge.rake +57 -0
  127. data/tasks/setup.rb +227 -0
  128. data/tasks/spec.rake +54 -0
  129. data/tasks/svn.rake +44 -0
  130. data/tasks/test.rake +38 -0
  131. data/templates/mole/e_mole/exception_alerts.rhtml +14 -0
  132. data/templates/mole/e_mole/feature_alerts.rhtml +11 -0
  133. data/templates/mole/e_mole/perf_alerts.rhtml +12 -0
  134. metadata +206 -0
@@ -0,0 +1,49 @@
1
+ # $Id$
2
+
3
+ require 'find'
4
+
5
+ namespace :manifest do
6
+
7
+ desc 'Verify the manifest'
8
+ task :check do
9
+ fn = PROJ.manifest_file + '.tmp'
10
+ files = manifest_files
11
+
12
+ File.open(fn, 'w') {|fp| fp.puts files}
13
+ lines = %x(#{DIFF} -du #{PROJ.manifest_file} #{fn}).split("\n")
14
+ if HAVE_FACETS_ANSICODE and ENV.has_key?('TERM')
15
+ lines.map! do |line|
16
+ case line
17
+ when %r/^(-{3}|\+{3})/; nil
18
+ when %r/^@/; Console::ANSICode.blue line
19
+ when %r/^\+/; Console::ANSICode.green line
20
+ when %r/^\-/; Console::ANSICode.red line
21
+ else line end
22
+ end
23
+ end
24
+ puts lines.compact
25
+ rm fn rescue nil
26
+ end
27
+
28
+ desc 'Create a new manifest'
29
+ task :create do
30
+ files = manifest_files
31
+ unless test(?f, PROJ.manifest_file)
32
+ files << PROJ.manifest_file
33
+ files.sort!
34
+ end
35
+ File.open(PROJ.manifest_file, 'w') {|fp| fp.puts files}
36
+ end
37
+
38
+ task :assert do
39
+ files = manifest_files
40
+ manifest = File.read(PROJ.manifest_file).split($/)
41
+ raise "ERROR: #{PROJ.manifest_file} is out of date" unless files == manifest
42
+ end
43
+
44
+ end # namespace :manifest
45
+
46
+ desc 'Alias to manifest:check'
47
+ task :manifest => 'manifest:check'
48
+
49
+ # EOF
data/tasks/mole.rake ADDED
@@ -0,0 +1,115 @@
1
+ # -----------------------------------------------------------------------------
2
+ # MOLE Related rake tasks
3
+ # Mole db setup upon installation
4
+ # -----------------------------------------------------------------------------
5
+ require 'ftools'
6
+
7
+ namespace :mole do
8
+ namespace :db do
9
+ task :environment do
10
+ require 'rubygems'
11
+
12
+ gem "activerecord", "=2.0.2"
13
+ require 'active_record'
14
+
15
+ environment = ENV['MOLE_ENV'] || "test"
16
+ db_config = YAML.load_file( File.join( File.dirname(__FILE__), "..", "config", "test_database.yml") )[environment]
17
+ ::ActiveRecord::Base.establish_connection(db_config)
18
+ end
19
+
20
+ # ---------------------------------------------------------------------
21
+ # Create mole persistence tables and pre-populate
22
+ desc 'Create the database tables needed for the mole plugin.'
23
+ task :migrate_up => :environment do
24
+ # Create the mole_features table if it doesn't exist
25
+ unless ActiveRecord::Schema.tables.include?('mole_features')
26
+ ActiveRecord::Schema.create_table('mole_features') do |t|
27
+ t.column :name, :string
28
+ t.column :context, :string
29
+ t.column :app_name, :string
30
+ t.column :created_at, :datetime
31
+ t.column :updated_at, :datetime
32
+ end
33
+ ActiveRecord::Schema.add_index( 'mole_features', 'name' )
34
+
35
+ # Create some default features
36
+ # MoleFeature.create :id => 0, :name => MoleFeature::ALL
37
+ # MoleFeature.create :id => 1, :name => MoleFeature::EXCEPTION
38
+ # MoleFeature.create :id => 2, :name => MoleFeature::PERFORMANCE
39
+ end
40
+
41
+ # Create the mole_logs table if it doesn't exist
42
+ unless ActiveRecord::Schema.tables.include?('mole_logs')
43
+ ActiveRecord::Schema.create_table('mole_logs') do |t|
44
+ t.column :mole_feature_id, :integer
45
+ t.column :user_id, :integer
46
+ t.column :params, :string
47
+ t.column :ip_address, :string
48
+ t.column :browser_type, :string
49
+ t.column :host_name, :string
50
+ t.column :created_at, :datetime
51
+ t.column :updated_at, :datetime
52
+ end
53
+ ActiveRecord::Schema.add_index( 'mole_logs', ['mole_feature_id','user_id'] )
54
+ ActiveRecord::Schema.add_index( 'mole_logs', ['mole_feature_id','created_at'] )
55
+ end
56
+ end
57
+
58
+ # -------------------------------------------------------------------------
59
+ # Destroys mole persistence tables
60
+ desc 'Drop the database tables needed for the mole plugin.'
61
+ task :migrate_down => :environment do
62
+ # Delete the mole_feature table
63
+ if ActiveRecord::Schema.tables.include?('mole_features')
64
+ ActiveRecord::Schema.drop_table('mole_features')
65
+ end
66
+
67
+ # Delete the mole_logs table
68
+ if ActiveRecord::Schema.tables.include?('mole_logs')
69
+ ActiveRecord::Schema.remove_index('mole_logs', ['mole_feature_id','user_id'] )
70
+ ActiveRecord::Schema.drop_table('mole_logs')
71
+ end
72
+ end
73
+ end
74
+
75
+ # ---------------------------------------------------------------------------
76
+ # Installs the mole plugin
77
+ desc 'The task that is run when you first install the plugin.'
78
+ task :install => :setup do
79
+ # Copy over the sample mole.conf file to the default location
80
+ destination = @plugin_base + '/../../../config'
81
+ File.makedirs(destination) unless File.exists?(destination)
82
+ unless File.exists?(destination + '/mole.conf')
83
+ File.copy(@plugin_base + '/lib/mole.conf.sample', destination + '/mole.conf')
84
+ end
85
+
86
+ # Migrate the database
87
+ Rake::Task["mole:migrate:up"].invoke
88
+ end
89
+
90
+ # ---------------------------------------------------------------------------
91
+ # Removes the mole plugin and cleanup artifacts
92
+ desc 'The task that is run when you want to remove the plugin.'
93
+ task :remove => :setup do
94
+ # Remove the database tables
95
+ Rake::Task["mole:migrate:down"].invoke
96
+
97
+ # Delete the default mole.conf file
98
+ File.delete( "#{RAILS_ROOT}/config/mole.conf" )
99
+ end
100
+
101
+ # ---------------------------------------------------------------------------
102
+ desc 'Setup plugin base dir'
103
+ task :setup do
104
+ @plugin_base = File.dirname(__FILE__) + '/..'
105
+ end
106
+
107
+ # ---------------------------------------------------------------------------
108
+ # Upgrade task from MOLE version 0.002
109
+ # This task will setup the extra mole features columns and reset the indexes
110
+ # on the mole_features table.
111
+ desc 'Ugrade the mole schema from version 0.002'
112
+ task :upgrade do
113
+ Rake::Task["mole:migrate:upgrade"].invoke
114
+ end
115
+ end
@@ -0,0 +1,26 @@
1
+ # $Id$
2
+
3
+ # This file does not define any rake tasks. It is used to load some project
4
+ # settings if they are not defined by the user.
5
+
6
+ PROJ.rdoc_exclude << "^#{Regexp.escape(PROJ.manifest_file)}$"
7
+ PROJ.exclude << "^#{Regexp.escape(PROJ.ann_file)}$"
8
+
9
+ PROJ.changes ||= paragraphs_of(PROJ.history_file, 0..1).join("\n\n")
10
+
11
+ PROJ.description ||= paragraphs_of(PROJ.readme_file, 'description').join("\n\n")
12
+
13
+ PROJ.summary ||= PROJ.description.split('.').first
14
+
15
+ PROJ.files ||=
16
+ if test(?f, PROJ.manifest_file)
17
+ files = File.readlines(PROJ.manifest_file).map {|fn| fn.chomp.strip}
18
+ files.delete ''
19
+ files
20
+ else [] end
21
+
22
+ PROJ.executables ||= PROJ.files.find_all {|fn| fn =~ %r/^bin/}
23
+
24
+ PROJ.rdoc_main ||= PROJ.readme_file
25
+
26
+ # EOF
@@ -0,0 +1,57 @@
1
+ # $Id$
2
+
3
+ if PROJ.rubyforge_name && HAVE_RUBYFORGE
4
+
5
+ require 'rubyforge'
6
+ require 'rake/contrib/sshpublisher'
7
+
8
+ namespace :gem do
9
+ desc 'Package and upload to RubyForge'
10
+ task :release => [:clobber, :package] do |t|
11
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
12
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
13
+ pkg = "pkg/#{PROJ.spec.full_name}"
14
+
15
+ if $DEBUG then
16
+ puts "release_id = rf.add_release #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, #{PROJ.version.inspect}, \"#{pkg}.tgz\""
17
+ puts "rf.add_file #{PROJ.rubyforge_name.inspect}, #{PROJ.name.inspect}, release_id, \"#{pkg}.gem\""
18
+ end
19
+
20
+ rf = RubyForge.new
21
+ puts 'Logging in'
22
+ rf.login
23
+
24
+ c = rf.userconfig
25
+ c['release_notes'] = PROJ.description if PROJ.description
26
+ c['release_changes'] = PROJ.changes if PROJ.changes
27
+ c['preformatted'] = true
28
+
29
+ files = [(PROJ.need_tar ? "#{pkg}.tgz" : nil),
30
+ (PROJ.need_zip ? "#{pkg}.zip" : nil),
31
+ "#{pkg}.gem"].compact
32
+
33
+ puts "Releasing #{PROJ.name} v. #{PROJ.version}"
34
+ rf.add_release PROJ.rubyforge_name, PROJ.name, PROJ.version, *files
35
+ end
36
+ end # namespace :gem
37
+
38
+
39
+ namespace :doc do
40
+ desc "Publish RDoc to RubyForge"
41
+ task :release => %w(doc:clobber_rdoc doc:rdoc) do
42
+ config = YAML.load(
43
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
44
+ )
45
+
46
+ host = "#{config['username']}@rubyforge.org"
47
+ remote_dir = "/var/www/gforge-projects/#{PROJ.rubyforge_name}/"
48
+ remote_dir << PROJ.rdoc_remote_dir if PROJ.rdoc_remote_dir
49
+ local_dir = PROJ.rdoc_dir
50
+
51
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
52
+ end
53
+ end # namespace :doc
54
+
55
+ end # if HAVE_RUBYFORGE
56
+
57
+ # EOF
data/tasks/setup.rb ADDED
@@ -0,0 +1,227 @@
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ PROJ = OpenStruct.new
10
+
11
+ PROJ.name = nil
12
+ PROJ.summary = nil
13
+ PROJ.description = nil
14
+ PROJ.changes = nil
15
+ PROJ.authors = nil
16
+ PROJ.email = nil
17
+ PROJ.url = nil
18
+ PROJ.version = ENV['VERSION'] || '0.0.0'
19
+ PROJ.rubyforge_name = nil
20
+ PROJ.exclude = %w(tmp$ bak$ ~$ CVS .svn/ .git/ ^pkg/ ^doc/)
21
+ PROJ.release_name = ENV['RELEASE']
22
+ PROJ.history_file = 'History.txt'
23
+ PROJ.manifest_file = 'Manifest.txt'
24
+ PROJ.readme_file = 'README.txt'
25
+
26
+ # Rspec
27
+ PROJ.specs = FileList['spec/**/*_spec.rb']
28
+ PROJ.spec_opts = []
29
+
30
+ # Test::Unit
31
+ PROJ.tests = FileList['test/**/test_*.rb']
32
+ PROJ.test_file = 'test/all.rb'
33
+ PROJ.test_opts = []
34
+
35
+ # Rcov
36
+ PROJ.rcov_dir = 'coverage'
37
+ PROJ.rcov_opts = ['--sort', 'coverage', '-T']
38
+ PROJ.rcov_threshold = 90.0
39
+ PROJ.rcov_threshold_exact = false
40
+
41
+ # Rdoc
42
+ PROJ.rdoc_opts = []
43
+ PROJ.rdoc_include = %w(^lib/ ^bin/ ^ext/ .txt$)
44
+ PROJ.rdoc_exclude = %w(extconf.rb$)
45
+ PROJ.rdoc_main = nil
46
+ PROJ.rdoc_dir = 'doc'
47
+ PROJ.rdoc_remote_dir = nil
48
+
49
+ # Extensions
50
+ PROJ.extensions = FileList['ext/**/extconf.rb']
51
+ PROJ.ruby_opts = %w(-w)
52
+ PROJ.libs = []
53
+ %w(lib ext).each {|dir| PROJ.libs << dir if test ?d, dir}
54
+
55
+ # Gem Packaging
56
+ PROJ.files = nil
57
+ PROJ.executables = nil
58
+ PROJ.dependencies = []
59
+ PROJ.need_tar = true
60
+ PROJ.need_zip = false
61
+ PROJ.post_install_message = nil
62
+
63
+ # File Annotations
64
+ PROJ.annotation_exclude = %w(^tasks/setup.rb$)
65
+ PROJ.annotation_extensions = %w(.txt .rb .erb) << ''
66
+ PROJ.annotation_tags = %w(FIXME OPTIMIZE TODO)
67
+
68
+ # Subversion Repository
69
+ PROJ.svn = false
70
+ PROJ.svn_root = nil
71
+ PROJ.svn_trunk = 'trunk'
72
+ PROJ.svn_tags = 'tags'
73
+ PROJ.svn_branches = 'branches'
74
+
75
+ # Announce
76
+ PROJ.ann_file = 'announcement.txt'
77
+ PROJ.ann_text = nil
78
+ PROJ.ann_paragraphs = []
79
+ PROJ.ann_email = {
80
+ :from => nil,
81
+ :to => %w(ruby-talk@ruby-lang.org),
82
+ :server => 'localhost',
83
+ :port => 25,
84
+ :domain => ENV['HOSTNAME'],
85
+ :acct => nil,
86
+ :passwd => nil,
87
+ :authtype => :plain
88
+ }
89
+
90
+ # Load the other rake files in the tasks folder
91
+ rakefiles = Dir.glob('tasks/*.rake').sort
92
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
93
+ import(*rakefiles)
94
+
95
+ # Setup some constants
96
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
97
+
98
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
99
+
100
+ def quiet( &block )
101
+ io = [STDOUT.dup, STDERR.dup]
102
+ STDOUT.reopen DEV_NULL
103
+ STDERR.reopen DEV_NULL
104
+ block.call
105
+ ensure
106
+ STDOUT.reopen io.first
107
+ STDERR.reopen io.last
108
+ end
109
+
110
+ DIFF = if WIN32 then 'diff.exe'
111
+ else
112
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
113
+ else 'diff' end
114
+ end unless defined? DIFF
115
+
116
+ SUDO = if WIN32 then ''
117
+ else
118
+ if quiet {system 'which sudo'} then 'sudo'
119
+ else '' end
120
+ end
121
+
122
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
123
+ GEM = WIN32 ? 'gem.bat' : 'gem'
124
+
125
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
126
+ begin
127
+ require lib
128
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
129
+ rescue LoadError
130
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
131
+ end
132
+ end
133
+
134
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
135
+ # specified.
136
+ #
137
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
138
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
139
+ #
140
+ def paragraphs_of( path, *paragraphs )
141
+ title = String === paragraphs.first ? paragraphs.shift : nil
142
+ ary = File.read(path).delete("\r").split(/\n\n+/)
143
+
144
+ result = if title
145
+ tmp, matching = [], false
146
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
147
+ paragraphs << (0..-1) if paragraphs.empty?
148
+
149
+ ary.each do |val|
150
+ if val =~ rgxp
151
+ break if matching
152
+ matching = true
153
+ rgxp = %r/^=+/i
154
+ elsif matching
155
+ tmp << val
156
+ end
157
+ end
158
+ tmp
159
+ else ary end
160
+
161
+ result.values_at(*paragraphs)
162
+ end
163
+
164
+ # Adds the given gem _name_ to the current project's dependency list. An
165
+ # optional gem _version_ can be given. If omitted, the newest gem version
166
+ # will be used.
167
+ #
168
+ def depend_on( name, version = nil )
169
+ spec = Gem.source_index.find_name(name).last
170
+ version = spec.version.to_s if version.nil? and !spec.nil?
171
+
172
+ PROJ.dependencies << case version
173
+ when nil; [name]
174
+ when %r/^\d/; [name, ">= #{version}"]
175
+ else [name, version] end
176
+ end
177
+
178
+ # Adds the given arguments to the include path if they are not already there
179
+ #
180
+ def ensure_in_path( *args )
181
+ args.each do |path|
182
+ path = File.expand_path(path)
183
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
184
+ end
185
+ end
186
+
187
+ # Find a rake task using the task name and remove any description text. This
188
+ # will prevent the task from being displayed in the list of available tasks.
189
+ #
190
+ def remove_desc_for_task( names )
191
+ Array(names).each do |task_name|
192
+ task = Rake.application.tasks.find {|t| t.name == task_name}
193
+ next if task.nil?
194
+ task.instance_variable_set :@comment, nil
195
+ end
196
+ end
197
+
198
+ # Change working directories to _dir_, call the _block_ of code, and then
199
+ # change back to the original working directory (the current directory when
200
+ # this method was called).
201
+ #
202
+ def in_directory( dir, &block )
203
+ curdir = pwd
204
+ begin
205
+ cd dir
206
+ return block.call
207
+ ensure
208
+ cd curdir
209
+ end
210
+ end
211
+
212
+ # Scans the current working directory and creates a list of files that are
213
+ # candidates to be in the manifest.
214
+ #
215
+ def manifest_files
216
+ files = []
217
+ exclude = Regexp.new(PROJ.exclude.join('|'))
218
+ Find.find '.' do |path|
219
+ path.sub! %r/^(\.\/|\/)/o, ''
220
+ next unless test ?f, path
221
+ next if path =~ exclude
222
+ files << path
223
+ end
224
+ files.sort!
225
+ end
226
+
227
+ # EOF