active_decorator 1.3.4 → 1.4.1

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
  SHA256:
3
- metadata.gz: abd22d415613228c6c98fe9a0bf7255496dabaada709c34ba2cbe032a2fcc9b6
4
- data.tar.gz: af38045be9a3de1832be692fa8f349010e7f79c7144d8d1f9f248aa3c311abb3
3
+ metadata.gz: 23b742ea8c0e64545e2ad4249061b4f459f73f8012c9313d5900b5011399169d
4
+ data.tar.gz: 58b7e4519a166264d6565d04ae593309da02c026240164f01a9dbe3795b100a3
5
5
  SHA512:
6
- metadata.gz: 39f6198f7583dbc4df7bb3071161f234ce858cda7d17a27c07caab910bc3a1c652468cd42dfd7bf094cb53ceedc9da8c9a35d031a0e258398dc41f15b44d2925
7
- data.tar.gz: 3b342f062765a460b03b3adbe2562cf01579a4b54427713dd3abe88694e371acee44ded648a218e9a2fd2872285635a08016cf11a0b68ecae0631243c6909c2f
6
+ metadata.gz: 23f24b4acbb2c9cfdbfb6c4c6ce7f6aafba6924bab0fc924b7ebeb51f9dad4ffbb5bb8280f9b7f12a51fbcb1cd0be859e6d7621cf4092d344afce85536364a16
7
+ data.tar.gz: 4e4938a409750f666a0bffacd411c82d33e79b247acd221c9f62ac150e00dc12a361e9e3bc7dbd151aeaccacafe165348621b927c10ab5e2c15ddec4c895c79d
@@ -0,0 +1,7 @@
1
+ version: 2
2
+
3
+ updates:
4
+ - package-ecosystem: github-actions
5
+ directory: "/"
6
+ schedule:
7
+ interval: daily
@@ -0,0 +1,88 @@
1
+ name: build
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '45 23 * * *'
8
+
9
+ jobs:
10
+ build:
11
+ name: Ruby ${{ matrix.ruby_version }} / Rails ${{ matrix.rails_version }}${{ matrix.api == '1' && ' / API' || '' }}
12
+ strategy:
13
+ matrix:
14
+ ruby_version: [ruby-head, '3.2', '3.1', '3.0', '2.7']
15
+ rails_version: [edge, '7.0', '6.1']
16
+ api: ['0', '1']
17
+
18
+ include:
19
+ - ruby_version: '2.7'
20
+ rails_version: '6.0'
21
+ - ruby_version: '2.7'
22
+ rails_version: '6.0'
23
+ api: '1'
24
+
25
+ - ruby_version: '2.6'
26
+ rails_version: '6.1'
27
+ - ruby_version: '2.6'
28
+ rails_version: '6.1'
29
+ api: '1'
30
+ - ruby_version: '2.6'
31
+ rails_version: '6.0'
32
+ - ruby_version: '2.6'
33
+ rails_version: '6.0'
34
+ api: '1'
35
+ - ruby_version: '2.6'
36
+ rails_version: '5.2'
37
+ - ruby_version: '2.6'
38
+ rails_version: '5.2'
39
+ api: '1'
40
+ - ruby_version: '2.6'
41
+ rails_version: '5.1'
42
+ - ruby_version: '2.6'
43
+ rails_version: '5.1'
44
+ api: '1'
45
+ - ruby_version: '2.6'
46
+ rails_version: '5.0'
47
+ - ruby_version: '2.6'
48
+ rails_version: '5.0'
49
+ api: '1'
50
+
51
+ - ruby_version: '2.5'
52
+ rails_version: '5.2'
53
+
54
+ - ruby_version: '2.4'
55
+ rails_version: '5.2'
56
+
57
+ - ruby_version: '2.3'
58
+ rails_version: '5.2'
59
+ - ruby_version: '2.3'
60
+ rails_version: '4.2'
61
+ bundler_version: '1'
62
+
63
+ - ruby_version: '2.2'
64
+ rails_version: '5.2'
65
+
66
+ - ruby_version: '2.1'
67
+ rails_version: '4.2'
68
+ bundler_version: '1'
69
+
70
+ env:
71
+ RAILS_VERSION: ${{ matrix.rails_version }}
72
+ API: ${{ matrix.api }}
73
+
74
+ runs-on: ubuntu-20.04
75
+
76
+ steps:
77
+ - uses: actions/checkout@v3
78
+
79
+ - uses: ruby/setup-ruby@v1
80
+ with:
81
+ ruby-version: ${{ matrix.ruby_version }}
82
+ rubygems: ${{ matrix.ruby_version < '2.6' && 'default' || 'latest' }}
83
+ bundler: ${{ matrix.bundler_version }}
84
+ bundler-cache: true
85
+ continue-on-error: ${{ matrix.allow_failures == 'true' }}
86
+
87
+ - run: bundle exec rake
88
+ continue-on-error: ${{ matrix.allow_failures == 'true' }}
data/CHANGELOG.md CHANGED
@@ -1,19 +1,35 @@
1
+ ## 1.4.1
2
+
3
+ * Support Ruby 3.2 by `File.exists?` => `File.exists?` in generator [@kyoshidajp]
4
+
5
+ * A little bit of internal code cleanup
6
+
7
+
8
+ ## 1.4.0
9
+
10
+ * Decorate non-nil objects where `nil?` returns true, namely, ActionText::RichText body [@jamesbrooks]
11
+
12
+
1
13
  ## 1.3.4
