problem_details-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/problem_details-rails.rb +3 -0
- data/lib/problem_details/rails.rb +9 -0
- data/lib/problem_details/rails/config.rb +27 -0
- data/lib/problem_details/rails/railtie.rb +17 -0
- data/lib/problem_details/rails/render_option_builder.rb +23 -0
- data/problem_details-rails.gemspec +29 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 28c3dbae235a1977ebf1b0020708b00eeda28fe6
|
4
|
+
data.tar.gz: 54405d35d097d1da2cc1bea4f5f4259dff67df0b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4b975fa68bf2a498d167e74a2a1d0cf529699f3d6e68140d29519dd1dc38430771111b300ae47517298435c745a2e0f15a068883f99528e4f6bdd095fc58439e
|
7
|
+
data.tar.gz: 441cb4d5c915e25043e741f6f47686fa5d07ade7fe79dfcbcdad66bb4304d18b5f83cea12fb3b6b303e3c4ba6be3a9b8091647bff892db7d81599cf8ec128aa8
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ProblemDetails
|
4
|
+
module Rails
|
5
|
+
# Configures global settings for ProblemDetails::Rails
|
6
|
+
# ProblemDetails::Rails.configure do |config|
|
7
|
+
# config.default_json_content_type = 'application/json'
|
8
|
+
# end
|
9
|
+
class << self
|
10
|
+
def configure
|
11
|
+
yield config
|
12
|
+
end
|
13
|
+
|
14
|
+
def config
|
15
|
+
@config ||= Config.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Config
|
20
|
+
attr_accessor :default_json_content_type
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@default_json_content_type = 'application/problem+json'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ProblemDetails
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
initializer 'problem_details.initialize' do |_app|
|
6
|
+
ActiveSupport.on_load(:action_controller) do
|
7
|
+
require 'problem_details'
|
8
|
+
require 'problem_details/rails/render_option_builder'
|
9
|
+
|
10
|
+
ActionController::Renderers.add :problem do |content, options|
|
11
|
+
builder = ProblemDetails::Rails::RenderOptionBuilder.new(content, options)
|
12
|
+
render(**builder.build)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ProblemDetails
|
4
|
+
module Rails
|
5
|
+
# A builder to build a hash that is passed to ActionController's render method.
|
6
|
+
class RenderOptionBuilder
|
7
|
+
# @param [Hash] content given as a value of :problem key of render method.
|
8
|
+
# @param [Hash] options options of render method.
|
9
|
+
def initialize(content, options)
|
10
|
+
@content = content
|
11
|
+
@options = options.dup
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Hash] build a hash being passed to render method.
|
15
|
+
def build
|
16
|
+
content_type = @options.delete(:content_type) || ProblemDetails::Rails.config.default_json_content_type
|
17
|
+
status = @options.delete(:status) || :ok
|
18
|
+
document = ProblemDetails::Document.new(status: status, **@content)
|
19
|
+
{ json: document.to_h, status: status, content_type: content_type, **@options }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'problem_details/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'problem_details-rails'
|
9
|
+
spec.version = ProblemDetails::VERSION
|
10
|
+
spec.authors = ['Nobuhiro Nikushi']
|
11
|
+
spec.email = ['deneb.ge@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Add a :problem renderer that renponds with RFC 7807 Problem Details format'
|
14
|
+
spec.description = spec.summary
|
15
|
+
spec.homepage = 'https://github.com/nikushi/problem_details'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files|grep rails`.split($OUTPUT_RECORD_SEPARATOR).reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_runtime_dependency 'problem_details', ProblemDetails::VERSION
|
24
|
+
spec.add_dependency 'actionpack', '>= 4.0'
|
25
|
+
spec.add_dependency 'activesupport', '>= 4.0'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: problem_details-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nobuhiro Nikushi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: problem_details
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: actionpack
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Add a :problem renderer that renponds with RFC 7807 Problem Details format
|
98
|
+
email:
|
99
|
+
- deneb.ge@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- lib/problem_details-rails.rb
|
105
|
+
- lib/problem_details/rails.rb
|
106
|
+
- lib/problem_details/rails/config.rb
|
107
|
+
- lib/problem_details/rails/railtie.rb
|
108
|
+
- lib/problem_details/rails/render_option_builder.rb
|
109
|
+
- problem_details-rails.gemspec
|
110
|
+
homepage: https://github.com/nikushi/problem_details
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.5.1
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: Add a :problem renderer that renponds with RFC 7807 Problem Details format
|
134
|
+
test_files: []
|