request-log-analyzer 1.0.2 → 1.6.3

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.
Files changed (144) hide show
  1. data/.gitignore +10 -0
  2. data/DESIGN.rdoc +41 -0
  3. data/LICENSE +4 -4
  4. data/README.rdoc +38 -0
  5. data/Rakefile +6 -3
  6. data/bin/request-log-analyzer +70 -72
  7. data/lib/cli/command_line_arguments.rb +53 -53
  8. data/lib/cli/database_console.rb +26 -0
  9. data/lib/cli/database_console_init.rb +43 -0
  10. data/lib/cli/progressbar.rb +166 -189
  11. data/lib/cli/tools.rb +49 -0
  12. data/lib/request_log_analyzer/aggregator/database_inserter.rb +83 -0
  13. data/lib/request_log_analyzer/aggregator/echo.rb +17 -12
  14. data/lib/request_log_analyzer/aggregator/summarizer.rb +101 -63
  15. data/lib/request_log_analyzer/{aggregator/base.rb → aggregator.rb} +17 -13
  16. data/lib/request_log_analyzer/controller.rb +251 -98
  17. data/lib/request_log_analyzer/database/base.rb +114 -0
  18. data/lib/request_log_analyzer/database/connection.rb +38 -0
  19. data/lib/request_log_analyzer/database/request.rb +22 -0
  20. data/lib/request_log_analyzer/database/source.rb +13 -0
  21. data/lib/request_log_analyzer/database/warning.rb +14 -0
  22. data/lib/request_log_analyzer/database.rb +102 -0
  23. data/lib/request_log_analyzer/file_format/amazon_s3.rb +74 -0
  24. data/lib/request_log_analyzer/file_format/apache.rb +147 -0
  25. data/lib/request_log_analyzer/file_format/delayed_job.rb +55 -0
  26. data/lib/request_log_analyzer/file_format/merb.rb +65 -29
  27. data/lib/request_log_analyzer/file_format/mysql.rb +101 -0
  28. data/lib/request_log_analyzer/file_format/postgresql.rb +68 -0
  29. data/lib/request_log_analyzer/file_format/rack.rb +9 -0
  30. data/lib/request_log_analyzer/file_format/rails.rb +164 -78
  31. data/lib/request_log_analyzer/file_format/rails3.rb +86 -0
  32. data/lib/request_log_analyzer/file_format/rails_development.rb +12 -0
  33. data/lib/request_log_analyzer/file_format.rb +252 -58
  34. data/lib/request_log_analyzer/filter/anonymize.rb +39 -0
  35. data/lib/request_log_analyzer/filter/field.rb +19 -13
  36. data/lib/request_log_analyzer/filter/timespan.rb +25 -12
  37. data/lib/request_log_analyzer/filter.rb +30 -0
  38. data/lib/request_log_analyzer/line_definition.rb +69 -96
  39. data/lib/request_log_analyzer/log_processor.rb +31 -53
  40. data/lib/request_log_analyzer/mailer.rb +65 -0
  41. data/lib/request_log_analyzer/output/fancy_html.rb +49 -0
  42. data/lib/request_log_analyzer/output/fixed_width.rb +220 -0
  43. data/lib/request_log_analyzer/output/html.rb +187 -0
  44. data/lib/request_log_analyzer/output.rb +117 -0
  45. data/lib/request_log_analyzer/request.rb +125 -40
  46. data/lib/request_log_analyzer/source/database_loader.rb +87 -0
  47. data/lib/request_log_analyzer/source/log_parser.rb +297 -0
  48. data/lib/request_log_analyzer/source.rb +72 -0
  49. data/lib/request_log_analyzer/tracker/duration.rb +28 -64
  50. data/lib/request_log_analyzer/tracker/frequency.rb +108 -0
  51. data/lib/request_log_analyzer/tracker/hourly_spread.rb +76 -49
  52. data/lib/request_log_analyzer/tracker/numeric_value.rb +223 -0
  53. data/lib/request_log_analyzer/tracker/timespan.rb +54 -27
  54. data/lib/request_log_analyzer/tracker/traffic.rb +40 -0
  55. data/lib/request_log_analyzer/tracker.rb +101 -0
  56. data/lib/request_log_analyzer.rb +43 -13
  57. data/request-log-analyzer.gemspec +41 -0
  58. data/spec/database.yml +23 -0
  59. data/spec/fixtures/apache_combined.log +5 -0
  60. data/spec/fixtures/apache_common.log +10 -0
  61. data/spec/fixtures/decompression.log +12 -0
  62. data/spec/fixtures/decompression.log.bz2 +0 -0
  63. data/spec/fixtures/decompression.log.gz +0 -0
  64. data/spec/fixtures/decompression.log.zip +0 -0
  65. data/spec/fixtures/decompression.tar.gz +0 -0
  66. data/spec/fixtures/decompression.tgz +0 -0
  67. data/spec/fixtures/header_and_footer.log +6 -0
  68. data/spec/fixtures/merb_prefixed.log +9 -0
  69. data/spec/fixtures/mysql_slow_query.log +110 -0
  70. data/spec/fixtures/postgresql.log +2980 -0
  71. data/spec/fixtures/rails.db +0 -0
  72. data/spec/fixtures/rails_22.log +1 -1
  73. data/spec/fixtures/sinatra.log +99 -0
  74. data/spec/integration/command_line_usage_spec.rb +84 -0
  75. data/spec/integration/mailer_spec.rb +179 -0
  76. data/spec/integration/munin_plugins_rails_spec.rb +58 -0
  77. data/spec/integration/scout_spec.rb +152 -0
  78. data/spec/lib/helpers.rb +72 -0
  79. data/spec/lib/macros.rb +18 -0
  80. data/spec/lib/matchers.rb +77 -0
  81. data/spec/lib/mocks.rb +77 -0
  82. data/spec/lib/testing_format.rb +46 -0
  83. data/spec/spec_helper.rb +16 -59
  84. data/spec/unit/aggregator/database_inserter_spec.rb +93 -0
  85. data/spec/unit/aggregator/summarizer_spec.rb +26 -0
  86. data/spec/unit/controller/controller_spec.rb +41 -0
  87. data/spec/unit/controller/log_processor_spec.rb +18 -0
  88. data/spec/unit/database/base_class_spec.rb +183 -0
  89. data/spec/unit/database/connection_spec.rb +34 -0
  90. data/spec/unit/database/database_spec.rb +133 -0
  91. data/spec/unit/file_format/amazon_s3_format_spec.rb +67 -0
  92. data/spec/unit/file_format/apache_format_spec.rb +203 -0
  93. data/spec/unit/file_format/common_regular_expressions_spec.rb +53 -0
  94. data/spec/unit/file_format/delayed_job_format_spec.rb +83 -0
  95. data/spec/unit/file_format/file_format_api_spec.rb +69 -0
  96. data/spec/unit/file_format/format_autodetection_spec.rb +40 -0
  97. data/spec/unit/file_format/line_definition_spec.rb +75 -0
  98. data/spec/unit/file_format/merb_format_spec.rb +52 -0
  99. data/spec/unit/file_format/mysql_format_spec.rb +154 -0
  100. data/spec/unit/file_format/postgresql_format_spec.rb +65 -0
  101. data/spec/unit/file_format/rack_format_spec.rb +50 -0
  102. data/spec/unit/file_format/rails3_format_spec.rb +120 -0
  103. data/spec/unit/file_format/rails_format_spec.rb +180 -0
  104. data/spec/unit/filter/anonymize_filter_spec.rb +21 -0
  105. data/spec/unit/filter/field_filter_spec.rb +66 -0
  106. data/spec/unit/filter/filter_spec.rb +17 -0
  107. data/spec/unit/filter/timespan_filter_spec.rb +58 -0
  108. data/spec/unit/mailer_spec.rb +42 -0
  109. data/spec/unit/request_spec.rb +111 -0
  110. data/spec/unit/source/log_parser_spec.rb +119 -0
  111. data/spec/unit/tracker/duration_tracker_spec.rb +49 -0
  112. data/spec/unit/tracker/frequency_tracker_spec.rb +88 -0
  113. data/spec/unit/tracker/hourly_spread_spec.rb +79 -0
  114. data/spec/unit/tracker/numeric_value_tracker_spec.rb +166 -0
  115. data/spec/unit/tracker/timespan_tracker_spec.rb +73 -0
  116. data/spec/unit/tracker/tracker_api_spec.rb +125 -0
  117. data/spec/unit/tracker/traffic_tracker_spec.rb +28 -0
  118. data/tasks/github-gem.rake +290 -139
  119. data/tasks/request_log_analyzer.rake +23 -7
  120. metadata +221 -94
  121. data/DESIGN +0 -14
  122. data/HACKING +0 -7
  123. data/README.textile +0 -36
  124. data/lib/cli/bashcolorizer.rb +0 -60
  125. data/lib/request_log_analyzer/aggregator/database.rb +0 -148
  126. data/lib/request_log_analyzer/filter/base.rb +0 -29
  127. data/lib/request_log_analyzer/log_parser.rb +0 -173
  128. data/lib/request_log_analyzer/source/base.rb +0 -42
  129. data/lib/request_log_analyzer/source/log_file.rb +0 -170
  130. data/lib/request_log_analyzer/tracker/base.rb +0 -54
  131. data/lib/request_log_analyzer/tracker/category.rb +0 -71
  132. data/spec/controller_spec.rb +0 -40
  133. data/spec/database_inserter_spec.rb +0 -101
  134. data/spec/file_format_spec.rb +0 -78
  135. data/spec/file_formats/spec_format.rb +0 -26
  136. data/spec/filter_spec.rb +0 -137
  137. data/spec/line_definition_spec.rb +0 -124
  138. data/spec/log_parser_spec.rb +0 -68
  139. data/spec/log_processor_spec.rb +0 -57
  140. data/spec/merb_format_spec.rb +0 -38
  141. data/spec/rails_format_spec.rb +0 -76
  142. data/spec/request_spec.rb +0 -72
  143. data/spec/summarizer_spec.rb +0 -9
  144. data/tasks/rspec.rake +0 -6
