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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +34 -27
  4. data/CHANGELOG.md +32 -0
  5. data/README.md +3 -3
  6. data/active_decorator.gemspec +7 -5
  7. data/gemfiles/Gemfile-rails.4.2.x +2 -0
  8. data/gemfiles/Gemfile-rails.5.0.x +2 -0
  9. data/gemfiles/Gemfile-rails.5.1.x +1 -0
  10. data/gemfiles/Gemfile-rails.5.2.x +3 -1
  11. data/gemfiles/Gemfile-rails.6.0.x +7 -0
  12. data/gemfiles/Gemfile-rails.6.1.x +7 -0
  13. data/gemfiles/Gemfile-rails.edge +6 -0
  14. data/lib/active_decorator.rb +5 -1
  15. data/lib/active_decorator/config.rb +7 -1
  16. data/lib/active_decorator/decorator.rb +3 -7
  17. data/lib/active_decorator/helpers.rb +1 -0
  18. data/lib/active_decorator/monkey/action_controller/base/rescue_from.rb +2 -2
  19. data/lib/active_decorator/monkey/action_view/collection_renderer.rb +12 -0
  20. data/lib/active_decorator/monkey/action_view/object_renderer.rb +12 -0
  21. data/lib/active_decorator/monkey/action_view/partial_renderer.rb +20 -8
  22. data/lib/active_decorator/monkey/active_record/associations.rb +28 -24
  23. data/lib/active_decorator/railtie.rb +16 -6
  24. data/lib/active_decorator/version.rb +1 -1
  25. data/lib/active_decorator/view_context.rb +3 -11
  26. data/lib/generators/rails/templates/decorator.rb +2 -0
  27. data/lib/generators/rspec/templates/decorator_spec.rb +2 -0
  28. data/lib/generators/test_unit/templates/decorator_test.rb +2 -0
  29. metadata +30 -71
  30. data/gemfiles/Gemfile-rails.3.2.x +0 -8
  31. data/gemfiles/Gemfile-rails.4.0.x +0 -6
  32. data/gemfiles/Gemfile-rails.4.1.x +0 -6
  33. data/test/configuration_test.rb +0 -28
  34. data/test/controllers/fake_detection_test.rb +0 -14
  35. data/test/decorator_test.rb +0 -51
  36. data/test/fake_app/app/views/api/bookstores/show.json.jbuilder +0 -1
  37. data/test/fake_app/app/views/authors/index.html.erb +0 -16
  38. data/test/fake_app/app/views/authors/show.html.erb +0 -10
  39. data/test/fake_app/app/views/authors/show.json.jbuilder +0 -2
  40. data/test/fake_app/app/views/book_mailer/thanks.text.erb +0 -1
  41. data/test/fake_app/app/views/books/_book.html.erb +0 -2
  42. data/test/fake_app/app/views/books/_book.json.jbuilder +0 -2
  43. data/test/fake_app/app/views/books/_book_locals.html.erb +0 -2
  44. data/test/fake_app/app/views/books/errata.html.erb +0 -1
  45. data/test/fake_app/app/views/books/errata2.html.erb +0 -1
  46. data/test/fake_app/app/views/books/error.html.erb +0 -1
  47. data/test/fake_app/app/views/books/index.html.erb +0 -4
  48. data/test/fake_app/app/views/books/purchase.html.erb +0 -1
  49. data/test/fake_app/app/views/books/show.html.erb +0 -4
  50. data/test/fake_app/app/views/movies/show.html.erb +0 -2
  51. data/test/fake_app/fake_app.rb +0 -288
  52. data/test/fake_app/public/images/cover.png +0 -0
  53. data/test/features/action_controller_api_test.rb +0 -19
  54. data/test/features/action_view_helpers_test.rb +0 -38
  55. data/test/features/association_test.rb +0 -43
  56. data/test/features/controller_ivar_test.rb +0 -41
  57. data/test/features/jbuilder_test.rb +0 -16
  58. data/test/features/name_error_handling_test.rb +0 -29
  59. data/test/features/partial_test.rb +0 -29
  60. data/test/test_helper.rb +0 -51
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aaf638a40c289f98d04544cf74fb6fc4ed4e6d900e9624612ad4369a61b2032d
4
- data.tar.gz: 014c96599fa99736ff84c75571a95e6ad49bb24d99220e382b78e8516f746759
3
+ metadata.gz: abd22d415613228c6c98fe9a0bf7255496dabaada709c34ba2cbe032a2fcc9b6
4
+ data.tar.gz: af38045be9a3de1832be692fa8f349010e7f79c7144d8d1f9f248aa3c311abb3
5
5
  SHA512:
