responders 2.4.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 0d361bfe3389f2e44b47a078d164fd6cd90bfedb
4
- data.tar.gz: 4c3c731cbd5d2bb82be8566b3ca2c9f81267be9c
2
+ SHA256:
3
+ metadata.gz: 00a016ab308a0960fc75a6dc1d6f8b35b3165fe0edfef25cb3b898631c7c0454
4
+ data.tar.gz: bf658c0505d528307b5b61b9c1854fa76b50269c7ddedc27f7c3816e588c2a1f
5
5
  SHA512:
6
- metadata.gz: 2105787536e9ea7484910379a1a0912eb0eaa4a7560289ac0f99d7d2f0779c5c7784d52ea69543d75b3a882c0b48d9ba7d6b7f51683c72db4367072489d76d09
7
- data.tar.gz: 44b4014266a8573a5effb2aed8ce5a17c1642d8166411e88822df8a71825efe4f0a463315b22511191c38c02d8a4fb1bb465ef0c813f0c6db316d2196915dd0d
6
+ metadata.gz: 316cf7158bbfede88e505b1b2dfe25cf86ef873f678362da6062d5b4093849a190da2f730265021e7a3613f5a5bb1622553bc423d8850226ee5235083a9cf38b
7
+ data.tar.gz: 7aa5dbc3ef20b9c7ddafa0d8342067eaccfc2b50231eef76c00cf7c9a5e07703d449110ee4ec8dc4f3dcb9fa7c06472e0635cc3c41d05820a193c9f7445d14e7
@@ -1,3 +1,16 @@
1
+ ## 3.0.1
2
+
3
+ * Add support to Ruby 2.7
4
+
5
+ ## 3.0.0
6
+
7
+ * Remove support for Rails 4.2
8
+ * Remove support for Ruby < 2.4
9
+
10
+ ## 2.4.1
11
+
12
+ * Add support for Rails 6 beta
13
+
1
14
  ## 2.4.0
2
15
 
3
16
  * `respond_with` now accepts a new kwargs called `:render` which goes straight to the `render`
@@ -1,4 +1,5 @@
1
- Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
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
  [![Gem Version](https://fury-badge.herokuapp.com/rb/responders.svg)](http://badge.fury.io/rb/responders)
4
- [![Build Status](https://api.travis-ci.org/plataformatec/responders.svg?branch=master)](http://travis-ci.org/plataformatec/responders)
5
- [![Code Climate](https://codeclimate.com/github/plataformatec/responders.svg)](https://codeclimate.com/github/plataformatec/responders)
4
+ [![Build Status](https://api.travis-ci.org/plataformatec/responders.svg?branch=master)](http://travis-ci.org/heartcombo/responders)
5
+ [![Code Climate](https://codeclimate.com/github/plataformatec/responders.svg)](https://codeclimate.com/github/heartcombo/responders)
6
6
 
7
- A set of responders modules to dry up your Rails 4.2+ app.
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 "bob@bob.com was successfully created" instead of the default "Invitation was successfully created."
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
- config.app_generators.scaffold_controller :responders_controller
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 successfull or not, and relies on your controllers to call
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
- mime type was not configured through the class level `respond_to`, but the
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`
@@ -241,7 +243,7 @@ end
241
243
 
242
244
  ## Examples
243
245
 
244
- Want more examples ? Check out this blog posts:
246
+ Want more examples ? Check out these blog posts:
245
247
 
246
248
  * [Embracing REST with mind, body and soul](http://blog.plataformatec.com.br/2009/08/embracing-rest-with-mind-body-and-soul/)
247
249
  * [Three reasons to love ActionController::Responder](http://weblog.rubyonrails.org/2009/8/31/three-reasons-love-responder/)
@@ -251,6 +253,6 @@ Want more examples ? Check out this 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/plataformatec/responders/issues
256
+ http://github.com/heartcombo/responders/issues
255
257
 
256
- MIT License. Copyright 2009-2016 Plataformatec. http://plataformatec.com.br
258
+ MIT License. Copyright 2020 Rafael França, Carlos Antônio da Silva. Copyright 2009-2019 Plataformatec.
@@ -1,5 +1,7 @@
1
- require 'active_support/core_ext/array/extract_options'
2
- require 'action_controller/metal/mime_responds'
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(&:to_s)
41
- except_actions = Array(options.delete(:except)).map(&:to_s)
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,11 +190,11 @@ 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. Usefull if for example you
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
  #
195
- # response_with(resource, render: { template: 'path/to/template', status: 422 })
197
+ # respond_with(resource, render: { template: 'path/to/template', status: 422 })
196
198
  def respond_with(*resources, &block)
197
199
  if self.class.mimes_for_respond_to.empty?
198
200
  raise "In order to use respond_with, first you need to declare the " \
@@ -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.to_s
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
- require 'active_support/json'
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
- :post => :new,
125
- :patch => :edit,
126
- :put => :edit
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, :to => :controller
146
- delegate :get?, :post?, :patch?, :put?, :delete?, :to => :request
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, :status => :created, :location => api_location
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
- {:errors => resource.errors}
296
+ { errors: resource.errors }
295
297
  end
296
298
 
297
299
  def response_overridden?
@@ -1,4 +1,6 @@
1
- require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator'
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
2
4
 
3
5
  module Rails
4
6
  module Generators
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Responders
2
4
  module Generators
3
5
  class InstallGenerator < Rails::Generators::Base
@@ -1,18 +1,20 @@
1
- require 'action_controller'
2
- require 'rails/railtie'
1
+ # frozen_string_literal: true
2
+
3
+ require "action_controller"
4
+ require "rails/railtie"
3
5
 
4
6
  module ActionController
5
- autoload :Responder, 'action_controller/responder'
6
- autoload :RespondWith, 'action_controller/respond_with'
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, 'responders/flash_responder'
11
- autoload :HttpCacheResponder, 'responders/http_cache_responder'
12
- autoload :CollectionResponder, 'responders/collection_responder'
13
- autoload :LocationResponder, 'responders/location_responder'
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 'responders/controller_method'
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 'active_support/i18n'
24
- I18n.load_path << File.expand_path('../responders/locales/en.yml', __FILE__)
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
  # This responder modifies your current responder to redirect
3
5
  # to the collection page on POST/PUT/DELETE.
@@ -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 = case 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
- :default => flash_defaults_by_namespace(status),
152
- :resource_name => resource_name,
153
- :downcase_resource_name => resource_name.downcase
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('.')}.#{controller.action_name}.#{status}"
189
+ controller_scope = :"flash.#{slices.fill(controller.controller_name, -1).join(".")}.#{controller.action_name}.#{status}"
188
190
 
189
- actions_scope = lookup ? slices.fill('actions', -1).join('.') : :actions
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Responders
2
4
  module LocationResponder
3
5
  def self.included(_base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Responders
2
- VERSION = "2.4.0".freeze
4
+ VERSION = "3.0.1"
3
5
  end
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: 2.4.0
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: 2017-04-28 00:00:00.000000000 Z
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: 4.2.0
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5.3'
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: 4.2.0
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5.3'
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: 4.2.0
40
- - - "<"
41
- - !ruby/object:Gem::Version
42
- version: '5.3'
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: 4.2.0
50
- - - "<"
51
- - !ruby/object:Gem::Version
52
- version: '5.3'
40
+ version: '5.0'
53
41
  description: A set of Rails responders to dry up your application
54
- email: contact@plataformatec.com.br
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: http://github.com/plataformatec/responders
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: '0'
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
- rubyforge_project: responders
97
- rubygems_version: 2.6.11
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