active_decorator 1.4.0 → 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: f803e15d40a85700faf6ceb443bea2fabc225c2d3503e32c99dcb4e54e7f75e3
4
- data.tar.gz: 1c15042cec49c02013f05ff50c91335d00d6acff63b6ae51ccee2ea77c27ec88
3
+ metadata.gz: 23b742ea8c0e64545e2ad4249061b4f459f73f8012c9313d5900b5011399169d
4
+ data.tar.gz: 58b7e4519a166264d6565d04ae593309da02c026240164f01a9dbe3795b100a3
5
5
  SHA512:
6
- metadata.gz: b48a0acdcdce16cd8f3fda7b56c95209af5e833502ea2ea5f9244e9e78bcf4255c376c21f50310631852a928279283d070bed45f618578867eb1edd45f6ddcaa
7
- data.tar.gz: 8b959e33b9c70791a47ee759a6e9c3c877672cda9bb3ba5dc1de0ea4587be5d16bbccd0d0e980fc9ecfaae47adad0f616b35dda7f3c902b05cba064fda21fcc5
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,23 +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
+
1
8
  ## 1.4.0
2
9
 
3
10
  * Decorate non-nil objects where `nil?` returns true, namely, ActionText::RichText body [@jamesbrooks]
4
11
 
12
+
5
13
  ## 1.3.4
6
14
 
7
15
  * Support Rails 6.1 [@y-yagi]
8
16
 
17
+
9
18
  ## 1.3.3
10
19
 
11
20
  * Fixed Ruby 2.7 keyword arguments warning [@pocke]
12
21
 
22
+
13
23
  ## 1.3.2
14
24
 
15
25
  * Fixed NameError on ActionController::API controllers without jbuilder enhancement [@kamillle]
16
26
 
27
+
17
28
  ## 1.3.1
18
29
 
19
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]
20
31
 
32
+
21
33
  ## 1.3.0
22
34
 
23
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, 2.7.x, 3.0.x, and 3.1 (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, 6.1, and 7.0 (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.
@@ -27,34 +27,22 @@ module ActiveDecorator
27
27
 
28
28
  case obj
29
29
  when Array
30
- obj.each do |r|
31
- decorate r
32
- end
30
+ obj.each {|e| decorate e }
33
31
  when Hash
34
- obj.each_value do |v|
35
- decorate v
36
- end
32
+ obj.each_value {|v| decorate v }
37
33
  when nil, true, false
38
- obj
34
+ # Do nothing
39
35
  else
40
- if defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation)
41
- # don't call each nor to_a immediately
42
- if obj.respond_to?(:records)
43
- # Rails 5.0
44
- obj.extend ActiveDecorator::RelationDecorator unless obj.is_a? ActiveDecorator::RelationDecorator
45
- else
46
- # Rails 3.x and 4.x
47
- obj.extend ActiveDecorator::RelationDecoratorLegacy unless obj.is_a? ActiveDecorator::RelationDecoratorLegacy
48
- end
49
- else
50
- if defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Base) && !obj.is_a?(ActiveDecorator::Decorated)
51
- 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
52
41
  end
53
-
54
- d = decorator_for obj.class
55
- return obj unless d
56
- obj.extend d unless obj.is_a? d
57
42
  end
43
+
44
+ d = decorator_for obj.class
45
+ obj.extend d if d && !(d === obj)
58
46
  end
59
47
 
60
48
  obj
@@ -63,45 +51,57 @@ module ActiveDecorator
63
51
  # Decorates AR model object's association only when the object was decorated.
64
52
  # Returns the association instance.
65
53
  def decorate_association(owner, target)
66
- owner.is_a?(ActiveDecorator::Decorated) ? decorate(target) : target
54
+ (ActiveDecorator::Decorated === owner) ? decorate(target) : target
67
55
  end
68
56
 
69
57
  private
70
58
  # Returns a decorator module for the given class.
71
59
  # Returns `nil` if no decorator module was found.
72
60
  def decorator_for(model_class)
73
- return @@decorators[model_class] if @@decorators.key? model_class
61
+ return @decorators[model_class] if @decorators.key? model_class
74
62
 
75
63
  decorator_name = "#{model_class.name}#{ActiveDecorator.config.decorator_suffix}"
76
64
  d = decorator_name.constantize
77
65
  unless Class === d
78
66
  d.send :include, ActiveDecorator::Helpers
79
- @@decorators[model_class] = d
67
+ @decorators[model_class] = d
80
68
  else
81
69
  # Cache nil results
