wvanbergen-http_status_exceptions 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ http_status_exceptions-*.gem
2
+ /tmp
3
+ /doc
4
+ /pkg
5
+ /coverage
6
+ .DS_Store
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
1
  Dir[File.dirname(__FILE__) + "/tasks/*.rake"].each { |file| load(file) }
2
-
3
- #task :default => :spec
2
+
3
+ GithubGem::RakeTasks.new(:gem)
4
+
5
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'http_status_exceptions'
3
+ s.version = "0.1.6"
4
+ s.date = "2009-09-26"
5
+
6
+ s.summary = "A Rails plugin to use exceptions for generating HTTP status responses"
7
+ s.description = "Clean up your controller code by raising exceptions that generate responses with different HTTP status codes."
8
+
9
+ s.add_runtime_dependency('action_controller')
10
+ s.add_development_dependency('rspec')
11
+
12
+ s.authors = ['Willem van Bergen']
13
+ s.email = ['willem@vanbergen.org']
14
+ s.homepage = 'http://github.com/wvanbergen/http_status_exceptions/wikis'
15
+
16
+ s.files = %w(spec/spec_helper.rb http_status_exceptions.gemspec .gitignore init.rb lib/http_status_exceptions.rb Rakefile MIT-LICENSE tasks/github-gem.rake README.rdoc spec/http_status_exception_spec.rb)
17
+ end
@@ -0,0 +1,51 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe 'HTTPStatus#http_status_exception' do
4
+ before(:each) do
5
+ @controller_class = Class.new(ActionController::Base)
6
+ @controller = @controller_class.new
7
+ end
8
+
9
+ it "should respond to the :http_status_exception method" do
10
+ @controller.should respond_to(:http_status_exception)
11
+ end
12
+
13
+ ['NotFound', 'Forbidden', 'PaymentRequired'].each do |status_class|
14
+ status_symbol = status_class.underscore.downcase.to_sym
15
+
16
+ it "should create the HTTPStatus::#{status_class} class" do
17
+ HTTPStatus.const_defined?(status_class).should be_true
18
+ end
19
+
20
+ it "should create a subclass of HTTPStatus::Base for the #{status_class.underscore.humanize.downcase} status" do
21
+ HTTPStatus.const_get(status_class).ancestors.should include(HTTPStatus::Base)
22
+ end
23
+
24
+ it "should call render with the correct #{status_class.underscore.humanize.downcase} view and correct HTTP status" do
25
+ @controller.should_receive(:render).with(hash_including(
26
+ :status => status_symbol,
27
+ :template => "shared/http_status/#{status_symbol}"))
28
+
29
+ @controller.http_status_exception(HTTPStatus.const_get(status_class).new('test'))
30
+ end
31
+ end
32
+ end
33
+
34
+ describe HTTPStatus::Base do
35
+ before(:each) { @status = HTTPStatus::Base.new }
36
+
37
+ it "should set the status symbol bases on the class name" do
38
+ @status.status.should == :base
39
+ end
40
+
41
+ it "should check ActionController's status code list for the status code based on the class name" do
42
+ ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.should_receive(:[]).with(:base)
43
+ @status.status_code
44
+ end
45
+
46
+ it "should use the HTTPStatus::Base.template_path setting to determine the error template" do
47
+ HTTPStatus::Base.template_path = 'testing'
48
+ @status.template.should == 'testing/base'
49
+ end
50
+ end
51
+
@@ -0,0 +1,17 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+
3
+ require 'rubygems'
4
+ require 'spec/autorun'
5
+
6
+ require 'action_controller'
7
+
8
+ require 'http_status_exceptions'
9
+
10
+ # Include all files in the spec_helper directory
11
+ Dir[File.dirname(__FILE__) + "/lib/**/*.rb"].each do |file|
12
+ require file
13
+ end
14
+
15
+ Spec::Runner.configure do |config|
16
+ # nothing special
17
+ end
@@ -1,250 +1,315 @@
1
1
  require 'rubygems'
2
- require 'rubyforge'
3
2
  require 'rake'
4
3
  require 'rake/tasklib'
5
4
  require 'date'
5
+ require 'git'
6
6
 
7
- module Rake
8
-
9
- class GithubGem < TaskLib
10
-
11
- attr_accessor :name
12
- attr_accessor :specification
13
-
14
- def self.define_tasks!
15
- gem_task_builder = Rake::GithubGem.new
16
- 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
17
22
  end
18
-
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
19
29
 
20
- def initialize
21
- reload_gemspec!
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!
22
49
  end
23
50
 