@@ -2,176 +2,327 @@ require 'rubygems'
2
2
  require 'rake'
3
3
  require 'rake/tasklib'
4
4
  require 'date'
5
+ require 'git'
5
6
 
6
- module Rake
7
-
8
- class GithubGem < TaskLib
9
-
10
- attr_accessor :name
11
- attr_accessor :specification
12
-
13
- def self.define_tasks!
14
- gem_task_builder = Rake::GithubGem.new
15
- gem_task_builder.register_all_tasks!
7
+ module GithubGem
8
+
9
+ # Detects the gemspc file of this project using heuristics.
10
+ def self.detect_gemspec_file
11
+ FileList['*.gemspec'].first
12
+ end
13
+
14
+ # Detects the main include file of this project using heuristics
15
+ def self.detect_main_include
16
+ if detect_gemspec_file =~ /^(\.*)\.gemspec$/ && File.exist?("lib/#{$1}.rb")
17
+ "lib/#{$1}.rb"
18
+ elsif FileList['lib/*.rb'].length == 1
19
+ FileList['lib/*.rb'].first
20
+ else
21
+ nil
16
22
  end
17
-
23
+ end
24
+
25
+ class RakeTasks
26
+
27
+ attr_reader :gemspec, :modified_files, :git
28
+ attr_accessor :gemspec_file, :task_namespace, :main_include, :root_dir, :spec_pattern, :test_pattern, :remote, :remote_branch, :local_branch
29
+
30
+ # Initializes the settings, yields itself for configuration
31
+ # and defines the rake tasks based on the gemspec file.
32
+ def initialize(task_namespace = :gem)
33
+ @gemspec_file = GithubGem.detect_gemspec_file
34
+ @task_namespace = task_namespace
35
+ @main_include = GithubGem.detect_main_include
36
+ @modified_files = []
37
+ @root_dir = Dir.pwd
38
+ @test_pattern = 'test/**/*_test.rb'
39
+ @spec_pattern = 'spec/**/*_spec.rb'
40
+ @local_branch = 'master'
41
+ @remote = 'origin'
42
+ @remote_branch = 'master'
43
+
44
+ yield(self) if block_given?
45
+
46
+ @git = Git.open(@root_dir)
47
+ load_gemspec!
48
+ define_tasks!
49
+ end
50
+
51
+ protected
18
52
 