2
14
 
3
15
  * Support Rails 6.1 [@y-yagi]
4
16
 
17
+
5
18
  ## 1.3.3
6
19
 
7
20
  * Fixed Ruby 2.7 keyword arguments warning [@pocke]
8
21
 
22
+
9
23
  ## 1.3.2
10
24
 
11
25
  * Fixed NameError on ActionController::API controllers without jbuilder enhancement [@kamillle]
12
26
 
27
+
13
28
  ## 1.3.1
14
29
 
15
30
  * 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
31
 
32
+
17
33
  ## 1.3.0
18
34
 
19
35
  * Switched from Active Support `constantize` to Ruby's `const_get` when fetching decorator modules
data/Gemfile CHANGED
@@ -3,3 +3,28 @@
3
3
  source 'https://rubygems.org'
4
4
 
5
5
  gemspec
6
+
7
+ if ENV['RAILS_VERSION'] == 'edge'
8
+ gem 'rails', git: 'https://github.com/rails/rails.git'
9
+ gem 'rackup'
10
+ elsif ENV['RAILS_VERSION']
11
+ gem 'rails', "~> #{ENV['RAILS_VERSION']}.0"
12
+ gem 'sqlite3', '< 1.4' if ENV['RAILS_VERSION'] <= '5.0'
13
+ gem 'rackup' if ENV['RAILS_VERSION'] > '7.1'
14
+ else
15
+ gem 'rails'
16
+ end
17
+
18
+ if RUBY_VERSION < '2.7'
19
+ gem 'puma', '< 6'
20
+ else
21
+ gem 'puma'
22
+ end
23
+
24
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
25
+ gem 'loofah', RUBY_VERSION < '2.5' ? '< 2.21.0' : '>= 0'
26
+ gem 'concurrent-ruby', RUBY_VERSION < '2.3' ? '~> 1.1.0' : '>= 1.2'
27
+ gem 'selenium-webdriver', RUBY_VERSION == '3.0' ? '4.9.0' : '>= 0'
28
+ gem 'webdrivers' if ENV['RAILS_VERSION'] && ENV['RAILS_VERSION'] >= '6'
29
+ gem 'net-smtp' if RUBY_VERSION >= '3.1'
30
+ gem 'jbuilder' unless ENV['API'] == '1'
data/README.md CHANGED
@@ -1,6 +1,6 @@
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)
1
+ # ActiveDecorator [![Build Status](https://github.com/amatsuda/active_decorator/actions/workflows/main.yml/badge.svg)](https://github.com/amatsuda/active_decorator/actions) [![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 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, Rails 6, and Rails 7. 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 4, Rails 5, and Rails 6. Keep your he
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, 2.5.x, 2.6.x, and 2.7 (trunk)
18
+ * Ruby 2.1.x, 2.2.x, 2.3.x, 2.4.x, 2.5.x, 2.6.x, 2.7.x, 3.0.x, 3.1.x, 3.2.x, and 3.3 (trunk)
19
19
 
