responders 2.0.2 → 2.1.0

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
2
  SHA1:
3
- metadata.gz: 1048b35bc57148e916fc54ea72aa8a0e3f9f7498
4
- data.tar.gz: 8d4c1c0825d565528c29371185d374e8266336ff
3
+ metadata.gz: 06ba4b048f7ab149753ce1222674abcde97594ce
4
+ data.tar.gz: d10721b4e6683ecc3095d709134d9e8785909c7f
5
5
  SHA512:
6
- metadata.gz: 2cd86b1e17658300952e4fea7326eafc6474d9b47ee7520322521a103300fa3ad803ed41c5c7849febdf0769bb7f43085d2898fe589d0b85cc835a9017f7e07c
7
- data.tar.gz: f390f3b7d962ede7cda0b454d45b7864d2606472c33029a24981d84374be0ba8d8f98536aa5af2ef9aa4c0f915e4d2750a2f06278cf4113f82f35e30ceb5dc6a
6
+ metadata.gz: 89dbb2374f73e0090d5ef320ae5d52235a075de8f344475717c1dc45474d86a0a2fd8de8dd8d7a7661f166f014658841106635c57cf1dc9db36b1acea5ad37d5
7
+ data.tar.gz: 973bbda1f6a6b6b4f056a8a5615b170d22f0e954fb2b77625279347e23f85378100fbf1d3079897c69174b304132099ed77c29963741439466bc0fdaff3b7120
@@ -1,3 +1,7 @@
1
+ ## 2.1.0
2
+
3
+ * No longer automatically set the responders generator as many projects may use this gem as a dependency. When upgrading, users will need to add `config.app_generators.scaffold_controller :responders_controller` to their application. The `responders:install` generator has been updated to automatically insert it in new applications
4
+
1
5
  ## 2.0.1
2
6
 
3
7
  * Require `rails/railtie` explicitly before using it
@@ -8,7 +12,7 @@
8
12
 
9
13
  * Import `respond_with` and class-level `respond_to` from Rails
10
14
  * Support only Rails ~> 4.2
11
- * `Responders::LocationResponder` is now included by in the default responder (and therefore deprecated)
15
+ * `Responders::LocationResponder` is now included by the default responder (and therefore deprecated)
12
16
 
13
17
  ## 1.1.0
14
18
 