24
- def register_all_tasks!
25
- namespace(:gem) do
26
- desc "Updates the file lists for this gem"
27
- task(:manifest) { manifest_task }
51
+ protected
28
52
 
29
- desc "Releases a new version of #{@name}"
30
- task(:build => [:manifest]) { build_task }
31
-
32
-
33
- release_dependencies = [:check_clean_master_branch, :version, :build, :create_tag]
34
- release_dependencies.push 'doc:publish' if has_rdoc?
35
- release_dependencies.unshift 'test' if has_tests?
36
- release_dependencies.unshift 'spec' if has_specs?
37
-
38
- desc "Releases a new version of #{@name}"
39
- task(:release => release_dependencies) { release_task }
40
-
41
- # helper task for releasing
42
- task(:check_clean_master_branch) { verify_clean_status('master') }
43
- task(:check_version) { verify_version(ENV['VERSION'] || @specification.version) }
44
- task(:version => [:check_version]) { set_gem_version! }
45
- task(:create_tag) { create_version_tag! }
46
- end
47
-
48
- # Register RDoc tasks
49
- if has_rdoc?
50
- require 'rake/rdoctask'
51
-
52
- namespace(:doc) do
53
- desc 'Generate documentation for request-log-analyzer'
54
- Rake::RDocTask.new(:compile) do |rdoc|
55
- rdoc.rdoc_dir = 'doc'
56
- rdoc.title = @name
57
- rdoc.options += @specification.rdoc_options
58
- rdoc.rdoc_files.include(@specification.extra_rdoc_files)
59
- rdoc.rdoc_files.include('lib/**/*.rb')
60
- end
61
-
62
- desc "Publish RDoc files for #{@name} to Github"
63
- task(:publish => :compile) do
64
- sh 'git checkout gh-pages'
65
- sh 'git pull origin gh-pages'
66
- sh 'cp -rf doc/* .'
67
- sh "git commit -am \"Publishing newest RDoc documentation for #{@name}\""
68
- sh "git push origin gh-pages"
69
- sh "git checkout master"
70
- end
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'
71
62
  end
72
63
  end
73
-
74
- # Setup :spec task if RSpec files exist
75
- if has_specs?
76
- require 'spec/rake/spectask'
77
-
78
- desc "Run all specs for #{@name}"
79
- Spec::Rake::SpecTask.new(:spec) do |t|
80
- t.spec_files = FileList['spec/**/*_spec.rb']
64
+
65
+ desc "Run all unit tests for #{gemspec.name}"
66
+ task(:test => ['test:basic'])
67
+ end
68
+
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]
81
77
  end
82
- end
83
-
84
- # Setup :test task if unit test files exist
85
- if has_tests?
86
- require 'rake/testtask'
87
-
88
- desc "Run all unit tests for #{@name}"
89
- Rake::TestTask.new(:test) do |t|
90
- t.pattern = 'test/**/*_test.rb'
91
- t.verbose = true
92
- t.libs << 'test'
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'
93
83
  end
94
- 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
95
  end
96
-
97
- protected
98
96
 
99
- def has_rdoc?
100
- @specification.has_rdoc
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"
105
+ task(:manifest) { manifest_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]
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(:github_release => [:commit_modified_files, :tag_version]) { github_release_task }
136
+ task(:tag_version) { tag_version_task }
137
+ task(:commit_modified_files) { commit_modified_files_task }
138
+
139
+ desc "Updates the gem release tasks with the latest version on Github"
140
+ task(:update_tasks) { update_tasks_task }
141
+ end
101
142
  end
102
143
 
103
- def has_specs?
104
- Dir['spec/**/*_spec.rb'].any?
144
+ # Updates the files list and test_files list in the gemspec file using the list of files
145
+ # in the repository and the spec/test file pattern.
146
+ def manifest_task
147
+ # Load all the gem's files using "git ls-files"
148
+ repository_files = git.ls_files.keys
149
+ test_files = Dir[test_pattern] + Dir[spec_pattern]
150
+
151
+ update_gemspec(:files, repository_files)
152
+ update_gemspec(:test_files, repository_files & test_files)
105
153
  end
106
-
107
- def has_tests?
108
- Dir['test/**/*_test.rb'].any?
154
+
155
+ # Builds the gem
156
+ def build_task
157
+ sh "gem build -q #{gemspec_file}"
158
+ Dir.mkdir('pkg') unless File.exist?('pkg')
159
+ sh "mv #{gemspec.name}-#{gemspec.version}.gem pkg/#{gemspec.name}-#{gemspec.version}.gem"
109
160
  end
110
161
 