19
- def initialize
20
- reload_gemspec!
53
+ # Define Unit test tasks
54
+ def define_test_tasks!
55
+ require 'rake/testtask'
56
+
57
+ namespace(:test) do
58
+ Rake::TestTask.new(:basic) do |t|
59
+ t.pattern = test_pattern
60
+ t.verbose = true
61
+ t.libs << 'test'
62
+ end
63
+ end
64
+
65
+ desc "Run all unit tests for #{gemspec.name}"
66
+ task(:test => ['test:basic'])
21
67
  end
22
68
 
23
- def register_all_tasks!
24
- namespace(:gem) do
25
- desc "Updates the file lists for this gem"
69
+ # Defines RSpec tasks
70
+ def define_rspec_tasks!
71
+ require 'spec/rake/spectask'
72
+
73
+ namespace(:spec) do
74
+ desc "Verify all RSpec examples for #{gemspec.name}"
75
+ Spec::Rake::SpecTask.new(:basic) do |t|
76
+ t.spec_files = FileList[spec_pattern]
77
+ end
78
+
79
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
80
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
81
+ t.spec_files = FileList[spec_pattern]
82
+ t.spec_opts << '--format' << 'specdoc' << '--color'
83
+ end
84
+
85
+ desc "Run RCov on specs for #{gemspec.name}"
86
+ Spec::Rake::SpecTask.new(:rcov) do |t|
87
+ t.spec_files = FileList[spec_pattern]
88
+ t.rcov = true
89
+ t.rcov_opts = ['--exclude', '"spec/*,gems/*"', '--rails']
90
+ end
91
+ end
92
+
93
+ desc "Verify all RSpec examples for #{gemspec.name} and output specdoc"
94
+ task(:spec => ['spec:specdoc'])
95
+ end
96
+
97
+ # Defines the rake tasks
98
+ def define_tasks!
99
+
100
+ define_test_tasks! if has_tests?
101
+ define_rspec_tasks! if has_specs?
102
+
103
+ namespace(@task_namespace) do
104
+ desc "Updates the filelist in the gemspec file"
26
105
  task(:manifest) { manifest_task }
