straides 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Straides
1
+ # Straides [![Build Status](https://secure.travis-ci.org/kevgo/straides.png)](http://travis-ci.org/#!/kevgo/straides)
2
2
 
3
3
  Better HTTP STatus coDES for RAIls!
4
4
 
@@ -9,11 +9,15 @@ in controllers. It makes it possible, for example, to abort execution of a reque
9
9
 
10
10
  1. Add the gem to your Gemfile.
11
11
 
12
- gem 'straides'
12
+ ```ruby
13
+ gem 'straides'
14
+ ```
13
15
 
14
16
  2. Update your gem bundle.
15
17
 
16
- $ bundle install
18
+ ```bash
19
+ $ bundle install
20
+ ```
17
21
 
18
22
 
19
23
  # Usage
@@ -22,11 +26,13 @@ Straides provides a helper method called `error`. Call it at any time with the H
22
26
  and optionally additional parameters for `render` to abort the current request and render an
23
27
  error message.
24
28
 
25
- # Stop controller execution and return the request with the given HTTP error.
26
- error 404 unless [condition]
29
+ ```ruby
30
+ # Stop controller execution and return the request with the given HTTP error.
31
+ error 404 unless [condition]
27
32
 
28
- # Abort with an error if an operation didn't return a result.
29
- user = User.find_by_username(params[:id]) or error 401
33
+ # Abort with an error if an operation didn't return a result.
34
+ user = User.find_by_username(params[:id]) or error 401
35
+ ```
30
36
 
31
37
 
32
38
  ## Customizing the response
@@ -39,25 +45,29 @@ Straides returns reasonable default responses dependent on the request format.
39
45
  These behaviors can be customized by providing the call to `error` with the same parameters
40
46
  as you would give to [render](http://apidock.com/rails/ActionController/Base/render) in Rails.
41
47
 
42
- # Provide a custom error message in the response body.
43
- error 401, :text => 'Please log in first.'
48
+ ```ruby
49
+ # Provide a custom error message in the response body.
50
+ error 401, :text => 'Please log in first.'
44
51
 
45
- # Render a different file in the response body.
46
- error 404, :file => 'public/custom_404.html'
52
+ # Render a different file in the response body.
53
+ error 404, :file => 'public/custom_404.html'
47
54
 
48
- # Render a custom JSON response.
49
- error 401, :json => { :code => 401, :message => 'Please log in first.' }
55
+ # Render a custom JSON response.
56
+ error 401, :json => { :code => 401, :message => 'Please log in first.' }
57
+ ```
50
58
 
51
59
 
52
60
  # Customizing Straides
53
61
 
54
62
  Straides can be configured by creating an initializer file at _config/initializers/straides.rb_.
55
63
 
56
- Straides.configure do |config|
64
+ ```ruby
65
+ Straides.configure do |config|
57
66
 
58
- # Disable auto-loading of Straides into every controller.
59
- config.auto_load = false
60
- end
67
+ # Disable auto-loading of Straides into every controller.
68
+ config.auto_load = false
69
+ end
70
+ ```
61
71
 
62
72
 
63
73
  ## Auto-loading
@@ -67,8 +77,10 @@ If you don't want that, for example because you only want to use Straides in cer
67
77
  you can disable this auto-loading behavior with `config.auto_load = false`.
68
78
  Please note that you then have to include Straides into every controller manually, like this:
69
79
 
70
- class FooController < ApplicationController
71
- include Straides
80
+ ```ruby
81
+ class FooController < ApplicationController
82
+ include Straides
72
83
 
73
- ...
74
- end
84
+ ...
85
+ end
86
+ ```
data/Rakefile CHANGED
@@ -24,18 +24,6 @@ end
24
24
 
25
25
  Bundler::GemHelper.install_tasks
26
26
 
27
- desc 'Default: run the specs and features.'
28
- task :default => 'spec:unit' do
29
- system("bundle exec rake spec")
30
- end
31
-
32
- namespace :spec do
33
-
34
- desc "Run unit specs"
35
- RSpec::Core::RakeTask.new('unit') do |t|
36
- t.pattern = 'spec/{*_spec.rb}'
37
- end
38
- end
39
-
40
- desc "Run the unit tests"
41
- task :spec => ['spec:unit']
27
+ # RSpec tasks.
28
+ RSpec::Core::RakeTask.new :spec
29
+ task :default => :spec
data/lib/straides.rb CHANGED
@@ -30,7 +30,7 @@ module Straides
30
30
  if request.send(:format).html?
31
31
  status_code = error.render_options[:status] || '500'
32
32
  status_code = Rack::Utils.status_code(error.render_options[:status]) if status_code.is_a?(Symbol)
33
- error.render_options[:file] = "public/#{status_code}.html"
33
+ error.render_options[:file] = "public/#{status_code}"
34
34
  error.render_options[:formats] = [:html]
35
35
  else
36
36
  error.render_options[:nothing] = true
@@ -7,7 +7,8 @@ module Straides
7
7
  # Initialize Straides after the Rails initializers have run.
8
8
  config.after_initialize do
9
9
  if Straides::Configuration.instance.auto_load
10
- ActionController::Base.send :include, Straides
10
+ # Note (KG): Including Straides into ActionController::Base here doesn't work in unit tests.
11
+ ApplicationController.send :include, Straides
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module Straides
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straides
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-01 00:00:00.000000000Z
12
+ date: 2012-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70131147045200 !ruby/object:Gem::Requirement
16
+ requirement: &70173022005160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70131147045200
24
+ version_requirements: *70173022005160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack
27
- requirement: &70131147044100 !ruby/object:Gem::Requirement
27
+ requirement: &70173022004220 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70131147044100
35
+ version_requirements: *70173022004220
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70131147042480 !ruby/object:Gem::Requirement
38
+ requirement: &70173022000440 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70131147042480
46
+ version_requirements: *70173022000440
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &70131147041480 !ruby/object:Gem::Requirement
49
+ requirement: &70173021999140 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70131147041480
57
+ version_requirements: *70173021999140
58
58
  description: A more convenient way to return different HTTP status codes from Rails.
59
59
  email:
60
60
  - kevin.goslar@gmail.com
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 1.8.10
93
+ rubygems_version: 1.8.15
94
94
  signing_key:
95
95
  specification_version: 3
96
96
  summary: HTTP STatus coDES for RAIls