111
- def reload_gemspec!
112
- raise "No gemspec file found!" if gemspec_file.nil?
113
- spec = File.read(gemspec_file)
114
- @specification = eval(spec)
115
- @name = specification.name
162
+ # Updates the version number in the gemspec file, the VERSION constant in the main
163
+ # include file and the contents of the VERSION file.
164
+ def version_task
165
+ update_gemspec(:version, ENV['VERSION']) if ENV['VERSION']
166
+ update_gemspec(:date, Date.today)
167
+
168
+ update_version_file(gemspec.version)
169
+ update_version_constant(gemspec.version)
116
170
  end
117
171
 
118
- def run_command(command)
119
- lines = []
120
- IO.popen(command) { |f| lines = f.readlines }
121
- return lines
172
+ def check_version_task
173
+ raise "#{ENV['VERSION']} is not a valid version number!" if ENV['VERSION'] && !Gem::Version.correct?(ENV['VERSION'])
174
+ proposed_version = Gem::Version.new(ENV['VERSION'] || gemspec.version)
175
+ # Loads the latest version number using the created tags
176
+ newest_version = git.tags.map { |tag| tag.name.split('-').last }.compact.map { |v| Gem::Version.new(v) }.max
177
+ raise "This version (#{proposed_version}) is not higher than the highest tagged version (#{newest_version})" if newest_version && newest_version >= proposed_version
122
178
  end
123
-
124
- def git_modified?(file)
125
- return !run_command('git status').detect { |line| Regexp.new(Regexp.quote(file)) =~ line }.nil?
179
+
180
+ # Checks whether the current branch is not diverged from the remote branch
181
+ def check_not_diverged_task
182
+ raise "The current branch is diverged from the remote branch!" if git.log.between('HEAD', git.branches["#{remote}/#{remote_branch}"].gcommit).any?
126
183
  end
127
-
128
- def git_commit_file(file, message, branch = nil)
129
- verify_current_branch(branch) unless branch.nil?
130
- if git_modified?(file)
131
- sh "git add #{file}"
132
- sh "git commit -m \"#{message}\""
133
- else
134
- raise "#{file} is not modified and cannot be committed!"
135
- end
184
+
185
+ # Checks whether the repository status ic clean
186
+ def check_clean_status_task
187
+ raise "The current working copy contains modifications" if git.status.changed.any?
136
188
  end