27
-
28
- desc "Builds a ruby gem for #{@name}"
29
- task(:build => [:manifest]) { build_task }
30
-
31
- desc "Installs the ruby gem for #{@name} locally"
32
- task(:install => [:build]) { install_task }
33
-
34
- desc "Uninstalls the ruby gem for #{@name} locally"
35
- task(:uninstall) { uninstall_task }
36
-
37
- desc "Releases a new version of #{@name}"
38
- task(:release) { release_task }
106
+
107
+ desc "Builds the .gem package"
108
+ task(:build => :manifest) { build_task }
109
+
110
+ desc "Sets the version of the gem in the gemspec"
111
+ task(:set_version => [:check_version, :check_current_branch]) { version_task }
112
+ task(:check_version => :fetch_origin) { check_version_task }
113
+
114
+ task(:fetch_origin) { fetch_origin_task }
115
+ task(:check_current_branch) { check_current_branch_task }
116
+ task(:check_clean_status) { check_clean_status_task }
117
+ task(:check_not_diverged => :fetch_origin) { check_not_diverged_task }
118
+
119
+ checks = [:check_current_branch, :check_clean_status, :check_not_diverged, :check_version]
120
+ checks.unshift('spec:basic') if has_specs?
121
+ checks.unshift('test:basic') if has_tests?
122
+ # checks.push << [:check_rubyforge] if gemspec.rubyforge_project
123
+
124
+ desc "Perform all checks that would occur before a release"
125
+ task(:release_checks => checks)
126
+
127
+ release_tasks = [:release_checks, :set_version, :build, :github_release, :gemcutter_release]
128
+ # release_tasks << [:rubyforge_release] if gemspec.rubyforge_project
129
+
130
+ desc "Release a new verison of the gem"
131
+ task(:release => release_tasks) { release_task }
132
+
133
+ # task(:check_rubyforge) { check_rubyforge_task }
134
+ # task(:rubyforge_release) { rubyforge_release_task }
135
+ task(:gemcutter_release) { gemcutter_release_task }
136
+ task(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
137
+ task(:tag_version) { tag_version_task }
138
+ task(:commit_modified_files) { commit_modified_files_task }
139
+
140
+ desc "Updates the gem release tasks with the latest version on Github"
141
+ task(:update_tasks) { update_tasks_task }
39
142
  end
40
143
  end
41
-
42
144
 
43
-
44
- protected
145
+ # Updates the files list and test_files list in the gemspec file using the list of files
146
+ # in the repository and the spec/test file pattern.
147
+ def manifest_task
148
+ # Load all the gem's files using "git ls-files"
149
+ repository_files = git.ls_files.keys
150
+ test_files = Dir[test_pattern] + Dir[spec_pattern]
45
151
 
46
- def reload_gemspec!
47
- raise "No gemspec file found!" if gemspec_file.nil?
48
- spec = File.read(gemspec_file)
49
- @specification = eval(spec)
50
- @name = specification.name
152
+ update_gemspec(:files, repository_files)
153
+ update_gemspec(:test_files, repository_files & test_files)
51
154
  end
52
155
 
53
- def run_command(command)
54
- lines = []
55
- IO.popen(command) { |f| lines = f.readlines }
56
- return lines
156
+ # Builds the gem
157
+ def build_task
158
+ sh "gem build -q #{gemspec_file}"
159
+ Dir.mkdir('pkg') unless File.exist?('pkg')
160
+ sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
57
161
  end
58
-
59
- def git_modified?(file)
60
- return !run_command('git status').detect { |line| Regexp.new(Regexp.quote(file)) =~ line }.nil?
162
+
163
+ # Updates the version number in the gemspec file, the VERSION constant in the main
164
+ # include file and the contents of the VERSION file.
165
+ def version_task
166
+ update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
167
+ update_gemspec(:date, Date.today)
168
+
169
+ update_version_file(gemspec.version)
170
+ update_version_constant(gemspec.version)
61
171
  end
62
-
63
- def git_commit_file(file, message, branch = nil)
64
- verify_current_branch(branch) unless branch.nil?
65
- if git_modified?(file)
66
- sh "git add #{file}"
67
- sh "git commit -m \"#{message}\""
68
- else
69
- raise "#{file} is not modified and cannot be committed!"
172
+
173
+ def check_version_task
174
+ raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
175
+ proposed_version = Gem::Version.new(ENV['VERSION'] || gemspec.version)
176
+ # Loads the latest version number using the created tags
177
+ newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
178
+ raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version && newest_version >= proposed_version
179
+ end
180
+
181
+ # Checks whether the current branch is not diverged from the remote branch
182
+ def check_not_diverged_task
183
+ raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.remote(remote).branch(remote_branch).gcommit).any?
184
+ end
185
+
186
+ # Checks whether the repository status ic clean
187
+ def check_clean_status_task
188
+ raise "The current working copy contains modifications" if git.status.changed.any?
189
+ end
190
+
191
+ # Checks whether the current branch is correct
192
+ def check_current_branch_task
193
+ raise "Currently not on #{local_branch} branch!" unless git.branch.name == local_branch.to_s
194
+ end
195
+
196
+ # Fetches the latest updates from Github
197
+ def fetch_origin_task
198
+ git.fetch('origin')
199
+ end
200
+
201
+ # Commits every file that has been changed by the release task.
202
+ def commit_modified_files_task
203
+ if modified_files.any?
204
+ modified_files.each { |file| git.add(file) }
205
+ git.commit("Released #{gemspec.name} gem version #{gemspec.version}")
70
206
  end