82
- @@decorators[model_class] = nil
70
+ @decorators[model_class] = nil
83
71
  end
84
72
  rescue NameError
85
73
  if model_class.respond_to?(:base_class) && (model_class.base_class != model_class)
86
- @@decorators[model_class] = decorator_for model_class.base_class
74
+ @decorators[model_class] = decorator_for model_class.base_class
87
75
  else
88
76
  # Cache nil results
89
- @@decorators[model_class] = nil
77
+ @decorators[model_class] = nil
90
78
  end
91
79
  end
92
- end
93
80
 
94
- # For AR 3 and 4
95
- module RelationDecoratorLegacy
96
- def to_a
97
- 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
98
91
  end
99
92
  end
100
93
 
101
- # For AR 5+
94
+ # Override AR::Relation#records to decorate each element after being loaded (for AR 5+)
102
95
  module RelationDecorator
103
96
  def records
104
97
  ActiveDecorator::Decorator.instance.decorate super
105
98
  end
106
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
107
107
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveDecorator
4
- VERSION = '1.4.0'
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.4.0
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: 2021-05-09 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.3.0.dev
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,100 +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.7
15
- # - 2.5.9
16
- # - 2.4.10
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: 3.0.1
30
- gemfile: gemfiles/Gemfile-rails.6.1.x
31
- - rvm: 3.0.1
32
- gemfile: gemfiles/Gemfile-rails.6.1.x
33
- env: API=1
34
-
35
- - rvm: 2.7.3
36
- gemfile: gemfiles/Gemfile-rails.6.1.x
37
- - rvm: 2.7.3
38
- gemfile: gemfiles/Gemfile-rails.6.1.x
39
- env: API=1
40
- - rvm: 2.7.3
41
- gemfile: gemfiles/Gemfile-rails.6.0.x
42
- - rvm: 2.7.3
43
- gemfile: gemfiles/Gemfile-rails.6.0.x
44
- env: API=1
45
-
46
- - rvm: 2.6.7
47
- gemfile: gemfiles/Gemfile-rails.6.1.x
48
- - rvm: 2.6.7
49
- gemfile: gemfiles/Gemfile-rails.6.1.x
50
- env: API=1
51
- - rvm: 2.6.7
52
- gemfile: gemfiles/Gemfile-rails.6.0.x
53
- - rvm: 2.6.7
54
- gemfile: gemfiles/Gemfile-rails.6.0.x
55
- env: API=1
56
- - rvm: 2.6.7
57
- gemfile: gemfiles/Gemfile-rails.5.2.x
58
- - rvm: 2.6.7
59
- gemfile: gemfiles/Gemfile-rails.5.2.x
60
- env: API=1
61
- - rvm: 2.6.7
62
- gemfile: gemfiles/Gemfile-rails.5.1.x
63
- - rvm: 2.6.7
64
- gemfile: gemfiles/Gemfile-rails.5.1.x
65
- env: API=1
66
- - rvm: 2.6.7
67
- gemfile: gemfiles/Gemfile-rails.5.0.x
68
- - rvm: 2.6.7
69
- gemfile: gemfiles/Gemfile-rails.5.0.x
70
- env: API=1
71
-
72
- - rvm: 2.5.9
73
- gemfile: gemfiles/Gemfile-rails.5.2.x
74
-
75
- - rvm: 2.4.10
76
- gemfile: gemfiles/Gemfile-rails.5.2.x
77
-
78
- - rvm: 2.3.8
79
- gemfile: gemfiles/Gemfile-rails.5.2.x
80
- - rvm: 2.3.8
81
- gemfile: gemfiles/Gemfile-rails.4.2.x
82
-
83
- - rvm: 2.2.10
84
- gemfile: gemfiles/Gemfile-rails.5.2.x
85
-
86
- - rvm: 2.1.10
87
- gemfile: gemfiles/Gemfile-rails.4.2.x
88
-
89
- - rvm: 2.0.0
90
- gemfile: gemfiles/Gemfile-rails.4.2.x
91
-
92
- - rvm: ruby-head
93
- gemfile: gemfiles/Gemfile-rails.edge
94
- - rvm: ruby-head
95
- gemfile: gemfiles/Gemfile-rails.edge
96
- env: API=1
97
-
98
- allow_failures:
99
- - rvm: ruby-head
100
- - 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,8 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec path: '..'
4
-
5
- gem 'rails', '~> 6.1.0'
6
- gem 'webdrivers'
7
- gem 'rexml'
8
- 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