137
-
138
- def git_create_tag(tag_name, message)
139
- sh "git tag -a \"#{tag_name}\" -m \"#{message}\""
140
- end
141
-
142
- def git_push(remote = 'origin', branch = 'master', options = [])
143
- verify_clean_status(branch)
144
- options_str = options.map { |o| "--#{o}"}.join(' ')
145
- sh "git push #{options_str} #{remote} #{branch}"
146
- end
147
-
148
- def gemspec_version=(new_version)
149
- spec = File.read(gemspec_file)
150
- spec.gsub!(/^(\s*s\.version\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_version}'#{$5}" }
151
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{Date.today.strftime('%Y-%m-%d')}'#{$5}" }
152
- File.open(gemspec_file, 'w') { |f| f << spec }
153
- reload_gemspec!
154
- end
155
-
156
- def gemspec_date=(new_date)
157
- spec = File.read(gemspec_file)
158
- spec.gsub!(/^(\s*s\.date\s*=\s*)('|")(.+)('|")(\s*)$/) { "#{$1}'#{new_date.strftime('%Y-%m-%d')}'#{$5}" }
159
- File.open(gemspec_file, 'w') { |f| f << spec }
160
- reload_gemspec!
161
- end
162
-
163
- def gemspec_file
164
- @gemspec_file ||= Dir['*.gemspec'].first
165
- end
166
-
167
- def verify_current_branch(branch)
168
- run_command('git branch').detect { |line| /^\* (.+)/ =~ line }
169
- raise "You are currently not working in the master branch!" unless branch == $1
170
- end
171
-
172
- def verify_clean_status(on_branch = nil)
173
- sh "git fetch"
174
- lines = run_command('git status')
175
- raise "You don't have the most recent version available. Run git pull first." if /^\# Your branch is behind/ =~ lines[1]
176
- raise "You are currently not working in the #{on_branch} branch!" unless on_branch.nil? || (/^\# On branch (.+)/ =~ lines.first && $1 == on_branch)
177
- raise "Your master branch contains modifications!" unless /^nothing to commit \(working directory clean\)/ =~ lines.last
178
- end
179
-
180
- def verify_version(new_version)
181
- newest_version = run_command('git tag').map { |tag| tag.split(name + '-').last }.compact.map { |v| Gem::Version.new(v) }.max
182
- 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)
183
- end
184
-
185
- def set_gem_version!
186
- # update gemspec file
187
- self.gemspec_version = ENV['VERSION'] if Gem::Version.correct?(ENV['VERSION'])
188
- self.gemspec_date = Date.today
189
+
190
+ # Checks whether the current branch is correct
191
+ def check_current_branch_task
192
+ raise "Currently not on #{local_branch} branch!" unless git.branch.name == local_branch.to_s
189
193
  end
190
194
 
191
- def manifest_task
192
- verify_current_branch('master')
193
-
194
- list = Dir['**/*'].sort
195
- list -= [gemspec_file]
196
-
197
- if File.exist?('.gitignore')
198
- File.read('.gitignore').each_line do |glob|
199
- glob = glob.chomp.sub(/^\//, '')
200
- list -= Dir[glob]
201
- list -= Dir["#{glob}/**/*"] if File.directory?(glob) and !File.symlink?(glob)
202
- end
203
- end
204
-
205
- # update the spec file
206
- spec = File.read(gemspec_file)
207
- spec.gsub! /^(\s* s.(test_)?files \s* = \s* )( \[ [^\]]* \] | %w\( [^)]* \) )/mx do
208
- assignment = $1
209
- bunch = $2 ? list.grep(/^(test.*_test\.rb|spec.*_spec.rb)$/) : list
210
- '%s%%w(%s)' % [assignment, bunch.join(' ')]
195
+ # Fetches the latest updates from Github
196
+ def fetch_origin_task
197
+ git.fetch('origin')
198
+ end
199
+
200
+ # Commits every file that has been changed by the release task.
201
+ def commit_modified_files_task
202
+ if modified_files.any?
203
+ modified_files.each { |file| git.add(file) }
204
+ git.commit("Released #{gemspec.name} gem version #{gemspec.version}")
211
205
  end
206
+ end
212
207
 
213
- File.open(gemspec_file, 'w') { |f| f << spec }
214
- reload_gemspec!
208
+ # Adds a tag for the released version
209
+ def tag_version_task
210
+ git.add_tag("#{gemspec.name}-#{gemspec.version}")
215
211
  end
216
-
217
- def build_task
218
- sh "gem build #{gemspec_file}"
219
- Dir.mkdir('pkg') unless File.exist?('pkg')
220
- sh "mv #{name}-#{specification.version}.gem pkg/#{name}-#{specification.version}.gem"
221
- end
222
-
223
- def install_task
224
- raise "#{name} .gem file not found" unless File.exist?("pkg/#{name}-#{specification.version}.gem")
225
- sh "gem install pkg/#{name}-#{specification.version}.gem"
226
- end
227
-
228
- def uninstall_task
229
- raise "#{name} .gem file not found" unless File.exist?("pkg/#{name}-#{specification.version}.gem")
230
- sh "gem uninstall #{name}"
231
- end
232
-
233
- def create_version_tag!
234
- # commit the gemspec file
235
- git_commit_file(gemspec_file, "Released #{@name} version #{@specification.version}") if git_modified?(gemspec_file)
236
-
237
- # create tag and push changes
238
- git_create_tag("#{@name}-#{@specification.version}", "Tagged #{@name} version #{@specification.version}")
239
- git_push('origin', 'master', [:tags])
240
- end
241
-
212
+
213
+ # Pushes the changes and tag to github
214
+ def github_release_task
215
+ git.push(remote, remote_branch, true)
216
+ end
217
+
218
+ # Checks whether Rubyforge is configured properly
219
+ def check_rubyforge_task
220
+ # Login no longer necessary when using rubyforge 2.0.0 gem
221
+ # raise "Could not login on rubyforge!" unless `rubyforge login 2>&1`.strip.empty?
222
+ output = `rubyforge names`.split("\n")
223
+ raise "Rubyforge group not found!" unless output.any? { |line| %r[^groups\s*\:.*\b#{Regexp.quote(gemspec.rubyforge_project)}\b.*] =~ line }
224
+ raise "Rubyforge package not found!" unless output.any? { |line| %r[^packages\s*\:.*\b#{Regexp.quote(gemspec.name)}\b.*] =~ line }
225
+ end
226
+
227
+ # Task to release the .gem file toRubyforge.
228
+ def rubyforge_release_task
229
+ sh 'rubyforge', 'add_release', gemspec.rubyforge_project, gemspec.name, gemspec.version.to_s, "pkg/#{gemspec.name}-#{gemspec.version}.gem"
230
+ end
231
+
232
+ # Gem release task.
233
+ # All work is done by the task's dependencies, so just display a release completed message.
242
234
  def release_task
243
235
  puts
244
236
  puts '------------------------------------------------------------'
245
- puts "Released #{@name} - version #{@specification.version}"
237
+ puts "Released #{gemspec.name} version #{gemspec.version}"
238
+ end
239
+
240
+ private
241
+
242
+ # Checks whether this project has any RSpec files
243
+ def has_specs?
244
+ FileList[spec_pattern].any?
245
+ end
246
+
247
+ # Checks whether this project has any unit test files
248
+ def has_tests?
249
+ FileList[test_pattern].any?
246
250
  end
251
+
252
+ # Loads the gemspec file
253
+ def load_gemspec!
254
+ @gemspec = eval(File.read(@gemspec_file))
255
+ end
256
+
257
+ # Updates the VERSION file with the new version
258
+ def update_version_file(version)
259
+ if File.exists?('VERSION')
260
+ File.open('VERSION', 'w') { |f| f << version.to_s }
261
+ modified_files << 'VERSION'
262
+ end
263
+ end
264
+
265
+ # Updates the VERSION constant in the main include file if it exists
266
+ def update_version_constant(version)
267
+ if main_include && File.exist?(main_include)
268
+ file_contents = File.read(main_include)
269
+ if file_contents.sub!(/^(\s+VERSION\s*=\s*)[^\s].*$/) { $1 + version.to_s.inspect }
270
+ File.open(main_include, 'w') { |f| f << file_contents }
271
+ modified_files << main_include
272
+ end
273
+ end
274
+ end
275
+
276
+ # Updates an attribute of the gemspec file.
277
+ # This function will open the file, and search/replace the attribute using a regular expression.
278
+ def update_gemspec(attribute, new_value, literal = false)
279
+
280
+ unless literal
281
+ new_value = case new_value
282
+ when Array then "%w(#{new_value.join(' ')})"
283
+ when Hash, String then new_value.inspect
284
+ when Date then new_value.strftime('%Y-%m-%d').inspect
285
+ else raise "Cannot write value #{new_value.inspect} to gemspec file!"
286
+ end
287
+ end
288
+
289
+ spec = File.read(gemspec_file)
290
+ regexp = Regexp.new('^(\s+\w+\.' + Regexp.quote(attribute.to_s) + '\s*=\s*)[^\s].*$')
291
+ if spec.sub!(regexp) { $1 + new_value }
292
+ File.open(gemspec_file, 'w') { |f| f << spec }
293
+ modified_files << gemspec_file
294
+
295
+ # Reload the gemspec so the changes are incorporated
296
+ load_gemspec!
297
+ end
298
+ end
299
+
300
+ # Updates the tasks file using the latest file found on Github
301
+ def update_tasks_task
302
+ require 'net/http'
303
+
304
+ server = 'github.com'
305
+ path = '/wvanbergen/github-gem/raw/master/tasks/github-gem.rake'
306
+
307
+ Net::HTTP.start(server) do |http|
308
+ response = http.get(path)
309
+ open(__FILE__, "w") { |file| file.write(response.body) }
310
+ end
311
+ puts "Updated gem release tasks file with latest version."
312
+ end
313
+
247
314
  end
248
315
  end
249
-
250
- Rake::GithubGem.define_tasks!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wvanbergen-http_status_exceptions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willem van Bergen
@@ -9,10 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-24 00:00:00 -07:00
12
+ date: 2009-09-26 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: action_controller
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
16
35
  description: Clean up your controller code by raising exceptions that generate responses with different HTTP status codes.
17
36
  email:
18
37
  - willem@vanbergen.org
@@ -23,16 +42,19 @@ extensions: []
23
42
  extra_rdoc_files: []
24
43
 
25
44
  files:
26
- - MIT-LICENSE
27
- - README.rdoc
28
- - Rakefile
45
+ - spec/spec_helper.rb
46
+ - http_status_exceptions.gemspec
47
+ - .gitignore
29
48
  - init.rb
30
- - lib
31
49
  - lib/http_status_exceptions.rb
32
- - tasks
50
+ - Rakefile
51
+ - MIT-LICENSE
33
52
  - tasks/github-gem.rake
53
+ - README.rdoc
54
+ - spec/http_status_exception_spec.rb
34
55
  has_rdoc: false
35
56
  homepage: http://github.com/wvanbergen/http_status_exceptions/wikis
57
+ licenses:
36
58
  post_install_message:
37
59
  rdoc_options: []
38
60
 
@@ -53,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
53
75
  requirements: []
54
76
 
55
77
  rubyforge_project:
56
- rubygems_version: 1.2.0
78
+ rubygems_version: 1.3.5
57
79
  signing_key:
58
80
  specification_version: 2
59
81
  summary: A Rails plugin to use exceptions for generating HTTP status responses