active_decorator 1.2.0 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +34 -27
- data/CHANGELOG.md +32 -0
- data/README.md +3 -3
- data/active_decorator.gemspec +7 -5
- data/gemfiles/Gemfile-rails.4.2.x +2 -0
- data/gemfiles/Gemfile-rails.5.0.x +2 -0
- data/gemfiles/Gemfile-rails.5.1.x +1 -0
- data/gemfiles/Gemfile-rails.5.2.x +3 -1
- data/gemfiles/Gemfile-rails.6.0.x +7 -0
- data/gemfiles/Gemfile-rails.6.1.x +7 -0
- data/gemfiles/Gemfile-rails.edge +6 -0
- data/lib/active_decorator.rb +5 -1
- data/lib/active_decorator/config.rb +7 -1
- data/lib/active_decorator/decorator.rb +3 -7
- data/lib/active_decorator/helpers.rb +1 -0
- data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +2 -2
- data/lib/active_decorator/monkey/action_view/collection_renderer.rb +12 -0
- data/lib/active_decorator/monkey/action_view/object_renderer.rb +12 -0
- data/lib/active_decorator/monkey/action_view/partial_renderer.rb +20 -8
- data/lib/active_decorator/monkey/active_record/associations.rb +28 -24
- data/lib/active_decorator/railtie.rb +16 -6
- data/lib/active_decorator/version.rb +1 -1
- data/lib/active_decorator/view_context.rb +3 -11
- data/lib/generators/rails/templates/decorator.rb +2 -0
- data/lib/generators/rspec/templates/decorator_spec.rb +2 -0
- data/lib/generators/test_unit/templates/decorator_test.rb +2 -0
- metadata +30 -71
- data/gemfiles/Gemfile-rails.3.2.x +0 -8
- data/gemfiles/Gemfile-rails.4.0.x +0 -6
- data/gemfiles/Gemfile-rails.4.1.x +0 -6
- data/test/configuration_test.rb +0 -28
- data/test/controllers/fake_detection_test.rb +0 -14
- data/test/decorator_test.rb +0 -51
- data/test/fake_app/app/views/api/bookstores/show.json.jbuilder +0 -1
- data/test/fake_app/app/views/authors/index.html.erb +0 -16
- data/test/fake_app/app/views/authors/show.html.erb +0 -10
- data/test/fake_app/app/views/authors/show.json.jbuilder +0 -2
- data/test/fake_app/app/views/book_mailer/thanks.text.erb +0 -1
- data/test/fake_app/app/views/books/_book.html.erb +0 -2
- data/test/fake_app/app/views/books/_book.json.jbuilder +0 -2
- data/test/fake_app/app/views/books/_book_locals.html.erb +0 -2
- data/test/fake_app/app/views/books/errata.html.erb +0 -1
- data/test/fake_app/app/views/books/errata2.html.erb +0 -1
- data/test/fake_app/app/views/books/error.html.erb +0 -1
- data/test/fake_app/app/views/books/index.html.erb +0 -4
- data/test/fake_app/app/views/books/purchase.html.erb +0 -1
- data/test/fake_app/app/views/books/show.html.erb +0 -4
- data/test/fake_app/app/views/movies/show.html.erb +0 -2
- data/test/fake_app/fake_app.rb +0 -288
- data/test/fake_app/public/images/cover.png +0 -0
- data/test/features/action_controller_api_test.rb +0 -19
- data/test/features/action_view_helpers_test.rb +0 -38
- data/test/features/association_test.rb +0 -43
- data/test/features/controller_ivar_test.rb +0 -41
- data/test/features/jbuilder_test.rb +0 -16
- data/test/features/name_error_handling_test.rb +0 -29
- data/test/features/partial_test.rb +0 -29
- data/test/test_helper.rb +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abd22d415613228c6c98fe9a0bf7255496dabaada709c34ba2cbe032a2fcc9b6
|
4
|
+
data.tar.gz: af38045be9a3de1832be692fa8f349010e7f79c7144d8d1f9f248aa3c311abb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f6198f7583dbc4df7bb3071161f234ce858cda7d17a27c07caab910bc3a1c652468cd42dfd7bf094cb53ceedc9da8c9a35d031a0e258398dc41f15b44d2925
|
7
|
+
data.tar.gz: 3b342f062765a460b03b3adbe2562cf01579a4b54427713dd3abe88694e371acee44ded648a218e9a2fd2872285635a08016cf11a0b68ecae0631243c6909c2f
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,22 +1,19 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
sudo: false
|
4
|
-
|
5
|
-
script: bundle exec rake test
|
6
|
-
|
7
3
|
addons:
|
8
4
|
chrome: stable
|
9
5
|
|
10
6
|
before_install:
|
11
7
|
- sudo apt update -qq
|
12
8
|
- sudo apt install -y chromium-chromedriver
|
13
|
-
- sudo ln -s /usr/lib/chromium-browser/chromedriver /usr/bin/
|
14
9
|
- gem i bundler -v '<2'
|
15
10
|
|
11
|
+
cache: bundler
|
12
|
+
|
16
13
|
# rvm:
|
17
|
-
# - 2.6.
|
18
|
-
# - 2.5.
|
19
|
-
# - 2.4.
|
14
|
+
# - 2.6.6
|
15
|
+
# - 2.5.8
|
16
|
+
# - 2.4.6
|
20
17
|
# - 2.3.8
|
21
18
|
# - 2.2.10
|
22
19
|
# - 2.1.10
|
@@ -26,42 +23,56 @@ before_install:
|
|
26
23
|
# - gemfiles/Gemfile-rails.5.1.x
|
27
24
|
# - gemfiles/Gemfile-rails.5.0.x
|
28
25
|
# - gemfiles/Gemfile-rails.4.2.x
|
29
|
-
# - gemfiles/Gemfile-rails.4.1.x
|
30
|
-
# - gemfiles/Gemfile-rails.4.0.x
|
31
|
-
# - gemfiles/Gemfile-rails.3.2.x
|
32
26
|
|
33
27
|
matrix:
|
34
28
|
include:
|
35
|
-
- rvm: 2.
|
29
|
+
- rvm: 2.7.1
|
30
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
31
|
+
- rvm: 2.7.1
|
32
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
33
|
+
env: API=1
|
34
|
+
- rvm: 2.7.1
|
35
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
36
|
+
- rvm: 2.7.1
|
37
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
38
|
+
env: API=1
|
39
|
+
|
40
|
+
- rvm: 2.6.6
|
41
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
42
|
+
- rvm: 2.6.6
|
43
|
+
gemfile: gemfiles/Gemfile-rails.6.1.x
|
44
|
+
env: API=1
|
45
|
+
- rvm: 2.6.6
|
46
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
47
|
+
- rvm: 2.6.6
|
48
|
+
gemfile: gemfiles/Gemfile-rails.6.0.x
|
49
|
+
env: API=1
|
50
|
+
- rvm: 2.6.6
|
36
51
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
37
|
-
- rvm: 2.6.
|
52
|
+
- rvm: 2.6.6
|
38
53
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
39
54
|
env: API=1
|
40
|
-
- rvm: 2.6.
|
55
|
+
- rvm: 2.6.6
|
41
56
|
gemfile: gemfiles/Gemfile-rails.5.1.x
|
42
|
-
- rvm: 2.6.
|
57
|
+
- rvm: 2.6.6
|
43
58
|
gemfile: gemfiles/Gemfile-rails.5.1.x
|
44
59
|
env: API=1
|
45
|
-
- rvm: 2.6.
|
60
|
+
- rvm: 2.6.6
|
46
61
|
gemfile: gemfiles/Gemfile-rails.5.0.x
|
47
|
-
- rvm: 2.6.
|
62
|
+
- rvm: 2.6.6
|
48
63
|
gemfile: gemfiles/Gemfile-rails.5.0.x
|
49
64
|
env: API=1
|
50
65
|
|
51
|
-
- rvm: 2.5.
|
66
|
+
- rvm: 2.5.8
|
52
67
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
53
68
|
|
54
|
-
- rvm: 2.4.
|
69
|
+
- rvm: 2.4.6
|
55
70
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
56
71
|
|
57
72
|
- rvm: 2.3.8
|
58
73
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
59
74
|
- rvm: 2.3.8
|
60
75
|
gemfile: gemfiles/Gemfile-rails.4.2.x
|
61
|
-
- rvm: 2.3.8
|
62
|
-
gemfile: gemfiles/Gemfile-rails.4.1.x
|
63
|
-
- rvm: 2.3.8
|
64
|
-
gemfile: gemfiles/Gemfile-rails.4.0.x
|
65
76
|
|
66
77
|
- rvm: 2.2.10
|
67
78
|
gemfile: gemfiles/Gemfile-rails.5.2.x
|
@@ -72,10 +83,6 @@ matrix:
|
|
72
83
|
- rvm: 2.0.0
|
73
84
|
gemfile: gemfiles/Gemfile-rails.4.2.x
|
74
85
|
|
75
|
-
- rvm: 2.0.0
|
76
|
-
gemfile: gemfiles/Gemfile-rails.3.2.x
|
77
|
-
|
78
|
-
|
79
86
|
- rvm: ruby-head
|
80
87
|
gemfile: gemfiles/Gemfile-rails.edge
|
81
88
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,35 @@
|
|
1
|
+
## 1.3.4
|
2
|
+
|
3
|
+
* Support Rails 6.1 [@y-yagi]
|
4
|
+
|
5
|
+
## 1.3.3
|
6
|
+
|
7
|
+
* Fixed Ruby 2.7 keyword arguments warning [@pocke]
|
8
|
+
|
9
|
+
## 1.3.2
|
10
|
+
|
11
|
+
* Fixed NameError on ActionController::API controllers without jbuilder enhancement [@kamillle]
|
12
|
+
|
13
|
+
## 1.3.1
|
14
|
+
|
15
|
+
* Switched back from Ruby's `const_get` to Active Support `constantize` for fetching decorator modules, due to inability to properly detect namespaced decorator [@sinsoku]
|
16
|
+
|
17
|
+
## 1.3.0
|
18
|
+
|
19
|
+
* Switched from Active Support `constantize` to Ruby's `const_get` when fetching decorator modules
|
20
|
+
|
21
|
+
* Switched `config` from ActiveSupport::Configurable to a simple Struct
|
22
|
+
|
23
|
+
* Association decoration now propagates from AssociationRelation to spawned Relations (e.g. `@post.comments.order(:id).each`)
|
24
|
+
|
25
|
+
* Dropped support for Rails 3.2, 4.0, and 4.1
|
26
|
+
|
27
|
+
|
28
|
+
## 1.2.0
|
29
|
+
|
30
|
+
* Decorate values in Hash recursively [@FumiyaShibusawa]
|
31
|
+
|
32
|
+
|
1
33
|
## 1.1.1
|
2
34
|
|
3
35
|
* Improved ActionController::API support for Rails 5.0.x [@frodsan]
|
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
|
+
A simple and Rubyish view helper for Rails 4, Rails 5, and Rails 6. Keep your helpers and views Object-Oriented!
|
4
4
|
|
5
5
|
|
6
6
|
## Features ##
|
@@ -17,7 +17,7 @@ A simple and Rubyish view helper for Rails 3, Rails 4, Rails 5, and Rails 6. Kee
|
|
17
17
|
|
18
18
|
* Ruby 2.0.0, 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, and 2.7 (trunk)
|
19
19
|
|
20
|
-
* Rails
|
20
|
+
* Rails 4.2.x, 5.0, 5.1, 5.2, 6.0, and 6.1 (edge)
|
21
21
|
|
22
22
|
|
23
23
|
## Supported ORMs ##
|
@@ -105,7 +105,7 @@ end
|
|
105
105
|
```erb
|
106
106
|
<p><%= @author.name %></p>
|
107
107
|
<ul>
|
108
|
-
<% @author.books.each do |book| %>
|
108
|
+
<% @author.books.order(:id).each do |book| %>
|
109
109
|
<%# `book` here is auto-decorated because @author is a decorated instance %>
|
110
110
|
<li><%= book.link %></li>
|
111
111
|
<% end %>
|
data/active_decorator.gemspec
CHANGED
@@ -13,16 +13,18 @@ Gem::Specification.new do |s|
|
|
13
13
|
s.summary = %q{A simple and Rubyish view helper for Rails}
|
14
14
|
s.description = %q{A simple and Rubyish view helper for Rails}
|
15
15
|
|
16
|
-
s.files =
|
17
|
-
|
18
|
-
|
16
|
+
s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
19
|
s.require_paths = ["lib"]
|
20
20
|
|
21
|
+
s.add_dependency 'activesupport'
|
22
|
+
|
21
23
|
s.add_development_dependency 'test-unit-rails'
|
22
24
|
s.add_development_dependency 'selenium-webdriver'
|
23
25
|
s.add_development_dependency 'puma'
|
24
26
|
s.add_development_dependency 'capybara'
|
25
|
-
s.add_development_dependency 'sqlite3'
|
27
|
+
s.add_development_dependency 'sqlite3'
|
26
28
|
s.add_development_dependency 'rake'
|
27
|
-
s.add_development_dependency '
|
29
|
+
s.add_development_dependency 'byebug'
|
28
30
|
end
|
data/gemfiles/Gemfile-rails.edge
CHANGED
data/lib/active_decorator.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveDecorator
|
4
|
-
|
4
|
+
def self.config
|
5
|
+
@_config ||= Struct.new(:decorator_suffix).new
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
yield config
|
10
|
+
end
|
5
11
|
|
6
12
|
config.decorator_suffix = 'Decorator'
|
7
13
|
end
|
@@ -31,7 +31,7 @@ module ActiveDecorator
|
|
31
31
|
decorate r
|
32
32
|
end
|
33
33
|
elsif obj.is_a?(Hash)
|
34
|
-
obj.
|
34
|
+
obj.each_value do |v|
|
35
35
|
decorate v
|
36
36
|
end
|
37
37
|
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
|
@@ -90,18 +90,14 @@ module ActiveDecorator
|
|
90
90
|
# For AR 3 and 4
|
91
91
|
module RelationDecoratorLegacy
|
92
92
|
def to_a
|
93
|
-
|
94
|
-
ActiveDecorator::Decorator.instance.decorate arr
|
95
|
-
end
|
93
|
+
ActiveDecorator::Decorator.instance.decorate super
|
96
94
|
end
|
97
95
|
end
|
98
96
|
|
99
97
|
# For AR 5+
|
100
98
|
module RelationDecorator
|
101
99
|
def records
|
102
|
-
|
103
|
-
ActiveDecorator::Decorator.instance.decorate arr
|
104
|
-
end
|
100
|
+
ActiveDecorator::Decorator.instance.decorate super
|
105
101
|
end
|
106
102
|
end
|
107
103
|
end
|
@@ -7,10 +7,10 @@ module ActiveDecorator
|
|
7
7
|
module ActionController
|
8
8
|
module Base
|
9
9
|
def rescue_with_handler(*)
|
10
|
-
ActiveDecorator::ViewContext.push(view_context)
|
10
|
+
ActiveDecorator::ViewContext.push(view_context) if defined?(view_context)
|
11
11
|
super
|
12
12
|
ensure
|
13
|
-
ActiveDecorator::ViewContext.pop
|
13
|
+
ActiveDecorator::ViewContext.pop if defined?(view_context)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -5,18 +5,30 @@ module ActiveDecorator
|
|
5
5
|
module Monkey
|
6
6
|
module ActionView
|
7
7
|
module PartialRenderer
|
8
|
+
if Rails.version.to_f >= 6.1
|
9
|
+
def initialize(*)
|
10
|
+
super
|
11
|
+
|
12
|
+
@locals.each_value do |v|
|
13
|
+
ActiveDecorator::Decorator.instance.decorate v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
8
18
|
private
|
9
19
|
|
10
|
-
|
11
|
-
|
20
|
+
if Rails.version.to_f < 6.1
|
21
|
+
def setup(*)
|
22
|
+
super
|
12
23
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
24
|
+
@locals.each_value do |v|
|
25
|
+
ActiveDecorator::Decorator.instance.decorate v
|
26
|
+
end if @locals
|
27
|
+
ActiveDecorator::Decorator.instance.decorate @object if @object
|
28
|
+
ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
|
18
29
|
|
19
|
-
|
30
|
+
self
|
31
|
+
end
|
20
32
|
end
|
21
33
|
end
|
22
34
|
end
|
@@ -11,15 +11,7 @@ module ActiveDecorator
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
if Rails.version.to_f < 4.1
|
16
|
-
module CollectionAssociation
|
17
|
-
private
|
18
|
-
def first_or_last(*)
|
19
|
-
ActiveDecorator::Decorator.instance.decorate_association(owner, super)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
elsif Rails.version.to_f < 5.1
|
14
|
+
if Rails.version.to_f < 5.1
|
23
15
|
module CollectionAssociation
|
24
16
|
private
|
25
17
|
def first_nth_or_last(*)
|
@@ -28,29 +20,41 @@ module ActiveDecorator
|
|
28
20
|
end
|
29
21
|
end
|
30
22
|
|
31
|
-
|
32
|
-
|
33
|
-
|
23
|
+
module CollectionProxy
|
24
|
+
def take(*)
|
25
|
+
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
26
|
+
end
|
27
|
+
|
28
|
+
if Rails.version.to_f >= 5.1
|
29
|
+
def last(*)
|
34
30
|
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
35
31
|
end
|
36
32
|
|
37
|
-
|
38
|
-
def last(limit = nil)
|
39
|
-
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
33
|
+
private
|
43
34
|
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
def find_nth_with_limit(*)
|
36
|
+
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
37
|
+
end
|
47
38
|
|
48
|
-
|
49
|
-
|
50
|
-
end
|
39
|
+
def find_nth_from_last(*)
|
40
|
+
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
51
41
|
end
|
52
42
|
end
|
53
43
|
end
|
44
|
+
|
45
|
+
module CollectionAssociation
|
46
|
+
private
|
47
|
+
|
48
|
+
def build_record(*)
|
49
|
+
ActiveDecorator::Decorator.instance.decorate_association(@owner, super)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module AssociationRelation
|
55
|
+
def spawn(*)
|
56
|
+
ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|