71
207
  end
72
-
73
- def git_create_tag(tag_name, message)
74
- sh "git tag -a \"#{tag_name}\" -m \"#{message}\""
208
+
209
+ # Adds a tag for the released version
210
+ def tag_version_task
211
+ git.add_tag("#{gemspec.name}-#{gemspec.version}")
75
212
  end
76
-
77
- def git_push(remote = 'origin', branch = 'master', options = [])
78
- verify_clean_status(branch)
79
- options_str = options.map { |o| "--#{o}"}.join(' ')
80
- sh "git push #{options_str} #{remote} #{branch}"
213
+
214
+ # Pushes the changes and tag to github
215
+ def github_release_task
216
+ git.push(remote, remote_branch, true)
81
217
  end
218
+
219
+ # # Checks whether Rubyforge is configured properly
220
+ # def check_rubyforge_task
221
+ # # Login no longer necessary when using rubyforge 2.0.0 gem
222
+ # # raise "Could not login on rubyforge!" unless `rubyforge login 2>&1`.strip.empty?
223
+ # output = `rubyforge names`.split("\n")
224
+ # raise "Rubyforge group not found!" unless output.any? { |line| %r[^groups\s*\:.*\b#{Regexp.quote(gemspec.rubyforge_project)}\b.*] =~ line }
225
+ # raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
226
+ # end
227
+
228
+ # # Task to release the .gem file toRubyforge.
229
+ # def rubyforge_release_task
230
+ # sh 'rubyforge', 'add_release', gemspec.rubyforge_project, gemspec.name, gemspec.version.to_s, "pkg/#{gemspec.name}-#{gemspec.version}.gem"
231
+ # end
82
232
 