20
- * Rails 4.2.x, 5.0, 5.1, 5.2, 6.0, and 6.1 (edge)
20
+ * Rails 4.2.x, 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, and 7.1 (edge)
21
21
 
22
22
 
23
23
  ## Supported ORMs ##
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ require 'rake/testtask'
8
8
 
9
9
  Rake::TestTask.new do |t|
10
10
  t.libs << "test"
11
- if ENV['API']
11
+ if ENV['API'] == '1'
12
12
  t.pattern = 'test/**/*_api_test.rb'
13
13
  else
14
14
  t.test_files = Dir['test/**/*_test.rb'] - Dir['test/**/*_api_test.rb']
@@ -9,7 +9,7 @@ module ActiveDecorator
9
9
  include Singleton
10
10
 
11
11
  def initialize
12
- @@decorators = {}
12
+ @decorators = {}
13
13
  end
14
14
 
15
15
  # Decorates the given object.
@@ -23,34 +23,26 @@ module ActiveDecorator
23
23
  #
24
24
  # This method can be publicly called from anywhere by `ActiveDecorator::Decorator.instance.decorate(obj)`.
25
25
  def decorate(obj)
26
- return if defined?(Jbuilder) && (Jbuilder === obj)
27
- return if obj.nil?
26
+ return obj if defined?(Jbuilder) && (Jbuilder === obj)
28
27
 
29
- if obj.is_a?(Array)
30
- obj.each do |r|
31
- decorate r
32
- end
33
- elsif obj.is_a?(Hash)
34
- obj.each_value do |v|
35
- decorate v
36
- end
37
- elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
38
- # don't call each nor to_a immediately
39
- if obj.respond_to?(:records)
40
- # Rails 5.0
41
- obj.extend ActiveDecorator::RelationDecorator unless obj.is_a? ActiveDecorator::RelationDecorator
42
- else
43
- # Rails 3.x and 4.x
44
- obj.extend ActiveDecorator::RelationDecoratorLegacy unless obj.is_a? ActiveDecorator::RelationDecoratorLegacy
45
- end
28
+ case obj
29
+ when Array
30
+ obj.each {|e| decorate e }
31
+ when Hash
32
+ obj.each_value {|v| decorate v }
33
+ when nil, true, false
34
+ # Do nothing
46
35
  else
47
- if defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Base) && !obj.is_a?(ActiveDecorator::Decorated)
48
- obj.extend ActiveDecorator::Decorated
36
+ if defined? ActiveRecord
37
+ if obj.is_a? ActiveRecord::Relation
38
+ return decorate_relation obj
39
+ elsif ActiveRecord::Base === obj
40
+ obj.extend ActiveDecorator::Decorated unless ActiveDecorator::Decorated === obj
41
+ end
49
42
  end
50
43
 
51
44
  d = decorator_for obj.class
52
- return obj unless d
53
- obj.extend d unless obj.is_a? d
45
+ obj.extend d if d && !(d === obj)
54
46
  end
55
47
 
56
48
  obj
@@ -59,45 +51,57 @@ module ActiveDecorator
59
51
  # Decorates AR model object's association only when the object was decorated.
60
52
  # Returns the association instance.
61
53
  def decorate_association(owner, target)
62
- owner.is_a?(ActiveDecorator::Decorated) ? decorate(target) : target
54
+ (ActiveDecorator::Decorated === owner) ? decorate(target) : target
63
55
  end
64
56
 
65
57
  private
66
58
  # Returns a decorator module for the given class.
67
59
  # Returns `nil` if no decorator module was found.
68
60
  def decorator_for(model_class)
69
- return @@decorators[model_class] if @@decorators.key? model_class
61
+ return @decorators[model_class] if @decorators.key? model_class
70
62
 
