responders 2.4.1 → 3.0.1
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 +4 -4
- data/CHANGELOG.md +9 -0
- data/MIT-LICENSE +2 -1
- data/README.md +11 -9
- data/lib/action_controller/respond_with.rb +8 -6
- data/lib/action_controller/responder.rb +12 -10
- data/lib/generators/rails/responders_controller_generator.rb +3 -1
- data/lib/generators/rails/templates/{api_controller.rb → api_controller.rb.tt} +0 -0
- data/lib/generators/rails/templates/{controller.rb → controller.rb.tt} +0 -0
- data/lib/generators/responders/install_generator.rb +2 -0
- data/lib/responders/collection_responder.rb +2 -0
- data/lib/responders/controller_method.rb +4 -1
- data/lib/responders/flash_responder.rb +10 -8
- data/lib/responders/http_cache_responder.rb +3 -1
- data/lib/responders/location_responder.rb +2 -0
- data/lib/responders/version.rb +3 -1
- data/lib/responders.rb +13 -11
- metadata +12 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00a016ab308a0960fc75a6dc1d6f8b35b3165fe0edfef25cb3b898631c7c0454
|
4
|
+
data.tar.gz: bf658c0505d528307b5b61b9c1854fa76b50269c7ddedc27f7c3816e588c2a1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 316cf7158bbfede88e505b1b2dfe25cf86ef873f678362da6062d5b4093849a190da2f730265021e7a3613f5a5bb1622553bc423d8850226ee5235083a9cf38b
|
7
|
+
data.tar.gz: 7aa5dbc3ef20b9c7ddafa0d8342067eaccfc2b50231eef76c00cf7c9a5e07703d449110ee4ec8dc4f3dcb9fa7c06472e0635cc3c41d05820a193c9f7445d14e7
|
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
Copyright
|
1
|
+
Copyright (c) 2020 Rafael França, Carlos Antônio da Silva
|
2
|
+
Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
|
2
3
|
|
3
4
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
5
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Responders
|
2
2
|
|
3
3
|
[](http://badge.fury.io/rb/responders)
|
4
|
-
[](http://travis-ci.org/
|
5
|
-
[](https://codeclimate.com/github/
|
4
|
+
[](http://travis-ci.org/heartcombo/responders)
|
5
|
+
[](https://codeclimate.com/github/heartcombo/responders)
|
6
6
|
|
7
|
-
A set of responders modules to dry up your Rails
|
7
|
+
A set of responders modules to dry up your Rails app.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
@@ -179,19 +179,21 @@ class InvitationsController < ApplicationController
|
|
179
179
|
end
|
180
180
|
```
|
181
181
|
|
182
|
-
Now you would see the message "
|
182
|
+
Now you would see the message `"name@example.com was successfully created"` instead of the default `"Invitation was successfully created."`
|
183
183
|
|
184
184
|
## Generator
|
185
185
|
|
186
186
|
This gem also includes a responders controller generator, so your scaffold can be customized
|
187
187
|
to use `respond_with` instead of default `respond_to` blocks. From 2.1, you need to explicitly opt-in to use this generator by adding the following to your `config/application.rb`:
|
188
188
|
|
189
|
-
|
189
|
+
```ruby
|
190
|
+
config.app_generators.scaffold_controller :responders_controller
|
191
|
+
```
|
190
192
|
|
191
193
|
## Failure handling
|
192
194
|
|
193
195
|
Responders don't use `valid?` to check for errors in models to figure out if
|
194
|
-
the request was
|
196
|
+
the request was successful or not, and relies on your controllers to call
|
195
197
|
`save` or `create` to trigger the validations.
|
196
198
|
|
197
199
|
```ruby
|
@@ -219,7 +221,7 @@ end
|
|
219
221
|
## Verifying request formats
|
220
222
|
|
221
223
|
`respond_with` will raise an `ActionController::UnknownFormat` if the request
|
222
|
-
|
224
|
+
MIME type was not configured through the class level `respond_to`, but the
|
223
225
|
action will still be executed and any side effects (like creating a new record)
|
224
226
|
will still occur. To raise the `UnknownFormat` exception before your action
|
225
227
|
is invoked you can set the `verify_requested_format!` method as a `before_action`
|
@@ -251,6 +253,6 @@ Want more examples ? Check out these blog posts:
|
|
251
253
|
|
252
254
|
If you discover any bugs or want to drop a line, feel free to create an issue on GitHub.
|
253
255
|
|
254
|
-
http://github.com/
|
256
|
+
http://github.com/heartcombo/responders/issues
|
255
257
|
|
256
|
-
MIT License. Copyright 2009-
|
258
|
+
MIT License. Copyright 2020 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
|
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/array/extract_options"
|
4
|
+
require "action_controller/metal/mime_responds"
|
3
5
|
|
4
6
|
module ActionController #:nodoc:
|
5
7
|
module RespondWith
|
@@ -37,8 +39,8 @@ module ActionController #:nodoc:
|
|
37
39
|
def respond_to(*mimes)
|
38
40
|
options = mimes.extract_options!
|
39
41
|
|
40
|
-
only_actions = Array(options.delete(:only)).map(&:
|
41
|
-
except_actions = Array(options.delete(:except)).map(&:
|
42
|
+
only_actions = Array(options.delete(:only)).map(&:to_sym)
|
43
|
+
except_actions = Array(options.delete(:except)).map(&:to_sym)
|
42
44
|
|
43
45
|
hash = mimes_for_respond_to.dup
|
44
46
|
mimes.each do |mime|
|
@@ -188,7 +190,7 @@ module ActionController #:nodoc:
|
|
188
190
|
# 2. <tt>:action</tt> - overwrites the default render action used after an
|
189
191
|
# unsuccessful html +post+ request.
|
190
192
|
# 3. <tt>:render</tt> - allows to pass any options directly to the <tt>:render<tt/>
|
191
|
-
# call after unsuccessful html +post+ request.
|
193
|
+
# call after unsuccessful html +post+ request. Useful if for example you
|
192
194
|
# need to render a template which is outside of controller's path or you
|
193
195
|
# want to override the default http <tt>:status</tt> code, e.g.
|
194
196
|
#
|
@@ -238,7 +240,7 @@ module ActionController #:nodoc:
|
|
238
240
|
# Collect mimes declared in the class method respond_to valid for the
|
239
241
|
# current action.
|
240
242
|
def collect_mimes_from_class_level #:nodoc:
|
241
|
-
action = action_name.
|
243
|
+
action = action_name.to_sym
|
242
244
|
|
243
245
|
self.class.mimes_for_respond_to.keys.select do |mime|
|
244
246
|
config = self.class.mimes_for_respond_to[mime]
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/json"
|
2
4
|
|
3
5
|
module ActionController #:nodoc:
|
4
6
|
# Responsible for exposing a resource to different mime requests,
|
@@ -121,12 +123,12 @@ module ActionController #:nodoc:
|
|
121
123
|
attr_reader :controller, :request, :format, :resource, :resources, :options
|
122
124
|
|
123
125
|
DEFAULT_ACTIONS_FOR_VERBS = {
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
126
|
+
post: :new,
|
127
|
+
patch: :edit,
|
128
|
+
put: :edit
|
127
129
|
}
|
128
130
|
|
129
|
-
def initialize(controller, resources, options={})
|
131
|
+
def initialize(controller, resources, options = {})
|
130
132
|
@controller = controller
|
131
133
|
@request = @controller.request
|
132
134
|
@format = @controller.formats.first
|
@@ -142,8 +144,8 @@ module ActionController #:nodoc:
|
|
142
144
|
end
|
143
145
|
end
|
144
146
|
|
145
|
-
delegate :head, :render, :redirect_to, :
|
146
|
-
delegate :get?, :post?, :patch?, :put?, :delete?, :
|
147
|
+
delegate :head, :render, :redirect_to, to: :controller
|
148
|
+
delegate :get?, :post?, :patch?, :put?, :delete?, to: :request
|
147
149
|
|
148
150
|
# Undefine :to_json and :to_yaml since it's defined on Object
|
149
151
|
undef_method(:to_json) if method_defined?(:to_json)
|
@@ -213,7 +215,7 @@ module ActionController #:nodoc:
|
|
213
215
|
if get?
|
214
216
|
display resource
|
215
217
|
elsif post?
|
216
|
-
display resource, :
|
218
|
+
display resource, status: :created, location: api_location
|
217
219
|
else
|
218
220
|
head :no_content
|
219
221
|
end
|
@@ -256,7 +258,7 @@ module ActionController #:nodoc:
|
|
256
258
|
#
|
257
259
|
# render xml: @user, status: :created
|
258
260
|
#
|
259
|
-
def display(resource, given_options={})
|
261
|
+
def display(resource, given_options = {})
|
260
262
|
controller.render given_options.merge!(options).merge!(format => resource)
|
261
263
|
end
|
262
264
|
|
@@ -291,7 +293,7 @@ module ActionController #:nodoc:
|
|
291
293
|
end
|
292
294
|
|
293
295
|
def json_resource_errors
|
294
|
-
{:
|
296
|
+
{ errors: resource.errors }
|
295
297
|
end
|
296
298
|
|
297
299
|
def response_overridden?
|
File without changes
|
File without changes
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Responders
|
2
4
|
module ControllerMethod
|
3
5
|
# Adds the given responders to the current controller's responder, allowing you to cherry-pick
|
@@ -18,7 +20,8 @@ module Responders
|
|
18
20
|
#
|
19
21
|
def responders(*responders)
|
20
22
|
self.responder = responders.inject(Class.new(responder)) do |klass, responder|
|
21
|
-
responder =
|
23
|
+
responder = \
|
24
|
+
case responder
|
22
25
|
when Module
|
23
26
|
responder
|
24
27
|
when String, Symbol
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Responders
|
2
4
|
# Responder to automatically set flash messages based on I18n API. It checks for
|
3
5
|
# message based on the current action, but also allows defaults to be set, using
|
@@ -94,7 +96,7 @@ module Responders
|
|
94
96
|
ActionView::Helpers::TagHelper
|
95
97
|
)
|
96
98
|
|
97
|
-
def initialize(controller, resources, options={})
|
99
|
+
def initialize(controller, resources, options = {})
|
98
100
|
super
|
99
101
|
@flash = options.delete(:flash)
|
100
102
|
@notice = options.delete(:notice)
|
@@ -126,7 +128,7 @@ module Responders
|
|
126
128
|
return if controller.flash[status].present?
|
127
129
|
|
128
130
|
options = mount_i18n_options(status)
|
129
|
-
message = Responders::FlashResponder.helper.t options[:default].shift, options
|
131
|
+
message = Responders::FlashResponder.helper.t options[:default].shift, **options
|
130
132
|
set_flash(status, message)
|
131
133
|
end
|
132
134
|
|
@@ -148,9 +150,9 @@ module Responders
|
|
148
150
|
|
149
151
|
def mount_i18n_options(status) #:nodoc:
|
150
152
|
options = {
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
153
|
+
default: flash_defaults_by_namespace(status),
|
154
|
+
resource_name: resource_name,
|
155
|
+
downcase_resource_name: resource_name.downcase
|
154
156
|
}
|
155
157
|
|
156
158
|
controller_options = controller_interpolation_options
|
@@ -180,13 +182,13 @@ module Responders
|
|
180
182
|
|
181
183
|
def flash_defaults_by_namespace(status) #:nodoc:
|
182
184
|
defaults = []
|
183
|
-
slices = controller.controller_path.split(
|
185
|
+
slices = controller.controller_path.split("/")
|
184
186
|
lookup = Responders::FlashResponder.namespace_lookup
|
185
187
|
|
186
188
|
begin
|
187
|
-
controller_scope = :"flash.#{slices.fill(controller.controller_name, -1).join(
|
189
|
+
controller_scope = :"flash.#{slices.fill(controller.controller_name, -1).join(".")}.#{controller.action_name}.#{status}"
|
188
190
|
|
189
|
-
actions_scope = lookup ? slices.fill(
|
191
|
+
actions_scope = lookup ? slices.fill("actions", -1).join(".") : :actions
|
190
192
|
actions_scope = :"flash.#{actions_scope}.#{controller.action_name}.#{status}"
|
191
193
|
|
192
194
|
defaults << :"#{controller_scope}_html"
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Responders
|
2
4
|
# Set HTTP Last-Modified headers based on the given resource. It's used only
|
3
5
|
# on API behavior (to_format) and is useful for a client to check in the server
|
@@ -9,7 +11,7 @@ module Responders
|
|
9
11
|
# the digest of the body.
|
10
12
|
#
|
11
13
|
module HttpCacheResponder
|
12
|
-
def initialize(controller, resources, options={})
|
14
|
+
def initialize(controller, resources, options = {})
|
13
15
|
super
|
14
16
|
@http_cache = options.delete(:http_cache)
|
15
17
|
end
|
data/lib/responders/version.rb
CHANGED
data/lib/responders.rb
CHANGED
@@ -1,18 +1,20 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_controller"
|
4
|
+
require "rails/railtie"
|
3
5
|
|
4
6
|
module ActionController
|
5
|
-
autoload :Responder,
|
6
|
-
autoload :RespondWith,
|
7
|
+
autoload :Responder, "action_controller/responder"
|
8
|
+
autoload :RespondWith, "action_controller/respond_with"
|
7
9
|
end
|
8
10
|
|
9
11
|
module Responders
|
10
|
-
autoload :FlashResponder,
|
11
|
-
autoload :HttpCacheResponder,
|
12
|
-
autoload :CollectionResponder,
|
13
|
-
autoload :LocationResponder,
|
12
|
+
autoload :FlashResponder, "responders/flash_responder"
|
13
|
+
autoload :HttpCacheResponder, "responders/http_cache_responder"
|
14
|
+
autoload :CollectionResponder, "responders/collection_responder"
|
15
|
+
autoload :LocationResponder, "responders/location_responder"
|
14
16
|
|
15
|
-
require
|
17
|
+
require "responders/controller_method"
|
16
18
|
|
17
19
|
class Railtie < ::Rails::Railtie
|
18
20
|
config.responders = ActiveSupport::OrderedOptions.new
|
@@ -20,8 +22,8 @@ module Responders
|
|
20
22
|
config.responders.namespace_lookup = false
|
21
23
|
|
22
24
|
# Add load paths straight to I18n, so engines and application can overwrite it.
|
23
|
-
require
|
24
|
-
I18n.load_path << File.expand_path(
|
25
|
+
require "active_support/i18n"
|
26
|
+
I18n.load_path << File.expand_path("../responders/locales/en.yml", __FILE__)
|
25
27
|
|
26
28
|
initializer "responders.flash_responder" do |app|
|
27
29
|
Responders::FlashResponder.flash_keys = app.config.responders.flash_keys
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: responders
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -16,42 +16,30 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '6.0'
|
19
|
+
version: '5.0'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '6.0'
|
26
|
+
version: '5.0'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
name: actionpack
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
31
|
- - ">="
|
38
32
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
-
- - "<"
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: '6.0'
|
33
|
+
version: '5.0'
|
43
34
|
type: :runtime
|
44
35
|
prerelease: false
|
45
36
|
version_requirements: !ruby/object:Gem::Requirement
|
46
37
|
requirements:
|
47
38
|
- - ">="
|
48
39
|
- !ruby/object:Gem::Version
|
49
|
-
version:
|
50
|
-
- - "<"
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: '6.0'
|
40
|
+
version: '5.0'
|
53
41
|
description: A set of Rails responders to dry up your application
|
54
|
-
email:
|
42
|
+
email: heartcombo@googlegroups.com
|
55
43
|
executables: []
|
56
44
|
extensions: []
|
57
45
|
extra_rdoc_files: []
|
@@ -63,8 +51,8 @@ files:
|
|
63
51
|
- lib/action_controller/responder.rb
|
64
52
|
- lib/generators/rails/USAGE
|
65
53
|
- lib/generators/rails/responders_controller_generator.rb
|
66
|
-
- lib/generators/rails/templates/api_controller.rb
|
67
|
-
- lib/generators/rails/templates/controller.rb
|
54
|
+
- lib/generators/rails/templates/api_controller.rb.tt
|
55
|
+
- lib/generators/rails/templates/controller.rb.tt
|
68
56
|
- lib/generators/responders/install_generator.rb
|
69
57
|
- lib/responders.rb
|
70
58
|
- lib/responders/collection_responder.rb
|
@@ -74,7 +62,7 @@ files:
|
|
74
62
|
- lib/responders/locales/en.yml
|
75
63
|
- lib/responders/location_responder.rb
|
76
64
|
- lib/responders/version.rb
|
77
|
-
homepage: https://github.com/
|
65
|
+
homepage: https://github.com/heartcombo/responders
|
78
66
|
licenses:
|
79
67
|
- MIT
|
80
68
|
metadata: {}
|
@@ -86,15 +74,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
74
|
requirements:
|
87
75
|
- - ">="
|
88
76
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
77
|
+
version: 2.4.0
|
90
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
79
|
requirements:
|
92
80
|
- - ">="
|
93
81
|
- !ruby/object:Gem::Version
|
94
82
|
version: '0'
|
95
83
|
requirements: []
|
96
|
-
|
97
|
-
rubygems_version: 2.7.6
|
84
|
+
rubygems_version: 3.1.2
|
98
85
|
signing_key:
|
99
86
|
specification_version: 4
|
100
87
|
summary: A set of Rails responders to dry up your application
|