amoeba 3.2.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/activerecord_head.yml +26 -0
- data/.github/workflows/jruby.yml +30 -0
- data/.github/workflows/rspec.yml +49 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +12 -8
- data/.rubocop_todo.yml +149 -0
- data/Appraisals +31 -38
- data/CHANGELOG.md +68 -0
- data/Gemfile +6 -2
- data/LICENSE.md +11 -0
- data/README.md +28 -17
- data/Rakefile +2 -0
- data/amoeba.gemspec +18 -17
- data/docs/contributing.md +19 -0
- data/docs/test_refactor.md +20 -0
- data/gemfiles/activerecord_6.1.gemfile +17 -8
- data/gemfiles/activerecord_7.0.gemfile +22 -0
- data/gemfiles/activerecord_7.1.gemfile +21 -0
- data/gemfiles/activerecord_8.0.gemfile +21 -0
- data/gemfiles/activerecord_8.1.gemfile +21 -0
- data/gemfiles/activerecord_head.gemfile +12 -13
- data/gemfiles/jruby_activerecord_7.0.gemfile +20 -0
- data/gemfiles/jruby_activerecord_head.gemfile +15 -15
- data/lib/amoeba/class_methods.rb +2 -0
- data/lib/amoeba/cloner.rb +15 -6
- data/lib/amoeba/config.rb +30 -53
- data/lib/amoeba/instance_methods.rb +3 -0
- data/lib/amoeba/macros/base.rb +4 -1
- data/lib/amoeba/macros/has_and_belongs_to_many.rb +2 -0
- data/lib/amoeba/macros/has_many.rb +2 -0
- data/lib/amoeba/macros/has_one.rb +4 -0
- data/lib/amoeba/macros.rb +2 -0
- data/lib/amoeba/version.rb +3 -1
- data/lib/amoeba.rb +6 -2
- data/spec/lib/amoeba_spec.rb +425 -231
- data/spec/spec_helper.rb +16 -6
- data/spec/support/data.rb +23 -14
- data/spec/support/models.rb +50 -40
- data/spec/support/schema.rb +2 -0
- metadata +53 -39
- data/.travis.yml +0 -110
- data/gemfiles/activerecord_4.2.gemfile +0 -18
- data/gemfiles/activerecord_5.0.gemfile +0 -18
- data/gemfiles/activerecord_5.1.gemfile +0 -18
- data/gemfiles/activerecord_5.2.gemfile +0 -18
- data/gemfiles/activerecord_6.0.gemfile +0 -18
- data/gemfiles/jruby_activerecord_6.1.gemfile +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e23f137845db9ab5d966278ecc7310519e2194767cb156bd3b20063441d126e2
|
|
4
|
+
data.tar.gz: b0006cfc924dc4d1f443b065ab0592719af14adf0b3a0d58e3f24e680ac404d5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f49bff4617121516954f3423b512ef9ed0e7e4fe8cbb444c5d6faad681009882948332cd28907c3a194cb4fb18ee9472504b489f24295918b853ecdcdeeb37b
|
|
7
|
+
data.tar.gz: a50ebd357ae15ca4ff5efb96b959e6fa5e3de692de6fd396dc6a64c6a0d188e4a7fa2237f61dc42b59da772320ff0ef8ed967980a9be550381eb89678227e794
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Active Record head
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
ruby_version: [ 3.3, 3.4, '4.0', head ]
|
|
15
|
+
env:
|
|
16
|
+
BUNDLE_GEMFILE: gemfiles/activerecord_head.gemfile
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- name: Set up Ruby
|
|
20
|
+
uses: ruby/setup-ruby@v1
|
|
21
|
+
with:
|
|
22
|
+
ruby-version: ${{ matrix.ruby_version }}
|
|
23
|
+
bundler-cache: true
|
|
24
|
+
- name: Run tests
|
|
25
|
+
# Allow tests to run on Active Record head without failing the pipeline
|
|
26
|
+
run: bundle exec rspec || true
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: JRuby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
gemfile: [ jruby_activerecord_7.0 ]
|
|
15
|
+
env:
|
|
16
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
|
17
|
+
JRUBY_OPTS: --debug
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v4
|
|
20
|
+
- name: Set up Ruby
|
|
21
|
+
uses: ruby/setup-ruby@v1
|
|
22
|
+
with:
|
|
23
|
+
ruby-version: jruby
|
|
24
|
+
bundler-cache: true
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: bundle exec rspec
|
|
27
|
+
- name: Coveralls
|
|
28
|
+
uses: coverallsapp/github-action@master
|
|
29
|
+
with:
|
|
30
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
name: Ruby
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
strategy:
|
|
14
|
+
matrix:
|
|
15
|
+
ruby_version: [ '3.0', 3.1, 3.2, 3.3, 3.4, '4.0', head ]
|
|
16
|
+
gemfile: [ activerecord_6.1, activerecord_7.0, activerecord_7.1, activerecord_8.0, activerecord_8.1 ]
|
|
17
|
+
exclude:
|
|
18
|
+
# Active Record 6.1 - 7.1 tests require sqlite3 1.6.9 which is not supported in Ruby 4.1 onwards
|
|
19
|
+
- ruby_version: head
|
|
20
|
+
gemfile: activerecord_6.1
|
|
21
|
+
- ruby_version: head
|
|
22
|
+
gemfile: activerecord_7.0
|
|
23
|
+
- ruby_version: head
|
|
24
|
+
gemfile: activerecord_7.1
|
|
25
|
+
- ruby_version: '3.0'
|
|
26
|
+
gemfile: activerecord_8.0
|
|
27
|
+
- ruby_version: '3.0'
|
|
28
|
+
gemfile: activerecord_8.1
|
|
29
|
+
- ruby_version: 3.1
|
|
30
|
+
gemfile: activerecord_8.0
|
|
31
|
+
- ruby_version: 3.1
|
|
32
|
+
gemfile: activerecord_8.1
|
|
33
|
+
- ruby_version: 3.2
|
|
34
|
+
gemfile: activerecord_8.1
|
|
35
|
+
env:
|
|
36
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
|
37
|
+
steps:
|
|
38
|
+
- uses: actions/checkout@v4
|
|
39
|
+
- name: Set up Ruby
|
|
40
|
+
uses: ruby/setup-ruby@v1
|
|
41
|
+
with:
|
|
42
|
+
ruby-version: ${{ matrix.ruby_version }}
|
|
43
|
+
bundler-cache: true
|
|
44
|
+
- name: Run tests
|
|
45
|
+
run: bundle exec rspec
|
|
46
|
+
- name: Coveralls
|
|
47
|
+
uses: coverallsapp/github-action@master
|
|
48
|
+
with:
|
|
49
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
name: Rubocop
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ master ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ master ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- name: Set up Ruby
|
|
15
|
+
uses: ruby/setup-ruby@v1
|
|
16
|
+
with:
|
|
17
|
+
ruby-version: 3.0
|
|
18
|
+
bundler-cache: true
|
|
19
|
+
- name: Run Rubocop
|
|
20
|
+
run: bundle exec rubocop -d
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
- rubocop-rake
|
|
4
|
+
|
|
5
|
+
inherit_from: .rubocop_todo.yml
|
|
6
|
+
|
|
1
7
|
AllCops:
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Max: 99
|
|
8
|
-
Style/FileName:
|
|
8
|
+
TargetRubyVersion: 2.7
|
|
9
|
+
NewCops: enable
|
|
10
|
+
Layout/LineLength:
|
|
11
|
+
Max: 120
|
|
12
|
+
Naming/FileName:
|
|
9
13
|
Enabled: false
|
|
10
14
|
Style/ModuleFunction:
|
|
11
15
|
Enabled: false
|
|
12
16
|
Style/Encoding:
|
|
13
17
|
Enabled: false
|
|
14
|
-
Documentation:
|
|
18
|
+
Style/Documentation:
|
|
15
19
|
Enabled: false
|
|
16
20
|
Metrics/MethodLength:
|
|
17
21
|
Max: 15
|
data/.rubocop_todo.yml
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2025-12-14 18:27:46 UTC using RuboCop version 1.71.2.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
11
|
+
# Configuration parameters: Severity, Include.
|
|
12
|
+
# Include: **/*.gemspec
|
|
13
|
+
Gemspec/DeprecatedAttributeAssignment:
|
|
14
|
+
Exclude:
|
|
15
|
+
- 'amoeba.gemspec'
|
|
16
|
+
|
|
17
|
+
# Offense count: 7
|
|
18
|
+
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
|
|
19
|
+
# SupportedStyles: Gemfile, gems.rb, gemspec
|
|
20
|
+
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
|
|
21
|
+
Gemspec/DevelopmentDependencies:
|
|
22
|
+
Exclude:
|
|
23
|
+
- 'amoeba.gemspec'
|
|
24
|
+
|
|
25
|
+
# Offense count: 1
|
|
26
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
27
|
+
# Configuration parameters: Severity, Include.
|
|
28
|
+
# Include: **/*.gemspec
|
|
29
|
+
Gemspec/RequireMFA:
|
|
30
|
+
Exclude:
|
|
31
|
+
- 'amoeba.gemspec'
|
|
32
|
+
|
|
33
|
+
# Offense count: 1
|
|
34
|
+
# Configuration parameters: Severity, Include.
|
|
35
|
+
# Include: **/*.gemspec
|
|
36
|
+
Gemspec/RequiredRubyVersion:
|
|
37
|
+
Exclude:
|
|
38
|
+
- 'amoeba.gemspec'
|
|
39
|
+
|
|
40
|
+
# Offense count: 1
|
|
41
|
+
# Configuration parameters: AllowedParentClasses.
|
|
42
|
+
Lint/MissingSuper:
|
|
43
|
+
Exclude:
|
|
44
|
+
- 'lib/amoeba/macros/base.rb'
|
|
45
|
+
|
|
46
|
+
# Offense count: 17
|
|
47
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
48
|
+
# Configuration parameters: AutoCorrect.
|
|
49
|
+
Lint/UselessAssignment:
|
|
50
|
+
Exclude:
|
|
51
|
+
- 'spec/support/data.rb'
|
|
52
|
+
|
|
53
|
+
# Offense count: 2
|
|
54
|
+
# Configuration parameters: CountComments, CountAsOne.
|
|
55
|
+
Metrics/ClassLength:
|
|
56
|
+
Max: 130
|
|
57
|
+
|
|
58
|
+
# Offense count: 3
|
|
59
|
+
# Configuration parameters: ForbiddenDelimiters.
|
|
60
|
+
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
|
|
61
|
+
Naming/HeredocDelimiterNaming:
|
|
62
|
+
Exclude:
|
|
63
|
+
- 'lib/amoeba/config.rb'
|
|
64
|
+
|
|
65
|
+
# Offense count: 2
|
|
66
|
+
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
|
|
67
|
+
# SupportedStyles: snake_case, normalcase, non_integer
|
|
68
|
+
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
|
|
69
|
+
Naming/VariableNumber:
|
|
70
|
+
Exclude:
|
|
71
|
+
- 'spec/support/data.rb'
|
|
72
|
+
|
|
73
|
+
# Offense count: 1
|
|
74
|
+
RSpec/BeforeAfterAll:
|
|
75
|
+
Exclude:
|
|
76
|
+
- '**/spec/spec_helper.rb'
|
|
77
|
+
- '**/spec/rails_helper.rb'
|
|
78
|
+
- '**/spec/support/**/*.rb'
|
|
79
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
80
|
+
|
|
81
|
+
# Offense count: 12
|
|
82
|
+
# Configuration parameters: Prefixes, AllowedPatterns.
|
|
83
|
+
# Prefixes: when, with, without
|
|
84
|
+
RSpec/ContextWording:
|
|
85
|
+
Exclude:
|
|
86
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
87
|
+
|
|
88
|
+
# Offense count: 1
|
|
89
|
+
# Configuration parameters: IgnoredMetadata.
|
|
90
|
+
RSpec/DescribeClass:
|
|
91
|
+
Exclude:
|
|
92
|
+
- '**/spec/features/**/*'
|
|
93
|
+
- '**/spec/requests/**/*'
|
|
94
|
+
- '**/spec/routing/**/*'
|
|
95
|
+
- '**/spec/system/**/*'
|
|
96
|
+
- '**/spec/views/**/*'
|
|
97
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
98
|
+
|
|
99
|
+
# Offense count: 2
|
|
100
|
+
# Configuration parameters: CountAsOne.
|
|
101
|
+
RSpec/ExampleLength:
|
|
102
|
+
Max: 29
|
|
103
|
+
|
|
104
|
+
# Offense count: 1
|
|
105
|
+
# Configuration parameters: .
|
|
106
|
+
# SupportedStyles: have_received, receive
|
|
107
|
+
RSpec/MessageSpies:
|
|
108
|
+
EnforcedStyle: receive
|
|
109
|
+
|
|
110
|
+
# Offense count: 6
|
|
111
|
+
RSpec/MultipleExpectations:
|
|
112
|
+
Max: 17
|
|
113
|
+
|
|
114
|
+
# Offense count: 18
|
|
115
|
+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
|
|
116
|
+
# SupportedStyles: always, named_only
|
|
117
|
+
RSpec/NamedSubject:
|
|
118
|
+
Exclude:
|
|
119
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
120
|
+
|
|
121
|
+
# Offense count: 3
|
|
122
|
+
# Configuration parameters: AllowedGroups.
|
|
123
|
+
RSpec/NestedGroups:
|
|
124
|
+
Max: 4
|
|
125
|
+
|
|
126
|
+
# Offense count: 1
|
|
127
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
128
|
+
# Configuration parameters: Strict, EnforcedStyle, AllowedExplicitMatchers.
|
|
129
|
+
# SupportedStyles: inflected, explicit
|
|
130
|
+
RSpec/PredicateMatcher:
|
|
131
|
+
Exclude:
|
|
132
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
133
|
+
|
|
134
|
+
# Offense count: 25
|
|
135
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
136
|
+
Style/RedundantConstantBase:
|
|
137
|
+
Exclude:
|
|
138
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
139
|
+
- 'spec/spec_helper.rb'
|
|
140
|
+
- 'spec/support/models.rb'
|
|
141
|
+
|
|
142
|
+
# Offense count: 5
|
|
143
|
+
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
144
|
+
# Configuration parameters: Mode.
|
|
145
|
+
Style/StringConcatenation:
|
|
146
|
+
Exclude:
|
|
147
|
+
- 'spec/lib/amoeba_spec.rb'
|
|
148
|
+
- 'spec/spec_helper.rb'
|
|
149
|
+
- 'spec/support/models.rb'
|
data/Appraisals
CHANGED
|
@@ -1,76 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
gem 'activerecord', '~> 4.2.0'
|
|
3
|
-
group :development, :test do
|
|
4
|
-
gem "sqlite3", "~> 1.3.0"
|
|
5
|
-
end
|
|
6
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
7
2
|
|
|
8
|
-
appraise 'activerecord-
|
|
9
|
-
gem 'activerecord', '~>
|
|
3
|
+
appraise 'activerecord-6.1' do
|
|
4
|
+
gem 'activerecord', '~> 6.1.0'
|
|
5
|
+
gem 'concurrent-ruby', '<= 1.3.4'
|
|
6
|
+
gem 'mutex_m'
|
|
7
|
+
gem 'base64'
|
|
8
|
+
gem 'bigdecimal'
|
|
9
|
+
gem 'logger'
|
|
10
|
+
gem 'benchmark'
|
|
10
11
|
group :development, :test do
|
|
11
|
-
gem
|
|
12
|
+
gem 'sqlite3', '~> 1.6.0'
|
|
12
13
|
end
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
appraise 'activerecord-
|
|
16
|
-
gem 'activerecord', '~>
|
|
16
|
+
appraise 'activerecord-7.0' do
|
|
17
|
+
gem 'activerecord', '~> 7.0.0'
|
|
18
|
+
gem 'concurrent-ruby', '<= 1.3.4'
|
|
17
19
|
group :development, :test do
|
|
18
|
-
gem
|
|
20
|
+
gem 'sqlite3', '~> 1.6.0'
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
|
|
22
|
-
appraise 'activerecord-
|
|
23
|
-
gem 'activerecord', '~>
|
|
24
|
+
appraise 'activerecord-7.1' do
|
|
25
|
+
gem 'activerecord', '~> 7.1.0'
|
|
24
26
|
group :development, :test do
|
|
25
|
-
gem
|
|
27
|
+
gem 'sqlite3', '~> 1.6.0'
|
|
26
28
|
end
|
|
27
29
|
end
|
|
28
30
|
|
|
29
|
-
appraise 'activerecord-
|
|
30
|
-
gem 'activerecord', '~>
|
|
31
|
+
appraise 'activerecord-8.0' do
|
|
32
|
+
gem 'activerecord', '~> 8.0.0'
|
|
31
33
|
group :development, :test do
|
|
32
|
-
gem
|
|
34
|
+
gem 'sqlite3', '~> 2.1.0'
|
|
33
35
|
end
|
|
34
36
|
end
|
|
35
37
|
|
|
36
|
-
appraise 'activerecord-
|
|
37
|
-
gem 'activerecord', '~>
|
|
38
|
+
appraise 'activerecord-8.1' do
|
|
39
|
+
gem 'activerecord', '~> 8.1.0'
|
|
38
40
|
group :development, :test do
|
|
39
|
-
gem
|
|
41
|
+
gem 'sqlite3', '~> 2.1.0'
|
|
40
42
|
end
|
|
41
43
|
end
|
|
42
44
|
|
|
43
|
-
appraise 'jruby-activerecord-
|
|
44
|
-
gem 'activerecord', '~>
|
|
45
|
-
group :development, :test do
|
|
46
|
-
gem 'activerecord-jdbc-adapter', '~> 61.0'
|
|
47
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 61.0'
|
|
48
|
-
end
|
|
45
|
+
appraise 'jruby-activerecord-7.0' do
|
|
46
|
+
gem 'activerecord', '~> 7.0.0'
|
|
49
47
|
end
|
|
50
48
|
|
|
51
49
|
appraise 'activerecord-head' do
|
|
52
|
-
git '
|
|
53
|
-
gem 'arel'
|
|
54
|
-
end
|
|
55
|
-
git 'git://github.com/rails/rails.git', branch: 'main' do
|
|
50
|
+
git 'https://github.com/rails/rails.git', branch: 'main' do
|
|
56
51
|
gem 'activerecord'
|
|
57
52
|
end
|
|
58
53
|
group :development, :test do
|
|
59
|
-
gem
|
|
54
|
+
gem 'sqlite3', '~> 2.1.0'
|
|
60
55
|
end
|
|
61
56
|
end
|
|
62
57
|
|
|
63
58
|
appraise 'jruby-activerecord-head' do
|
|
64
|
-
git '
|
|
65
|
-
gem 'arel'
|
|
66
|
-
end
|
|
67
|
-
git 'git://github.com/rails/rails.git', branch: 'main' do
|
|
59
|
+
git 'https://github.com/rails/rails.git', branch: 'main' do
|
|
68
60
|
gem 'activerecord'
|
|
69
61
|
end
|
|
70
62
|
group :development, :test do
|
|
71
|
-
git '
|
|
63
|
+
git 'https://github.com/jruby/activerecord-jdbc-adapter' do
|
|
72
64
|
gem 'activerecord-jdbc-adapter'
|
|
73
|
-
gem 'activerecord-jdbcsqlite3-adapter',
|
|
65
|
+
gem 'activerecord-jdbcsqlite3-adapter',
|
|
66
|
+
glob: 'activerecord-jdbcsqlite3-adapter/activerecord-jdbcsqlite3-adapter.gemspec'
|
|
74
67
|
end
|
|
75
68
|
end
|
|
76
69
|
end
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
### 3.4.0
|
|
2
|
+
|
|
3
|
+
* Update test matrix for current version for Ruby and Rails. Drop support for Rails versions 5.2 and 6.0, and Ruby 2.5, 2.6 and 2.7. [https://github.com/amoeba-rb/amoeba/pull/120 and https://github.com/amoeba-rb/amoeba/pull/124]
|
|
4
|
+
* Notes on contributing. Github Actions for automate tests. [https://github.com/amoeba-rb/amoeba/pull/124]
|
|
5
|
+
* Fix tests for Active Record after 7.1. [https://github.com/amoeba-rb/amoeba/pull/127]
|
|
6
|
+
* Refactor tests. [https://github.com/amoeba-rb/amoeba/pull/130]
|
|
7
|
+
* Allow `nullify` to accept an `:if` condition. `Config#null_fields` is now a Hash of field names to options rather than an Array of field names, for consistency with `includes` and `excludes`; code reading it directly should use `null_fields.keys`. [https://github.com/amoeba-rb/amoeba/pull/134] Thanks @bvicenzo.
|
|
8
|
+
|
|
9
|
+
#### Breaking change
|
|
10
|
+
|
|
11
|
+
Internally the configuration of `null_fields` is now stored as a `Hash` instead of an `Array`. This could cause failures if you access the `config` directly. For example;
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
# test.rb
|
|
15
|
+
require_relative 'config/environment'
|
|
16
|
+
|
|
17
|
+
class Post < ActiveRecord::Base
|
|
18
|
+
amoeba do
|
|
19
|
+
enable
|
|
20
|
+
nullify :topic_id
|
|
21
|
+
nullify :likes
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
config = Post.amoeba
|
|
26
|
+
|
|
27
|
+
pp config.null_fields
|
|
28
|
+
pp config.null_fields.first
|
|
29
|
+
pp config.null_fields.map(&:to_s)
|
|
30
|
+
pp config.null_fields << :extra
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
With previous versions of `amoeba` the output of this will be;
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
[:topic_id, :likes]
|
|
37
|
+
:topic_id
|
|
38
|
+
["topic_id", "likes"]
|
|
39
|
+
[:topic_id, :likes, :extra]
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
With the new version of `amoeba` some of these command execute successfully with changed output and the final line fails with an exception;
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
{topic_id: {}, likes: {}}
|
|
46
|
+
[:topic_id, {}]
|
|
47
|
+
["[:topic_id, {}]", "[:likes, {}]"]
|
|
48
|
+
test.rb:18:in '<main>': undefined method '<<' for an instance of Hash (NoMethodError)
|
|
49
|
+
|
|
50
|
+
pp config.null_fields << :extra
|
|
51
|
+
^^
|
|
52
|
+
Did you mean? <
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 3.3.0
|
|
56
|
+
|
|
57
|
+
* Move test pipelines from Travis to Github Actions.
|
|
58
|
+
* `include_field` and `exclude_field` configuration options have been removed.
|
|
59
|
+
These had been marked as deprecated in version 2 and replaced by
|
|
60
|
+
`include_association` and `exclude_association`.
|
|
61
|
+
* Official support dropped for Rails 5.1 and earlier. Test pipelines now run
|
|
62
|
+
for Rails 5.2 up to 7.0 as well as the current development head.
|
|
63
|
+
* Official support dropped for Ruby 2.4 and earlier. Test pipelines now run for
|
|
64
|
+
Ruby 2.5 up to 3.2 as well as the current development head.
|
|
65
|
+
* Ambiguous 'BSD' license replaced with 'BSD 2-Claus "Simplified" License'.
|
|
66
|
+
* Fix copy-and-paste mistake in documenation. Thanks @budu.
|
|
67
|
+
* Use lazy load hooks to extend ActiveRecord::Base. This is to ensure
|
|
68
|
+
compatibility with Factory Bot Rails 6.4.0. Thanks @tagliala.
|
data/Gemfile
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
source 'https://rubygems.org'
|
|
2
4
|
gemspec
|
|
3
5
|
|
|
4
6
|
group :development, :test do
|
|
5
7
|
gem 'rake'
|
|
6
|
-
gem '
|
|
8
|
+
gem 'simplecov', '~> 0.21.2'
|
|
9
|
+
gem 'simplecov-lcov', '~> 0.8.0'
|
|
10
|
+
gem 'sqlite3', '~> 1.6'
|
|
7
11
|
end
|
|
8
12
|
|
|
9
13
|
group :local_development do
|
|
10
|
-
gem 'pry'
|
|
11
14
|
gem 'appraisal'
|
|
15
|
+
gem 'pry'
|
|
12
16
|
end
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
[The 2-Clause BSD License](http://www.opensource.org/licenses/bsd-license.php)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2012, Vaughn Draughon
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
10
|
+
|
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
|
@@ -6,6 +6,10 @@ Easy cloning of active_record objects including associations and several operati
|
|
|
6
6
|
[](http://badge.fury.io/rb/amoeba)
|
|
7
7
|
[](https://travis-ci.org/amoeba-rb/amoeba)
|
|
8
8
|
|
|
9
|
+
## Interested in contributing?
|
|
10
|
+
|
|
11
|
+
See [here.](docs/contributing.md)
|
|
12
|
+
|
|
9
13
|
## What?
|
|
10
14
|
|
|
11
15
|
The goal was to be able to easily and quickly reproduce ActiveRecord objects including their children, for example copying a blog post maintaining its associated tags or categories.
|
|
@@ -16,7 +20,7 @@ This gem is named "Amoeba" because amoebas are (small life forms that are) good
|
|
|
16
20
|
|
|
17
21
|
An ActiveRecord extension gem to allow the duplication of associated child record objects when duplicating an active record model.
|
|
18
22
|
|
|
19
|
-
Rails
|
|
23
|
+
Rails 5.2, 6.0, 6.1 compatible. For Rails 4.2 to 5.1 use version 3.x.
|
|
20
24
|
|
|
21
25
|
### Features
|
|
22
26
|
|
|
@@ -336,6 +340,25 @@ This example will copy all of a post's comments. It will also nullify the publis
|
|
|
336
340
|
|
|
337
341
|
Unlike inclusive and exclusive styles, specifying null fields will not automatically enable amoeba to copy all child records. As with any active record object, the default field value will be used instead of `nil` if a default value exists on the migration.
|
|
338
342
|
|
|
343
|
+
A field may also be nullified only under a given condition, by passing the name of a method on the source record to the `:if` option, just like the [conditions](#conditions) available for `include_association` and `exclude_association`:
|
|
344
|
+
|
|
345
|
+
```ruby
|
|
346
|
+
class Post < ActiveRecord::Base
|
|
347
|
+
belongs_to :topic
|
|
348
|
+
|
|
349
|
+
amoeba do
|
|
350
|
+
nullify :date_published
|
|
351
|
+
nullify :topic_id, if: :popular?
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
def popular?
|
|
355
|
+
likes > 15
|
|
356
|
+
end
|
|
357
|
+
end
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Here `date_published` is always nullified, while `topic_id` is only nullified when `popular?` returns a truthy value on the post being copied. The `:if` option accepts a method name only.
|
|
361
|
+
|
|
339
362
|
#### Set
|
|
340
363
|
|
|
341
364
|
If you wish to just set a field to an arbitrary value on all duplicated objects you may use the `set` directive. For example, if you wanted to copy an object that has some kind of approval process associated with it, you likely may wish to set the new object's state to be open or "in progress" again.
|
|
@@ -984,7 +1007,7 @@ After cloning we will get instance of `Child` instead of `ChildPrototype`
|
|
|
984
1007
|
|
|
985
1008
|
## Remapping associations
|
|
986
1009
|
|
|
987
|
-
If you will need to do complex cloning with remapping associations name you can
|
|
1010
|
+
If you will need to do complex cloning with remapping associations name you can use `remapper`:
|
|
988
1011
|
|
|
989
1012
|
```ruby
|
|
990
1013
|
class ObjectPrototype < ActiveRecord::Base
|
|
@@ -1125,13 +1148,15 @@ end
|
|
|
1125
1148
|
|
|
1126
1149
|
Adds a field to the list of non-association based fields which should be set to nil during copy. All fields in this list will be set to `nil` - note that any nullified field will be given its default value if a default value exists on this model's migration. This method may be called multiple times, once per desired field, or you may pass an array of field names. Passing a single symbol will add to the list of null fields. Passing an array will empty the list and replace it with the array you pass.
|
|
1127
1150
|
|
|
1151
|
+
Accepts an `:if` option, taking the name of a method that is called on the record being copied. The field is only nullified when that method returns a truthy value, e.g. `nullify :topic_id, if: :popular?`. When an array of field names is given, the condition applies to every field in the array. Declaring the same field again without `:if` clears a condition previously set on it.
|
|
1152
|
+
|
|
1128
1153
|
#### prepend
|
|
1129
1154
|
|
|
1130
1155
|
Prefix a field with some text. This only works for string fields. Accepts a hash of fields to prepend. The keys are the field names and the values are the prefix strings. An example scenario would be to add a string such as "Copy of " to your title field. Don't forget to include extra space to the right if you want it. Passing a hash will add each key value pair to the list of prepend directives. If you wish to empty the list of directives, you may pass the hash inside of an array like this `[{:title => "Copy of "}]`.
|
|
1131
1156
|
|
|
1132
1157
|
#### append
|
|
1133
1158
|
|
|
1134
|
-
Append some text to a field. This only works for string fields. Accepts a hash of fields to
|
|
1159
|
+
Append some text to a field. This only works for string fields. Accepts a hash of fields to append. The keys are the field names and the values are the prefix strings. An example would be to add " (copied version)" to your description field. Don't forget to add a leading space if you want it. Passing a hash will add each key value pair to the list of append directives. If you wish to empty the list of directives, you may pass the hash inside of an array like this `[{:contents => " (copied version)"}]`.
|
|
1135
1160
|
|
|
1136
1161
|
#### set
|
|
1137
1162
|
|
|
@@ -1173,17 +1198,3 @@ bundle exec rspec spec
|
|
|
1173
1198
|
|
|
1174
1199
|
* add ability to cancel further processing from within an override block
|
|
1175
1200
|
* write some spec for the override method
|
|
1176
|
-
|
|
1177
|
-
## License
|
|
1178
|
-
|
|
1179
|
-
[The BSD License](http://www.opensource.org/licenses/bsd-license.php)
|
|
1180
|
-
|
|
1181
|
-
Copyright (c) 2012, Vaughn Draughon
|
|
1182
|
-
All rights reserved.
|
|
1183
|
-
|
|
1184
|
-
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
1185
|
-
|
|
1186
|
-
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
1187
|
-
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
1188
|
-
|
|
1189
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|