71
63
  decorator_name = "#{model_class.name}#{ActiveDecorator.config.decorator_suffix}"
72
64
  d = decorator_name.constantize
73
65
  unless Class === d
74
66
  d.send :include, ActiveDecorator::Helpers
75
- @@decorators[model_class] = d
67
+ @decorators[model_class] = d
76
68
  else
77
69
  # Cache nil results
78
- @@decorators[model_class] = nil
70
+ @decorators[model_class] = nil
79
71
  end
80
72
  rescue NameError
81
73
  if model_class.respond_to?(:base_class) && (model_class.base_class != model_class)
82
- @@decorators[model_class] = decorator_for model_class.base_class
74
+ @decorators[model_class] = decorator_for model_class.base_class
83
75
  else
84
76
  # Cache nil results
85
- @@decorators[model_class] = nil
77
+ @decorators[model_class] = nil
86
78
  end
87
79
  end
88
- end
89
80
 
90
- # For AR 3 and 4
91
- module RelationDecoratorLegacy
92
- def to_a
93
- ActiveDecorator::Decorator.instance.decorate super
81
+ # Decorate with proper monkey patch based on AR version
82
+ def decorate_relation(obj)
83
+ if obj.respond_to?(:records)
84
+ # Rails 5.0
85
+ obj.extend ActiveDecorator::RelationDecorator unless ActiveDecorator::RelationDecorator === obj
86
+ else
87
+ # Rails 3.x and 4.x
88
+ obj.extend ActiveDecorator::RelationDecoratorLegacy unless ActiveDecorator::RelationDecoratorLegacy === obj
89
+ end
90
+ obj
94
91
  end
95
92
  end
96
93
 
97
- # For AR 5+
94
+ # Override AR::Relation#records to decorate each element after being loaded (for AR 5+)
98
95
  module RelationDecorator
99
96
  def records
100
97
  ActiveDecorator::Decorator.instance.decorate super
101
98
  end
102
99
  end
100
+
101
+ # Override AR::Relation#to_a to decorate each element after being loaded (for AR 3 and 4)
102
+ module RelationDecoratorLegacy
103
+ def to_a
104
+ ActiveDecorator::Decorator.instance.decorate super
105
+ end
106
+ end
103
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDecorator
4
- VERSION = '1.3.4'
4
+ VERSION = '1.4.1'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require '<%= File.exists?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
3
+ require '<%= File.exist?('spec/rails_helper.rb') ? 'rails_helper' : 'spec_helper' %>'
4
4
 
5
5
  RSpec.describe <%= class_name %>Decorator do
6
6
  let(:<%= singular_name %>) { <%= class_name %>.new.extend <%= class_name %>Decorator }
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.3.4
4
+ version: 1.4.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: 2020-12-21 00:00:00.000000000 Z
11
+ date: 2023-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,21 +129,15 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - ".github/dependabot.yml"
133
+ - ".github/workflows/main.yml"
132
134
  - ".gitignore"
133
- - ".travis.yml"
134
135
  - CHANGELOG.md
135
136
  - Gemfile
136
137
  - MIT-LICENSE
137
138
  - README.md
138
139
  - Rakefile
139
140
  - active_decorator.gemspec
140
- - gemfiles/Gemfile-rails.4.2.x
141
- - gemfiles/Gemfile-rails.5.0.x
142
- - gemfiles/Gemfile-rails.5.1.x
143
- - gemfiles/Gemfile-rails.5.2.x
144
- - gemfiles/Gemfile-rails.6.0.x
145
- - gemfiles/Gemfile-rails.6.1.x
146
- - gemfiles/Gemfile-rails.edge
147
141
  - lib/active_decorator.rb
148
142
  - lib/active_decorator/config.rb
149
143
  - lib/active_decorator/decorated.rb
@@ -184,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
184
178
  - !ruby/object:Gem::Version
185
179
  version: '0'
186
180
  requirements: []
187
- rubygems_version: 3.2.0
181
+ rubygems_version: 3.5.0.dev
188
182
  signing_key:
