active_decorator 1.1.0 → 1.1.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/.travis.yml +12 -0
- data/CHANGELOG.md +7 -0
- data/README.md +3 -3
- data/Rakefile +5 -1
- data/lib/active_decorator/helpers.rb +14 -10
- data/lib/active_decorator/railtie.rb +8 -8
- data/lib/active_decorator/version.rb +1 -1
- data/test/fake_app/app/views/api/bookstores/show.json.jbuilder +0 -1
- data/test/fake_app/app/views/authors/show.json.jbuilder +0 -1
- data/test/fake_app/app/views/books/_book.json.jbuilder +0 -1
- data/test/fake_app/fake_app.rb +59 -58
- data/test/fake_app/public/images/cover.png +0 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d46d933899535231f0e24953747370ac289afed99ac881dd91a1bafca06d00
|
4
|
+
data.tar.gz: '08989f206e82987244927a07c17f147f59f25c268bb61b59763dbed7cf11aa06'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e89c4cc6d373b308858919ebf119c18bc3547e09d0f0dda9d1c52643a844eb50696aac9f5e0372f7c274acbe5d3f34db5b66ad02db62cd3a0808f7c3b566436b
|
7
|
+
data.tar.gz: d62771d0c66da65522e8a3b05ba03a5bce188da0c6bad782bac5d8b7d53827ca5471fbd756e7533b7b4701b4539f0a038098c0be37dac514b688c32821b1cd93
|
data/.travis.yml
CHANGED
@@ -78,5 +78,17 @@ matrix:
|
|
78
78
|
include:
|
79
79
|
- rvm: ruby-head
|
80
80
|
gemfile: gemfiles/Gemfile-rails.edge
|
81
|
+
- rvm: 2.5.3
|
82
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
83
|
+
env: API=1
|
84
|
+
- rvm: 2.5.3
|
85
|
+
gemfile: gemfiles/Gemfile-rails.5.1.x
|
86
|
+
env: API=1
|
87
|
+
- rvm: 2.5.3
|
88
|
+
gemfile: gemfiles/Gemfile-rails.5.0.x
|
89
|
+
env: API=1
|
90
|
+
- rvm: ruby-head
|
91
|
+
gemfile: gemfiles/Gemfile-rails.edge
|
92
|
+
env: API=1
|
81
93
|
allow_failures:
|
82
94
|
- rvm: ruby-head
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 1.1.1
|
2
|
+
|
3
|
+
* Improved ActionController::API support for Rails 5.0.x [@frodsan]
|
4
|
+
|
5
|
+
* Fixed "NameError: undefined local variable or method `view_context'" with ActionController::API or when rendering in controllers
|
6
|
+
|
7
|
+
|
1
8
|
## 1.1.0
|
2
9
|
|
3
10
|
* ActionController::API support [@frodsan]
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveDecorator [](https://travis-ci.org/amatsuda/active_decorator) [](https://codeclimate.com/github/amatsuda/active_decorator)
|
2
2
|
|
3
|
-
A simple and Rubyish view helper for Rails 3, Rails 4 and Rails
|
3
|
+
A simple and Rubyish view helper for Rails 3, Rails 4, Rails 5, and Rails 6. Keep your helpers and views Object-Oriented!
|
4
4
|
|
5
5
|
|
6
6
|
## Features ##
|
@@ -15,9 +15,9 @@ A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your hel
|
|
15
15
|
|
16
16
|
## Supported versions ##
|
17
17
|
|
18
|
-
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, and 2.5 (trunk)
|
18
|
+
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, and 2.5, and 2.6 (trunk)
|
19
19
|
|
20
|
-
* Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, 5.1,
|
20
|
+
* Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, 5.1, 5.2, and 6.0 (edge)
|
21
21
|
|
22
22
|
|
23
23
|
## Supported ORMs ##
|
data/Rakefile
CHANGED
@@ -8,7 +8,11 @@ require 'rake/testtask'
|
|
8
8
|
|
9
9
|
Rake::TestTask.new do |t|
|
10
10
|
t.libs << "test"
|
11
|
-
|
11
|
+
if ENV['API']
|
12
|
+
t.pattern = 'test/**/*_api_test.rb'
|
13
|
+
else
|
14
|
+
t.test_files = Dir['test/**/*_test.rb'] - Dir['test/**/*_api_test.rb']
|
15
|
+
end
|
12
16
|
t.warning = true
|
13
17
|
t.verbose = true
|
14
18
|
end
|
@@ -5,20 +5,24 @@ module ActiveDecorator
|
|
5
5
|
module Helpers
|
6
6
|
def method_missing(method, *args, &block)
|
7
7
|
super
|
8
|
-
rescue NoMethodError, NameError =>
|
8
|
+
rescue NoMethodError, NameError => e1
|
9
9
|
# the error is not mine, so just releases it as is.
|
10
|
-
raise
|
10
|
+
raise e1 if e1.name != method
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
if (view_context = ActiveDecorator::ViewContext.current)
|
13
|
+
begin
|
14
|
+
view_context.send method, *args, &block
|
15
|
+
rescue NoMethodError => e2
|
16
|
+
raise e2 if e2.name != method
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
raise NoMethodError.new("undefined method `#{method}' for either #{self} or #{view_context}", method)
|
19
|
+
rescue NameError => e2
|
20
|
+
raise e2 if e2.name != method
|
20
21
|
|
21
|
-
|
22
|
+
raise NameError.new("undefined local variable `#{method}' for either #{self} or #{view_context}", method)
|
23
|
+
end
|
24
|
+
else # AC::API would have not view_context
|
25
|
+
raise e1
|
22
26
|
end
|
23
27
|
end
|
24
28
|
end
|
@@ -22,14 +22,14 @@ module ActiveDecorator
|
|
22
22
|
end
|
23
23
|
|
24
24
|
if Rails::VERSION::MAJOR >= 5
|
25
|
-
ActiveSupport.on_load :
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
25
|
+
ActiveSupport.on_load :action_controller do
|
26
|
+
if self == ActionController::API
|
27
|
+
require 'active_decorator/monkey/abstract_controller/rendering'
|
28
|
+
::ActionController::API.send :prepend, ActiveDecorator::Monkey::AbstractController::Rendering
|
29
|
+
|
30
|
+
require 'active_decorator/monkey/action_controller/base/rescue_from'
|
31
|
+
::ActionController::API.send :prepend, ActiveDecorator::Monkey::ActionController::Base
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/test/fake_app/fake_app.rb
CHANGED
@@ -167,79 +167,80 @@ end
|
|
167
167
|
class MovieDecorator; end
|
168
168
|
|
169
169
|
# controllers
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
# ActiveRecord 4.x
|
186
|
-
if params[:variable_type] == 'array'
|
187
|
-
@authors = Author.all.to_a
|
188
|
-
elsif params[:variable_type] == 'proxy'
|
189
|
-
@authors = RelationProxy.new(Author.all)
|
170
|
+
unless ENV['API']
|
171
|
+
class ApplicationController < ActionController::Base
|
172
|
+
self.append_view_path File.dirname(__FILE__)
|
173
|
+
end
|
174
|
+
class AuthorsController < ApplicationController
|
175
|
+
def index
|
176
|
+
if Author.respond_to?(:scoped)
|
177
|
+
# ActiveRecord 3.x
|
178
|
+
if params[:variable_type] == 'array'
|
179
|
+
@authors = Author.all
|
180
|
+
elsif params[:variable_type] == 'proxy'
|
181
|
+
@authors = RelationProxy.new(Author.scoped)
|
182
|
+
else
|
183
|
+
@authors = Author.scoped
|
184
|
+
end
|
190
185
|
else
|
191
|
-
|
186
|
+
# ActiveRecord 4.x
|
187
|
+
if params[:variable_type] == 'array'
|
188
|
+
@authors = Author.all.to_a
|
189
|
+
elsif params[:variable_type] == 'proxy'
|
190
|
+
@authors = RelationProxy.new(Author.all)
|
191
|
+
else
|
192
|
+
@authors = Author.all
|
193
|
+
end
|
192
194
|
end
|
193
195
|
end
|
194
|
-
end
|
195
196
|
|
196
|
-
|
197
|
-
|
197
|
+
def show
|
198
|
+
@author = Author.find params[:id]
|
199
|
+
end
|
198
200
|
end
|
199
|
-
|
200
|
-
class
|
201
|
-
class CustomError < StandardError; end
|
201
|
+
class BooksController < ApplicationController
|
202
|
+
class CustomError < StandardError; end
|
202
203
|
|
203
|
-
|
204
|
-
|
205
|
-
|
204
|
+
rescue_from CustomError do
|
205
|
+
render :error
|
206
|
+
end
|
206
207
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
208
|
+
def index
|
209
|
+
@author = Author.find params[:author_id]
|
210
|
+
@books = @author.books
|
211
|
+
end
|
211
212
|
|
212
|
-
|
213
|
-
|
214
|
-
|
213
|
+
def show
|
214
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
215
|
+
end
|
215
216
|
|
216
|
-
|
217
|
-
|
218
|
-
|
217
|
+
def errata
|
218
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
219
|
+
end
|
219
220
|
|
220
|
-
|
221
|
-
|
222
|
-
|
221
|
+
def errata2
|
222
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
223
|
+
end
|
223
224
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
225
|
+
def error
|
226
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
227
|
+
raise CustomError, "error"
|
228
|
+
end
|
228
229
|
|
229
|
-
|
230
|
-
|
230
|
+
def purchase
|
231
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
231
232
|
|
232
|
-
|
233
|
-
|
234
|
-
|
233
|
+
@view_context_before_sending_mail = ActiveDecorator::ViewContext.current
|
234
|
+
BookMailer.thanks(@book).deliver
|
235
|
+
raise 'Wrong ViewContext!' if ActiveDecorator::ViewContext.current != @view_context_before_sending_mail
|
236
|
+
end
|
235
237
|
end
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
238
|
+
class MoviesController < ApplicationController
|
239
|
+
def show
|
240
|
+
@movie = Movie.find params[:id]
|
241
|
+
end
|
240
242
|
end
|
241
|
-
|
242
|
-
if Rails::VERSION::MAJOR >= 5
|
243
|
+
else
|
243
244
|
module Api
|
244
245
|
class BookstoresController < ActionController::API
|
245
246
|
def show
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: test-unit-rails
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- test/fake_app/app/views/books/show.html.erb
|
170
170
|
- test/fake_app/app/views/movies/show.html.erb
|
171
171
|
- test/fake_app/fake_app.rb
|
172
|
+
- test/fake_app/public/images/cover.png
|
172
173
|
- test/features/action_controller_api_test.rb
|
173
174
|
- test/features/action_view_helpers_test.rb
|
174
175
|
- test/features/association_test.rb
|
@@ -221,6 +222,7 @@ test_files:
|
|
221
222
|
- test/fake_app/app/views/books/show.html.erb
|
222
223
|
- test/fake_app/app/views/movies/show.html.erb
|
223
224
|
- test/fake_app/fake_app.rb
|
225
|
+
- test/fake_app/public/images/cover.png
|
224
226
|
- test/features/action_controller_api_test.rb
|
225
227
|
- test/features/action_view_helpers_test.rb
|
226
228
|
- test/features/association_test.rb
|