active_decorator 0.7.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +9 -5
- data/Gemfile +4 -2
- data/README.md +2 -2
- data/Rakefile +1 -0
- data/active_decorator.gemspec +1 -0
- data/gemfiles/Gemfile-rails.3.2.x +1 -10
- data/gemfiles/{Gemfile-rails.5.0.0.rc1 → Gemfile-rails.5.0.x} +1 -1
- data/lib/active_decorator.rb +1 -0
- data/lib/active_decorator/config.rb +1 -0
- data/lib/active_decorator/decorator.rb +5 -4
- data/lib/active_decorator/helpers.rb +7 -5
- data/lib/active_decorator/monkey/abstract_controller/rendering.rb +2 -1
- data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +1 -0
- data/lib/active_decorator/monkey/action_view/partial_renderer.rb +3 -2
- data/lib/active_decorator/railtie.rb +1 -0
- data/lib/active_decorator/version.rb +2 -1
- data/lib/active_decorator/view_context.rb +1 -0
- data/lib/generators/rails/decorator_generator.rb +1 -0
- data/lib/generators/rspec/decorator_generator.rb +1 -0
- data/lib/generators/test_unit/decorator_generator.rb +1 -0
- data/test/configuration_test.rb +1 -0
- data/test/controllers/fake_detection_test.rb +1 -0
- data/test/fake_app/app/views/authors/show.json.jbuilder +1 -0
- data/test/fake_app/app/views/books/_book.json.jbuilder +1 -0
- data/test/fake_app/app/views/books/errata.html.erb +1 -0
- data/test/fake_app/fake_app.rb +11 -1
- data/test/features/action_view_helpers_test.rb +1 -0
- data/test/features/controller_ivar_test.rb +1 -0
- data/test/features/jbuilder_test.rb +1 -0
- data/test/features/name_error_handling_test.rb +17 -0
- data/test/features/partial_test.rb +1 -0
- data/test/test_helper.rb +1 -0
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14f002118bfbc2127bf674fc7488990d80a5152c
|
4
|
+
data.tar.gz: 6e40b90bb6ffc7ba584147a93041025456216f52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd8f1c1bdc0cfe4734755e9a56fd1d20cbea6205319ac20c308360b95b5c74303d3f16cda0002458c2b33795ad6690e2eb8401ed99d35db4c3068f5630e6936
|
7
|
+
data.tar.gz: cf5c094dedd2637ea7f23bdd3b0f131b2a33f0cc98e9ff2148433960e8305c2b1732d7cf6005bd82247d9cc8b8a71897c61e5bcd5f9d044a641d970f53c7fa58
|
data/.travis.yml
CHANGED
@@ -5,15 +5,15 @@ script: bundle exec rake test
|
|
5
5
|
rvm:
|
6
6
|
- 2.0.0
|
7
7
|
- 2.1.10
|
8
|
-
- 2.2.
|
9
|
-
- 2.3.
|
8
|
+
- 2.2.6
|
9
|
+
- 2.3.3
|
10
10
|
- ruby-head
|
11
11
|
gemfile:
|
12
12
|
- gemfiles/Gemfile-rails.3.2.x
|
13
13
|
- gemfiles/Gemfile-rails.4.0.x
|
14
14
|
- gemfiles/Gemfile-rails.4.1.x
|
15
15
|
- gemfiles/Gemfile-rails.4.2.x
|
16
|
-
- gemfiles/Gemfile-rails.5.0.
|
16
|
+
- gemfiles/Gemfile-rails.5.0.x
|
17
17
|
|
18
18
|
sudo: false
|
19
19
|
|
@@ -21,9 +21,13 @@ matrix:
|
|
21
21
|
exclude:
|
22
22
|
- rvm: ruby-head
|
23
23
|
gemfile: gemfiles/Gemfile-rails.3.2.x
|
24
|
+
- rvm: ruby-head
|
25
|
+
gemfile: gemfiles/Gemfile-rails.4.0.x
|
26
|
+
- rvm: ruby-head
|
27
|
+
gemfile: gemfiles/Gemfile-rails.4.1.x
|
24
28
|
- rvm: 2.0.0
|
25
|
-
gemfile: gemfiles/Gemfile-rails.5.0.
|
29
|
+
gemfile: gemfiles/Gemfile-rails.5.0.x
|
26
30
|
- rvm: 2.1.10
|
27
|
-
gemfile: gemfiles/Gemfile-rails.5.0.
|
31
|
+
gemfile: gemfiles/Gemfile-rails.5.0.x
|
28
32
|
allow_failures:
|
29
33
|
- rvm: ruby-head
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# ActiveDecorator [![Build Status](https://travis-ci.org/amatsuda/active_decorator.svg?branch=master)](https://travis-ci.org/amatsuda/active_decorator) [![Code Climate](https://codeclimate.com/github/amatsuda/active_decorator/badges/gpa.svg)](https://codeclimate.com/github/amatsuda/active_decorator)
|
2
2
|
|
3
|
-
A simple and Rubyish view helper for Rails 3 and Rails
|
3
|
+
A simple and Rubyish view helper for Rails 3, Rails 4 and Rails 5. Keep your helpers and views Object-Oriented!
|
4
4
|
|
5
5
|
|
6
6
|
## Features ##
|
@@ -16,7 +16,7 @@ A simple and Rubyish view helper for Rails 3 and Rails 4. Keep your helpers and
|
|
16
16
|
|
17
17
|
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, and 2.4 (trunk)
|
18
18
|
|
19
|
-
* Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, and 5.
|
19
|
+
* Rails 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, and 5.1 (edge)
|
20
20
|
|
21
21
|
|
22
22
|
## Supported ORMs ##
|
data/Rakefile
CHANGED
data/active_decorator.gemspec
CHANGED
@@ -4,17 +4,8 @@ gem 'active_decorator', path: '..'
|
|
4
4
|
|
5
5
|
gem 'rails', '~> 3.2.0'
|
6
6
|
gem 'test-unit-rails', '1.0.2'
|
7
|
-
if RUBY_VERSION <= '1.8.7'
|
8
|
-
gem 'i18n', '~> 0.6.11'
|
9
|
-
end
|
10
7
|
gem 'capybara', '~> 2.0.0'
|
11
|
-
# rubyzip >=1 doesn't support ruby 1.8
|
12
|
-
gem 'rubyzip', '< 1.0.0'
|
13
8
|
gem 'sqlite3'
|
14
9
|
gem 'nokogiri', '~> 1.5.0'
|
15
|
-
|
16
|
-
gem 'jbuilder', '< 2'
|
17
|
-
else
|
18
|
-
gem 'jbuilder'
|
19
|
-
end
|
10
|
+
gem 'jbuilder'
|
20
11
|
gem 'test-unit'
|
data/lib/active_decorator.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'singleton'
|
2
3
|
require 'active_decorator/helpers'
|
3
4
|
|
@@ -17,14 +18,14 @@ module ActiveDecorator
|
|
17
18
|
obj.each do |r|
|
18
19
|
decorate r
|
19
20
|
end
|
20
|
-
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
|
21
|
+
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
|
21
22
|
# don't call each nor to_a immediately
|
22
23
|
if obj.respond_to?(:records)
|
23
24
|
# Rails 5.0
|
24
|
-
obj.extend ActiveDecorator::RelationDecorator
|
25
|
+
obj.extend ActiveDecorator::RelationDecorator unless obj.is_a? ActiveDecorator::RelationDecorator
|
25
26
|
else
|
26
27
|
# Rails 3.x and 4.x
|
27
|
-
obj.extend ActiveDecorator::RelationDecoratorLegacy
|
28
|
+
obj.extend ActiveDecorator::RelationDecoratorLegacy unless obj.is_a? ActiveDecorator::RelationDecoratorLegacy
|
28
29
|
end
|
29
30
|
else
|
30
31
|
d = decorator_for obj.class
|
@@ -35,7 +36,7 @@ module ActiveDecorator
|
|
35
36
|
|
36
37
|
private
|
37
38
|
def decorator_for(model_class)
|
38
|
-
return @@decorators[model_class] if @@decorators.
|
39
|
+
return @@decorators[model_class] if @@decorators.key? model_class
|
39
40
|
|
40
41
|
decorator_name = "#{model_class.name}#{ActiveDecorator.config.decorator_suffix}"
|
41
42
|
d = decorator_name.constantize
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveDecorator
|
2
3
|
module Helpers
|
3
4
|
def method_missing(method, *args, &block)
|
4
5
|
super
|
5
|
-
|
6
|
-
rescue NoMethodError, NameError => original_error
|
6
|
+
rescue NoMethodError, NameError
|
7
7
|
begin
|
8
|
-
ActiveDecorator::ViewContext.current.send method, *args, &block
|
9
|
-
rescue NoMethodError
|
10
|
-
raise
|
8
|
+
(view_context = ActiveDecorator::ViewContext.current).send method, *args, &block
|
9
|
+
rescue NoMethodError
|
10
|
+
raise NoMethodError, "undefined method `#{method}` for either #{self} or #{view_context}"
|
11
|
+
rescue NameError
|
12
|
+
raise NameError, "undefined local variable `#{method}` for either #{self} or #{view_context}"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveDecorator
|
2
3
|
module Monkey
|
3
4
|
module AbstractController
|
4
5
|
module Rendering
|
5
6
|
def view_assigns
|
6
7
|
hash = super
|
7
|
-
hash.
|
8
|
+
hash.each_value do |v|
|
8
9
|
ActiveDecorator::Decorator.instance.decorate v
|
9
10
|
end
|
10
11
|
hash
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ActiveDecorator
|
2
3
|
module Monkey
|
3
4
|
module ActionView
|
@@ -9,8 +10,8 @@ module ActiveDecorator
|
|
9
10
|
|
10
11
|
@locals.values.each do |v|
|
11
12
|
ActiveDecorator::Decorator.instance.decorate v
|
12
|
-
end
|
13
|
-
ActiveDecorator::Decorator.instance.decorate @object
|
13
|
+
end if @locals
|
14
|
+
ActiveDecorator::Decorator.instance.decorate @object if @object && (@object != nil)
|
14
15
|
ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
|
15
16
|
|
16
17
|
self
|
data/test/configuration_test.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
<%= @book.errata %>
|
data/test/fake_app/fake_app.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'active_record'
|
2
3
|
require 'action_controller/railtie'
|
3
4
|
require 'action_mailer/railtie'
|
@@ -27,6 +28,7 @@ ActiveDecoratorTestApp::Application.routes.draw do
|
|
27
28
|
resources :authors, only: [:index, :show] do
|
28
29
|
resources :books, only: [:index, :show] do
|
29
30
|
member do
|
31
|
+
get :errata
|
30
32
|
get :error
|
31
33
|
post :purchase
|
32
34
|
end
|
@@ -83,6 +85,10 @@ module BookDecorator
|
|
83
85
|
image_tag 'cover.png'
|
84
86
|
end
|
85
87
|
|
88
|
+
def errata
|
89
|
+
poof!
|
90
|
+
end
|
91
|
+
|
86
92
|
def error
|
87
93
|
"ERROR"
|
88
94
|
end
|
@@ -126,7 +132,7 @@ class BooksController < ApplicationController
|
|
126
132
|
class CustomError < StandardError; end
|
127
133
|
|
128
134
|
rescue_from CustomError do
|
129
|
-
render
|
135
|
+
render :error
|
130
136
|
end
|
131
137
|
|
132
138
|
def index
|
@@ -138,6 +144,10 @@ class BooksController < ApplicationController
|
|
138
144
|
@book = Author.find(params[:author_id]).books.find(params[:id])
|
139
145
|
end
|
140
146
|
|
147
|
+
def errata
|
148
|
+
@book = Author.find(params[:author_id]).books.find(params[:id])
|
149
|
+
end
|
150
|
+
|
141
151
|
def error
|
142
152
|
@book = Author.find(params[:author_id]).books.find(params[:id])
|
143
153
|
raise CustomError, "error"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class NameErrorHandlingTest < ActionDispatch::IntegrationTest
|
5
|
+
setup do
|
6
|
+
aamine = Author.create! name: 'aamine'
|
7
|
+
@rhg = aamine.books.create! title: 'RHG'
|
8
|
+
end
|
9
|
+
|
10
|
+
test 'raising NameError in a decorator' do
|
11
|
+
err = assert_raises ActionView::Template::Error do
|
12
|
+
visit "/authors/#{@rhg.author.id}/books/#{@rhg.id}/errata"
|
13
|
+
end
|
14
|
+
|
15
|
+
assert_match(/undefined method `poof!` for/, err.message)
|
16
|
+
end
|
17
|
+
end
|
data/test/test_helper.rb
CHANGED
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: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and Rubyish view helper for Rails
|
14
14
|
email:
|
@@ -28,7 +28,7 @@ files:
|
|
28
28
|
- gemfiles/Gemfile-rails.4.0.x
|
29
29
|
- gemfiles/Gemfile-rails.4.1.x
|
30
30
|
- gemfiles/Gemfile-rails.4.2.x
|
31
|
-
- gemfiles/Gemfile-rails.5.0.
|
31
|
+
- gemfiles/Gemfile-rails.5.0.x
|
32
32
|
- lib/active_decorator.rb
|
33
33
|
- lib/active_decorator/config.rb
|
34
34
|
- lib/active_decorator/decorator.rb
|
@@ -54,6 +54,7 @@ files:
|
|
54
54
|
- test/fake_app/app/views/books/_book.html.erb
|
55
55
|
- test/fake_app/app/views/books/_book.json.jbuilder
|
56
56
|
- test/fake_app/app/views/books/_book_locals.html.erb
|
57
|
+
- test/fake_app/app/views/books/errata.html.erb
|
57
58
|
- test/fake_app/app/views/books/error.html.erb
|
58
59
|
- test/fake_app/app/views/books/index.html.erb
|
59
60
|
- test/fake_app/app/views/books/purchase.html.erb
|
@@ -63,6 +64,7 @@ files:
|
|
63
64
|
- test/features/action_view_helpers_test.rb
|
64
65
|
- test/features/controller_ivar_test.rb
|
65
66
|
- test/features/jbuilder_test.rb
|
67
|
+
- test/features/name_error_handling_test.rb
|
66
68
|
- test/features/partial_test.rb
|
67
69
|
- test/test_helper.rb
|
68
70
|
homepage: https://github.com/amatsuda/active_decorator
|
@@ -84,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
86
|
version: '0'
|
85
87
|
requirements: []
|
86
88
|
rubyforge_project:
|
87
|
-
rubygems_version: 2.6.
|
89
|
+
rubygems_version: 2.6.8
|
88
90
|
signing_key:
|
89
91
|
specification_version: 4
|
90
92
|
summary: A simple and Rubyish view helper for Rails
|
@@ -98,6 +100,7 @@ test_files:
|
|
98
100
|
- test/fake_app/app/views/books/_book.html.erb
|
99
101
|
- test/fake_app/app/views/books/_book.json.jbuilder
|
100
102
|
- test/fake_app/app/views/books/_book_locals.html.erb
|
103
|
+
- test/fake_app/app/views/books/errata.html.erb
|
101
104
|
- test/fake_app/app/views/books/error.html.erb
|
102
105
|
- test/fake_app/app/views/books/index.html.erb
|
103
106
|
- test/fake_app/app/views/books/purchase.html.erb
|
@@ -107,6 +110,6 @@ test_files:
|
|
107
110
|
- test/features/action_view_helpers_test.rb
|
108
111
|
- test/features/controller_ivar_test.rb
|
109
112
|
- test/features/jbuilder_test.rb
|
113
|
+
- test/features/name_error_handling_test.rb
|
110
114
|
- test/features/partial_test.rb
|
111
115
|
- test/test_helper.rb
|
112
|
-
has_rdoc:
|