6
- metadata.gz: f2270ef449d855e51524d81ba1feeda5582732969dd622a0e2e4cc4b700e8e0d1529e0f891ca39572f2c03c41cd6143a2809c8dad27fcfdca1c3408434445ee0
7
- data.tar.gz: 515a67fa6e3964ec7b8ece6a6ec4d410fd4479aac285d2bd2d6c59eeea023a35123b54b3bb0c0e4481931328d89200c682f7756db534934d59b90ff6b52984c9
6
+ metadata.gz: 39f6198f7583dbc4df7bb3071161f234ce858cda7d17a27c07caab910bc3a1c652468cd42dfd7bf094cb53ceedc9da8c9a35d031a0e258398dc41f15b44d2925
7
+ data.tar.gz: 3b342f062765a460b03b3adbe2562cf01579a4b54427713dd3abe88694e371acee44ded648a218e9a2fd2872285635a08016cf11a0b68ecae0631243c6909c2f
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ gemfiles/*.lock
5
5
  pkg/*
6
6
  log
7
7
  tmp
8
+ .byebug_history
@@ -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.2
18
- # - 2.5.5
19
- # - 2.4.5
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.6.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.2
52
+ - rvm: 2.6.6
38
53
  gemfile: gemfiles/Gemfile-rails.5.2.x
39
54
  env: API=1
40
- - rvm: 2.6.2
55
+ - rvm: 2.6.6
41
56
  gemfile: gemfiles/Gemfile-rails.5.1.x
42
- - rvm: 2.6.2
57
+ - rvm: 2.6.6
43
58
  gemfile: gemfiles/Gemfile-rails.5.1.x
44
59
  env: API=1
45
- - rvm: 2.6.2
60
+ - rvm: 2.6.6
46
61
  gemfile: gemfiles/Gemfile-rails.5.0.x
47
- - rvm: 2.6.2
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.5
66
+ - rvm: 2.5.8
52
67
  gemfile: gemfiles/Gemfile-rails.5.2.x
53
68
 
54
- - rvm: 2.4.5
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
 
@@ -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, Rails 4, Rails 5, and Rails 6. Keep your helpers and views Object-Oriented!
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 3.2.x, 4.0.x, 4.1.x, 4.2.x, 5.0, 5.1, 5.2, and 6.0 (edge)
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 %>
@@ -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 = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
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', '< 1.4'
27
+ s.add_development_dependency 'sqlite3'
26
28
  s.add_development_dependency 'rake'
27
- s.add_development_dependency 'jbuilder'
29
+ s.add_development_dependency 'byebug'
28
30
  end
@@ -3,4 +3,6 @@ source 'https://rubygems.org'
3
3
  gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 4.2.0'
6
+ gem 'sqlite3', '< 1.4'
6
7
  gem 'nokogiri', '~> 1.6.0'
8
+ gem 'jbuilder' unless ENV['API']
@@ -3,3 +3,5 @@ source 'https://rubygems.org'
3
3
  gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 5.0.0'
6
+ gem 'sqlite3', '< 1.4'
7
+ gem 'jbuilder' unless ENV['API']
@@ -3,3 +3,4 @@ source 'https://rubygems.org'
3
3
  gemspec path: '..'
4
4
 
5
5
  gem 'rails', '~> 5.1.0'
6
+ gem 'jbuilder' unless ENV['API']
@@ -2,4 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec path: '..'
4
4
 
5
- gem 'rails', '~> 5.2.0'
5
+ gem 'rails', git: 'https://github.com/rails/rails', branch: '5-2-stable'
6
+ gem 'webdrivers', '< 4'
7
+ gem 'jbuilder' unless ENV['API']
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 6.0.0'
6
+ gem 'webdrivers'
7
+ gem 'jbuilder' unless ENV['API']
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec path: '..'
4
+
5
+ gem 'rails', '~> 6.1.0'
6
+ gem 'webdrivers'
7
+ gem 'jbuilder' unless ENV['API']
@@ -10,3 +10,9 @@ end
10
10
  github 'rails/rails' do
11
11
  gem 'rails'
12
12
  end
13
+
14
+ unless ENV['API']
15
+ github 'rails/jbuilder' do
16
+ gem 'jbuilder'
17
+ end
18
+ end
@@ -2,5 +2,9 @@
2
2
 
3
3
  require 'active_decorator/version'
4
4
  require 'active_decorator/decorator'
5
- require 'active_decorator/railtie'
5
+ begin
6
+ require 'rails'
7
+ require 'active_decorator/railtie'
8
+ rescue LoadError
9
+ end
6
10
  require 'active_decorator/config'
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDecorator
4
- include ActiveSupport::Configurable
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.values.each do |v|
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
- super.tap do |arr|
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
- super.tap do |arr|
103
- ActiveDecorator::Decorator.instance.decorate arr
104
- end
100
+ ActiveDecorator::Decorator.instance.decorate super
105
101
  end
106
102
  end
107
103
  end
@@ -25,5 +25,6 @@ module ActiveDecorator
25
25
  raise e1
26
26
  end
27
27
  end
28
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
28
29
  end
29
30
  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
@@ -0,0 +1,12 @@
1
+ module ActiveDecorator
2
+ module Monkey
3
+ module ActionView
4
+ module CollectionRenderer
5
+ def render_collection_with_partial(collection, *)
6
+ ActiveDecorator::Decorator.instance.decorate collection
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module ActiveDecorator
2
+ module Monkey
3
+ module ActionView
4
+ module ObjectRenderer
5
+ def render_object_with_partial(object, *)
6
+ ActiveDecorator::Decorator.instance.decorate object
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
12
+ 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
- def setup(*)
11
- super
20
+ if Rails.version.to_f < 6.1
21
+ def setup(*)
22
+ super
12
23
 
13
- @locals.each_value do |v|
14
- ActiveDecorator::Decorator.instance.decorate v
15
- end if @locals
16
- ActiveDecorator::Decorator.instance.decorate @object if @object
17
- ActiveDecorator::Decorator.instance.decorate @collection unless @collection.blank?
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
- self
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
- # @see https://github.com/rails/rails/commit/03855e790de2224519f55382e3c32118be31eeff
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
- if Rails.version.to_f >= 4.0
32
- module CollectionProxy
33
- def take(limit = nil)
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
- if Rails.version.to_f >= 5.1
38
- def last(limit = nil)
39
- ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
40
- end
41
-
42
- private
33
+ private
43
34
 
44
- def find_nth_with_limit(index, limit)
45
- ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
46
- end
35
+ def find_nth_with_limit(*)
36
+ ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
37
+ end
47
38
 
48
- def find_nth_from_last(index)
49
- ActiveDecorator::Decorator.instance.decorate_association(@association.owner, super)
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