83
- def gemspec_version=(new_version)
84
- spec = File.read(gemspec_file)
85
- spec.gsub!(/^(\s*s\.version\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_version}'#{$5}" }
86
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{Date.today.strftime('%Y-%m-%d')}'#{$5}" }
87
- File.open(gemspec_file, 'w') { |f| f << spec }
88
- reload_gemspec!
233
+ def gemcutter_release_task
234
+ sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
89
235
  end
90
-
91
- def gemspec_date=(new_date)
92
- spec = File.read(gemspec_file)
93
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_date.strftime('%Y-%m-%d')}'#{$5}" }
94
- File.open(gemspec_file, 'w') { |f| f << spec }
95
- reload_gemspec!
236
+
237
+ # Gem release task.
238
+ # All work is done by the task's dependencies, so just display a release completed message.
239
+ def release_task
240
+ puts
241
+ puts '------------------------------------------------------------'
242
+ puts "Released #{gemspec.name} version #{gemspec.version}"
96
243
  end
97
-
98
- def gemspec_file
99
- @gemspec_file ||= Dir['*.gemspec'].first
244
+
245
+ private
246
+
247
+ # Checks whether this project has any RSpec files
248
+ def has_specs?
249
+ FileList[spec_pattern].any?
100
250
  end
101
-
102
- def verify_current_branch(branch)
103
- run_command('git branch').detect { |line| /^\* (.+)/ =~ line }
104
- raise "You are currently not working in the master branch!" unless branch == $1
251
+
252
+ # Checks whether this project has any unit test files
253
+ def has_tests?
254
+ FileList[test_pattern].any?
105
255
  end
