responders 2.4.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/MIT-LICENSE +1 -1
- data/README.md +2 -2
- data/lib/action_controller/respond_with.rb +7 -5
- 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.rb +13 -11
- data/lib/responders/collection_responder.rb +2 -0
- data/lib/responders/controller_method.rb +4 -1
- data/lib/responders/flash_responder.rb +9 -7
- data/lib/responders/http_cache_responder.rb +3 -1
- data/lib/responders/location_responder.rb +2 -0
- data/lib/responders/version.rb +3 -1
- metadata +10 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e208731d0352ee25ec32e97623939136d0008e8591f7017e31723d33196001d
|
4
|
+
data.tar.gz: 7983c8e1faea117019ea9166714725947cb9770d0c2e208e70dbdca5b3346595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6be9a9d459b573d73e83329a4443bb8e02e353ab3f9fa11c0004ff4dd9c8d073847dd936b4308095236312a1468007f09a04f963fd544a244f2ad7c566412f3
|
7
|
+
data.tar.gz: 6a7bd98426677b71939e1fa1d373ccbb014fd0c25b9f986e2540b9dc76c9ff7307b727bf20034e1fb51e9df45dd070102deb3badefe79f78738426fb3fd06dc9
|
data/CHANGELOG.md
CHANGED
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -179,7 +179,7 @@ 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
|
|
@@ -253,4 +253,4 @@ If you discover any bugs or want to drop a line, feel free to create an issue on
|
|
253
253
|
|
254
254
|
http://github.com/plataformatec/responders/issues
|
255
255
|
|
256
|
-
MIT License. Copyright 2009-
|
256
|
+
MIT License. Copyright 2009-2019 Plataformatec. http://plataformatec.com.br
|
@@ -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|
|
@@ -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
|
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
|
@@ -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)
|
@@ -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
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -16,40 +16,28 @@ 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
42
|
email: contact@plataformatec.com.br
|
55
43
|
executables: []
|
@@ -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
|
@@ -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.0.1
|
98
85
|
signing_key:
|
99
86
|
specification_version: 4
|
100
87
|
summary: A set of Rails responders to dry up your application
|