rack-http-status 0.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +4 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rack/http/status.rb +34 -0
- data/rack-http-status.gemspec +24 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 69aa0c32adff0816285c92c4913d3e9d06762e62
|
4
|
+
data.tar.gz: 1e2a75cd35e0c4c9754a6155e2718234f968710c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02261c69fd5dd99321e3fc95349bc920d35564f938ed873d1b38996b1b79ba928b1e58de09f8e7756500f8a7b0a55dc73f0c2da4de2bd7e0a5448120baafdc6d
|
7
|
+
data.tar.gz: 21c6d205c86e8e04c54d595a5d5987fcb63a10f671d0152c47bd8f2b2f9c6b6433a8be2db8bc42cc47898aa50f3180d8fcacee8ace27a63969077aa8dfd30976
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# Rack::HTTP::Status
|
2
|
+
|
3
|
+
This gem provides exception classes that represent each HTTP status.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'rack-http-status'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install rack-http-status
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# In Rails
|
25
|
+
class ExampleController < ApplicationController
|
26
|
+
include Rack::HTTP::Status
|
27
|
+
rescue_from Status do |status|
|
28
|
+
render plain: "Status code was: #{status.code} - #{status}", status: status
|
29
|
+
end
|
30
|
+
def action1
|
31
|
+
head NoContent # => HTTP 204 No Content
|
32
|
+
end
|
33
|
+
def action2
|
34
|
+
raise NotFound # => HTTP 404 with "Status code was: 404 - Not Found" body
|
35
|
+
end
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
Each status class inherits from `Rack::HTTP::Status`, and contains the following convenience methods:
|
40
|
+
|
41
|
+
| Method | Description | Example |
|
42
|
+
| ------ | ----------- | ------- |
|
43
|
+
| `#to_sym` | Returns the symbolized version of this HTTP status | `NotFound.to_sym #=> :not_found` |
|
44
|
+
| `#to_i` | Returns the HTTP status code's value | `NoContent.to_i #=> 204` |
|
45
|
+
| `#to_s` | Returns the description of the HTTP status | `NonAuthoritativeInformation.to_s #=> "Non-Authoritative Information"` |
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kenaniah/rack-http-status.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rack/http/status"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "rack/utils"
|
2
|
+
|
3
|
+
module Rack
|
4
|
+
module HTTP
|
5
|
+
module Status
|
6
|
+
class Status < Exception
|
7
|
+
class << self
|
8
|
+
attr_accessor :code, :description, :symbol
|
9
|
+
alias_method :to_i, :code
|
10
|
+
alias_method :to_sym, :symbol
|
11
|
+
alias_method :to_s, :description
|
12
|
+
end
|
13
|
+
def to_i
|
14
|
+
self.class.to_i
|
15
|
+
end
|
16
|
+
def to_s
|
17
|
+
self.class.to_s
|
18
|
+
end
|
19
|
+
def to_sym
|
20
|
+
self.class.to_sym
|
21
|
+
end
|
22
|
+
end
|
23
|
+
Rack::Utils::SYMBOL_TO_STATUS_CODE.each do |symbol, code|
|
24
|
+
name = Rack::Utils::HTTP_STATUS_CODES[code]
|
25
|
+
klass = Class.new Status
|
26
|
+
klass.code = code
|
27
|
+
klass.symbol = symbol
|
28
|
+
klass.description = name
|
29
|
+
klass.freeze
|
30
|
+
const_set name.gsub(/[ '-]/, ''), klass
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rack-http-status"
|
6
|
+
spec.version = "0.1.0"
|
7
|
+
spec.authors = ["Kenaniah Cerny"]
|
8
|
+
spec.email = ["kenaniah@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = "Provides exception classes and helpers for HTTP statuses"
|
11
|
+
spec.homepage = "https://github.com/kenaniah/rack-http-status"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
14
|
+
f.match(%r{^(test|spec|features)/})
|
15
|
+
end
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
|
23
|
+
spec.add_dependency "rack", "~> 2.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-http-status
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenaniah Cerny
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- kenaniah@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- README.md
|
65
|
+
- Rakefile
|
66
|
+
- bin/console
|
67
|
+
- bin/setup
|
68
|
+
- lib/rack/http/status.rb
|
69
|
+
- rack-http-status.gemspec
|
70
|
+
homepage: https://github.com/kenaniah/rack-http-status
|
71
|
+
licenses: []
|
72
|
+
metadata: {}
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.8
|
90
|
+
signing_key:
|
91
|
+
specification_version: 4
|
92
|
+
summary: Provides exception classes and helpers for HTTP statuses
|
93
|
+
test_files: []
|