106
-
107
- def verify_clean_status(on_branch = nil)
108
- sh "git fetch"
109
- lines = run_command('git status')
110
- raise "You don't have the most recent version available. Run git pull first." if /^\# Your branch is behind/ =~ lines[1]
111
- raise "You are currently not working in the #{on_branch} branch!" unless on_branch.nil? || (/^\# On branch (.+)/ =~ lines.first && $1 == on_branch)
112
- raise "Your master branch contains modifications!" unless /^nothing to commit \(working directory clean\)/ =~ lines.last
256
+
257
+ # Loads the gemspec file
258
+ def load_gemspec!
259
+ @gemspec = eval(File.read(@gemspec_file))
113
260
  end
114
-
115
- def verify_version(new_version)
116
- newest_version = run_command('git tag').map { |tag| tag.split(name + '-').last }.compact.map { |v| Gem::Version.new(v) }.max
117
- raise "This version number (#{new_version}) is not higher than the highest tagged version (#{newest_version})" if !newest_version.nil? && newest_version >= Gem::Version.new(new_version.to_s)
261
+
262
+ # Updates the VERSION file with the new version
263
+ def update_version_file(version)
264
+ if File.exists?('VERSION')
265
+ File.open('VERSION', 'w') { |f| f << version.to_s }
266
+ modified_files << 'VERSION'
267
+ end
118
268
  end
119
269
 
120
- def manifest_task
121
- verify_current_branch('master')
122
-
123
- list = Dir['**/*'].sort
124
- list -= [gemspec_file]
125
-
126
- if File.exist?('.gitignore')
127
- File.read('.gitignore').each_line do |glob|
128
- glob = glob.chomp.sub(/^\//, '')
129
- list -= Dir[glob]
130
- list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
270
+ # Updates the VERSION constant in the main include file if it exists
271
+ def update_version_constant(version)
272
+ if main_include && File.exist?(main_include)
273
+ file_contents = File.read(main_include)
274
+ if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
275
+ File.open(main_include, 'w') { |f| f << file_contents }
276
+ modified_files << main_include
131
277
  end
132
278
  end
133
-
134
- # update the spec file
135
- spec = File.read(gemspec_file)
136
- spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
137
- assignment = $1
138
- bunch = $2 ? list.grep(/^(test.*_test\.rb|spec.*_spec.rb)$/) : list
139
- '%s%%w(%s)' % [assignment, bunch.join(' ')]
279
+ end
280
+
281
+ # Updates an attribute of the gemspec file.
282
+ # This function will open the file, and search/replace the attribute using a regular expression.
283
+ def update_gemspec(attribute, new_value, literal = false)
284
+
285
+ unless literal
286
+ new_value = case new_value
287
+ when Array then "%w(#{new_value.join(' ')})"
288
+ when Hash, String then new_value.inspect
289
+ when Date then new_value.strftime('%Y-%m-%d').inspect
290
+ else raise "Cannot write value #{new_value.inspect} to gemspec file!"
291
+ end
140
292
  end
141
293
 
142
- File.open(gemspec_file, 'w') { |f| f << spec }
143
- reload_gemspec!
144
- end
145
-
146
- def build_task
147
- sh "gem build #{gemspec_file}"
148
- end
149
-
150
- def install_task
151
- raise "#{name} .gem file not found" unless File.exist?("#{name}-#{specification.version}.gem")
152
- sh "gem install #{name}-#{specification.version}.gem"
294
+ spec = File.read(gemspec_file)
295
+ regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
296
+ if spec.sub!(regexp) { $1 + new_value }
297
+ File.open(gemspec_file, 'w') { |f| f << spec }
298
+ modified_files << gemspec_file
299
+
300
+ # Reload the gemspec so the changes are incorporated
301
+ load_gemspec!
302
+ end
153
303
  end
154
-
155
- def uninstall_task
156
- raise "#{name} .gem file not found" unless File.exist?("#{name}-#{specification.version}.gem")
157
- sh "gem uninstall #{name}"
158
- end
159
-
160
- def release_task
161
- verify_clean_status('master')
162
- verify_version(ENV['VERSION'] || @specification.version)
163
-
164
- # update gemspec file
165
- self.gemspec_version = ENV['VERSION'] if Gem::Version.correct?(ENV['VERSION'])
166
- self.gemspec_date = Date.today
167
- manifest_task
168
- git_commit_file(gemspec_file, "Updated #{gemspec_file} for release of version #{@specification.version}") if git_modified?(gemspec_file)
169
-
170
- # create tag and push changes
171
- git_create_tag("#{@name}-#{@specification.version}", "Tagged version #{@specification.version}")
172
- git_push('origin', 'master', [:tags])
304
+
305
+ # Updates the tasks file using the latest file found on Github
306
+ def update_tasks_task
307
+ require 'net/http'
308
+
309
+ server = 'github.com'
310
+ path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
311
+
312
+ Net::HTTP.start(server) do |http|
313
+ response = http.get(path)
314
+ open(__FILE__, "w") { |file| file.write(response.body) }
315
+ end
316
+
317
+ relative_file = File.expand_path(__FILE__).sub(%r[^#{git.dir.path}/], '')
318
+ if git.status[relative_file] && git.status[relative_file].type == 'M'
319
+ git.add(relative_file)
320
+ git.commit("Updated to latest gem release management tasks.")
321
+ puts "Updated to latest version of gem release management tasks."
322
+ else
323
+ puts "Release managament tasks already are at the latest version."
324
+ end
173
325
  end
326
+
174
327
  end
175
328
  end
176
-
177
- Rake::GithubGem.define_tasks!
@@ -1,10 +1,26 @@
1
- namespace :log do
2
- desc "Analyze the Rails log file using the request-log-analyzer gem."
3
- task :analyze => :environment do
1
+ namespace :rla do
2
+ desc "Analyze the Rails log file using the request-log-analyzer gem."
3
+ task :report => :environment do
4
+ puts "Analyzing the Rails log file using the request-log-analyzer gem."
5
+ puts " Environment: #{RAILS_ENV}"
6
+ puts " Logfile: #{Rails.configuration.log_path}"
7
+ puts ""
8
+ IO.popen("request-log-analyzer #{Rails.configuration.log_path}") { |io| $stdout << io.read }
9
+
10
+ end
11
+
12
+ namespace :report do
13
+ desc "Analyze the Rails log file using the request-log-analyzer gem and output an HTML file."
14
+ task :html => :environment do
15
+ output_file = Rails.configuration.log_path + ".html"
16
+
4
17
  puts "Analyzing the Rails log file using the request-log-analyzer gem."
5
- puts "Environment: #{RAILS_ENV}"
6
- puts "Logfile: #{Rails.configuration.log_path}"
18
+ puts " Environment: #{RAILS_ENV}"
19
+ puts " Logfile: #{Rails.configuration.log_path}"
20
+ puts " Output: #{output_file}"
7
21
  puts ""
8
- `request-log-analyzer #{Rails.configuration.log_path} -z`
22
+ IO.popen("request-log-analyzer #{Rails.configuration.log_path} --output HTML --file #{output_file}") { |io| $stdout << io.read }
23
+ end
9
24
  end
10
- end
25
+
26
+ end