189
183
  specification_version: 4
190
184
  summary: A simple and Rubyish view helper for Rails
data/.travis.yml DELETED
@@ -1,95 +0,0 @@
1
- language: ruby
2
-
3
- addons:
4
- chrome: stable
5
-
6
- before_install:
7
- - sudo apt update -qq
8
- - sudo apt install -y chromium-chromedriver
9
- - gem i bundler -v '<2'
10
-
11
- cache: bundler
12
-
13
- # rvm:
14
- # - 2.6.6
15
- # - 2.5.8
16
- # - 2.4.6
17
- # - 2.3.8
18
- # - 2.2.10
19
- # - 2.1.10
20
- # - 2.0.0
21
- # gemfile:
22
- # - gemfiles/Gemfile-rails.5.2.x
23
- # - gemfiles/Gemfile-rails.5.1.x
24
- # - gemfiles/Gemfile-rails.5.0.x
25
- # - gemfiles/Gemfile-rails.4.2.x
26
-
27
- matrix:
28
- include:
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
51
- gemfile: gemfiles/Gemfile-rails.5.2.x
52
- - rvm: 2.6.6
53
- gemfile: gemfiles/Gemfile-rails.5.2.x
54
- env: API=1
55
- - rvm: 2.6.6
56
- gemfile: gemfiles/Gemfile-rails.5.1.x
57
- - rvm: 2.6.6
58
- gemfile: gemfiles/Gemfile-rails.5.1.x
59
- env: API=1
60
- - rvm: 2.6.6
61
- gemfile: gemfiles/Gemfile-rails.5.0.x
62
- - rvm: 2.6.6
63
- gemfile: gemfiles/Gemfile-rails.5.0.x
64
- env: API=1
65
-
66
- - rvm: 2.5.8
67
- gemfile: gemfiles/Gemfile-rails.5.2.x
68
-
69
- - rvm: 2.4.6
70
- gemfile: gemfiles/Gemfile-rails.5.2.x
71
-
72
- - rvm: 2.3.8
73
- gemfile: gemfiles/Gemfile-rails.5.2.x
74
- - rvm: 2.3.8
75
- gemfile: gemfiles/Gemfile-rails.4.2.x
76
-
77
- - rvm: 2.2.10
78
- gemfile: gemfiles/Gemfile-rails.5.2.x
79
-
80
- - rvm: 2.1.10
81
- gemfile: gemfiles/Gemfile-rails.4.2.x
82
-
83
- - rvm: 2.0.0
84
- gemfile: gemfiles/Gemfile-rails.4.2.x
85
-
86
- - rvm: ruby-head
87
- gemfile: gemfiles/Gemfile-rails.edge
88
-
89
- - rvm: ruby-head
90
- gemfile: gemfiles/Gemfile-rails.edge
91
- env: API=1
92
-
93
- allow_failures:
94
- - rvm: ruby-head
95
- - gemfile: gemfiles/Gemfile-rails.edge
@@ -1,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 4.2.0'
6
- gem 'sqlite3', '< 1.4'
7
- gem 'nokogiri', '~> 1.6.0'
8
- gem 'jbuilder' unless ENV['API']
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 5.0.0'
6
- gem 'sqlite3', '< 1.4'
7
- gem 'jbuilder' unless ENV['API']
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 5.1.0'
6
- gem 'jbuilder' unless ENV['API']
@@ -1,7 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', git: 'https://github.com/rails/rails', branch: '5-2-stable'
6
- gem 'webdrivers', '< 4'
7
- gem 'jbuilder' unless ENV['API']
@@ -1,7 +0,0 @@
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']
@@ -1,7 +0,0 @@
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']
@@ -1,18 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- git_source(:github) do |repo_name|
6
- repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
7
- "https://github.com/#{repo_name}.git"
8
- end
9
-
10
- github 'rails/rails' do
11
- gem 'rails'
12
- end
13
-
14
- unless ENV['API']
15
- github 'rails/jbuilder' do
16
- gem 'jbuilder'
17
- end
18
- end