data/README.md CHANGED
@@ -4,7 +4,18 @@
4
4
  [![Build Status](https://api.travis-ci.org/plataformatec/responders.png?branch=master)](http://travis-ci.org/plataformatec/responders)
5
5
  [![Code Climate](https://codeclimate.com/github/plataformatec/responders.png)](https://codeclimate.com/github/plataformatec/responders)
6
6
 
7
- A set of responders modules to dry up your Rails 3.2+ app.
7
+ A set of responders modules to dry up your Rails 4.2+ app.
8
+
9
+ ## Installation
10
+
11
+ Add the responders gem to your Gemfile:
12
+
13
+ gem "responders"
14
+
15
+ Update your bundle and run the install generator:
16
+
17
+ $ bundle install
18
+ $ rails g responders:install
8
19
 
9
20
  ## Responders Types
10
21
 
@@ -60,15 +71,27 @@ You can also have embedded HTML. Just create a `_html` scope.
60
71
 
61
72
  See also the `namespace_lookup` option to search the full hierarchy of possible keys.
62
73
 
74
+ ### HttpCacheResponder
75
+
76
+ Automatically adds Last-Modified headers to API requests. This
77
+ allows clients to easily query the server if a resource changed and if the client tries
78
+ to retrieve a resource that has not been modified, it returns not_modified status.
79
+
80
+ ### CollectionResponder
81
+
82
+ Makes your create and update action redirect to the collection on success.
83
+
63
84
  ### LocationResponder
64
85
 
65
86
  This responder allows you to use callable objects as the redirect location.
66
87
  Useful when you want to use the `respond_with` method with
67
88
  a custom route that requires persisted objects, but the validation may fail.
68
89
 
90
+ Note: this responder is included by default, and doesn't need to be included
91
+ on the top of your controller (including it will issue a deprecation warning).
92
+
69
93
  ```ruby
70
94
  class ThingsController < ApplicationController
71
- responders :location, :flash
72
95
  respond_to :html
73
96
 
74
97
  def create
@@ -78,46 +101,25 @@ class ThingsController < ApplicationController
78
101
  end
79
102
  ```
80
103
 
81
- ### HttpCacheResponder
82
-
83
- Automatically adds Last-Modified headers to API requests. This
84
- allows clients to easily query the server if a resource changed and if the client tries
85
- to retrieve a resource that has not been modified, it returns not_modified status.
86
-
87
- ### CollectionResponder
88
-
89
- Makes your create and update action redirect to the collection on success.
90
-
91
104
  ## Configuring your own responder
92
105
 
93
- The first step is to install the responders gem and configure it in your application:
94
-
95
- ```console
96
- gem install responders
97
- ```
98
-
99
- In your Gemfile, add this line:
100
-
101
- ```ruby
102
- gem 'responders'
103
- ```
104
-
105
- Responders only provides a set of modules, to use them, you have to create your own
106
- responder. This can be done inside the lib folder for example:
106
+ Responders only provides a set of modules and to use them you have to create your own
107
+ responder. After you run the install command, the following responder will be
108
+ generated in your application:
107
109
 
108
110
  ```ruby
109
- # lib/app_responder.rb
111
+ # lib/application_responder.rb
110
112
  class AppResponder < ActionController::Responder
111
113
  include Responders::FlashResponder
112
114
  include Responders::HttpCacheResponder
113
115
  end
114
116
  ```
115
117
 
116
- And then you need to configure your application to use it:
118
+ Your application also needs to be configured to use it:
117
119
 
118
120
  ```ruby
119
121
  # app/controllers/application_controller.rb
120
- require "app_responder"
122
+ require "application_responder"
121
123
 
122
124
  class ApplicationController < ActionController::Base
123
125
  self.responder = AppResponder
@@ -125,12 +127,6 @@ class ApplicationController < ActionController::Base
125
127
  end
126
128
  ```
127
129
 
128
- Or, for your convenience, just do:
129
-
130
- ```console
131
- rails generate responders:install
132
- ```
133
-
134
130
  ## Controller method
135
131
 
136
132
  This gem also includes the controller method `responders`, which allows you to cherry-pick which
@@ -168,14 +164,14 @@ Now you would see the message "bob@bob.com was successfully created" instead of
168
164
  ## Generator
169
165
 
170
166
  This gem also includes a responders controller generator, so your scaffold can be customized
171
- to use `respond_with` instead of default `respond_to` blocks. Installing this gem automatically
172
- sets the generator.
167
+ 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`:
168
+
169
+ config.app_generators.scaffold_controller :responders_controller
173
170
 
174
171
  ## Examples
175
172
 
176
173
  Want more examples ? Check out this blog posts:
177
174
 
178
- * [One in Three: Inherited Resources, Has Scope and Responders](http://blog.plataformatec.com.br/2009/12/one-in-three-inherited-resources-has-scope-and-responders/)
179
175
  * [Embracing REST with mind, body and soul](http://blog.plataformatec.com.br/2009/08/embracing-rest-with-mind-body-and-soul/)
180
176
  * [Three reasons to love ActionController::Responder](http://weblog.rubyonrails.org/2009/8/31/three-reasons-love-responder/)
181
177
  * [My five favorite things about Rails 3](http://www.engineyard.com/blog/2009/my-five-favorite-things-about-rails-3/)
@@ -194,7 +194,7 @@ module ActionController #:nodoc:
194
194
  mimes = collect_mimes_from_class_level()
195
195
  collector = ActionController::MimeResponds::Collector.new(mimes, request.variant)
196
196
  block.call(collector) if block_given?
197
-
197
+
198
198
  if format = collector.negotiate_format(request)
199
199
  _process_format(format)
200
200
  options = resources.size == 1 ? {} : resources.extract_options!
@@ -226,4 +226,4 @@ module ActionController #:nodoc:
226
226
  end
227
227
  end
228
228
  end
229
- end
229
+ end
@@ -15,32 +15,8 @@ module Rails
15
15
  end
16
16
  end
17
17
 
18
- def orm_instance_update(params)
19
- if orm_instance.respond_to?(:update)
20
- orm_instance.update params
21
- else
22
- orm_instance.update_attributes params
23
- end
24
- end
25
-
26
- def controller_before_filter
27
- if ActionController::Base.respond_to?(:before_action)
28
- "before_action"
29
- else
30
- "before_filter"
31
- end
32
- end
33
-
34
18
  def attributes_params
35
- if strong_parameters_defined?
36
- "#{file_name}_params"
37
- else
38
- "params[:#{file_name}]"
39
- end
40
- end
41
-
42
- def strong_parameters_defined?
43
- defined?(ActionController::StrongParameters)
19
+ "#{singular_table_name}_params"
44
20
  end
45
21
  end
46
22
  end
@@ -1,6 +1,10 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
1
5
  <% module_namespacing do -%>
2
6
  class <%= controller_class_name %>Controller < ApplicationController
3
- <%= controller_before_filter %> :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
4
8
 
5
9
  respond_to :html
6
10
 
@@ -30,7 +34,7 @@ class <%= controller_class_name %>Controller < ApplicationController
30
34
  end
31
35
 
32
36
  def update
33
- <%= "flash[:notice] = '#{class_name} was successfully updated.' if " if flash? %>@<%= orm_instance_update(attributes_params) %>
37
+ <%= "flash[:notice] = '#{class_name} was successfully updated.' if " if flash? %>@<%= orm_instance.update(attributes_params) %>
34
38
  respond_with(@<%= singular_table_name %>)
35
39
  end
36
40
 
@@ -43,7 +47,6 @@ class <%= controller_class_name %>Controller < ApplicationController
43
47
  def set_<%= singular_table_name %>
44
48
  @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
45
49
  end
46
- <%- if strong_parameters_defined? -%>
47
50
 
48
51
  def <%= "#{singular_table_name}_params" %>
49
52
  <%- if attributes_names.empty? -%>
@@ -52,6 +55,5 @@ class <%= controller_class_name %>Controller < ApplicationController
52
55
  params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
53
56
  <%- end -%>
54
57
  end
55
- <%- end -%>
56
58
  end
57
59
  <% end -%>
@@ -18,6 +18,14 @@ end
18
18
  RUBY
19
19
  end
20
20
 
21
+ def update_application
22
+ inject_into_class "config/application.rb", "Application", <<-RUBY
23
+ # Use the responders controller from the responders gem
24
+ config.app_generators.scaffold_controller :responders_controller
25
+
26
+ RUBY
27
+ end
28
+
21
29
  def update_application_controller
22
30
  prepend_file "app/controllers/application_controller.rb", %{require "application_responder"\n\n}
23
31
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController", <<-RUBY
@@ -19,12 +19,6 @@ module Responders
19
19
  config.responders.flash_keys = [:notice, :alert]
20
20
  config.responders.namespace_lookup = false
21
21
 
22
- if config.respond_to?(:app_generators)
23
- config.app_generators.scaffold_controller = :responders_controller
24
- else
25
- config.generators.scaffold_controller = :responders_controller
26
- end
27
-
28
22
  # Add load paths straight to I18n, so engines and application can overwrite it.
29
23
  require 'active_support/i18n'
30
24
  I18n.load_path << File.expand_path('../responders/locales/en.yml', __FILE__)
@@ -1,7 +1,7 @@
1
1
  module Responders
2
2
  module LocationResponder
3
3
  def self.included(_base)
4
- ActiveSupport::Deprecation.warn "Responders::LocationResponder is enabled by default, "
4
+ ActiveSupport::Deprecation.warn "Responders::LocationResponder is enabled by default, " \
5
5
  "no need to include it", caller
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Responders
2
- VERSION = "2.0.2".freeze
2
+ VERSION = "2.1.0".freeze
3
3
  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.0.2
4
+ version: 2.1.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: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0.alpha
19
+ version: 4.2.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: 4.2.0.alpha
29
+ version: 4.2.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5'