amoeba 3.1.0 → 3.3.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.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/jruby.yml +27 -0
  3. data/.github/workflows/ruby_25.yml +30 -0
  4. data/.github/workflows/ruby_26.yml +30 -0
  5. data/.github/workflows/ruby_27.yml +30 -0
  6. data/.github/workflows/ruby_30.yml +34 -0
  7. data/.github/workflows/ruby_31.yml +34 -0
  8. data/.github/workflows/ruby_32.yml +34 -0
  9. data/.github/workflows/ruby_head.yml +34 -0
  10. data/.gitignore +1 -0
  11. data/.rubocop.yml +11 -7
  12. data/.rubocop_todo.yml +120 -0
  13. data/Appraisals +48 -9
  14. data/CHANGELOG.md +14 -0
  15. data/Gemfile +5 -2
  16. data/LICENSE.md +11 -0
  17. data/README.md +3 -17
  18. data/Rakefile +2 -0
  19. data/amoeba.gemspec +20 -17
  20. data/gemfiles/activerecord_5.2.gemfile +19 -0
  21. data/gemfiles/activerecord_6.0.gemfile +19 -0
  22. data/gemfiles/activerecord_6.1.gemfile +19 -0
  23. data/gemfiles/activerecord_7.0.gemfile +19 -0
  24. data/gemfiles/activerecord_head.gemfile +10 -12
  25. data/gemfiles/jruby_activerecord_7.0.gemfile +20 -0
  26. data/gemfiles/jruby_activerecord_head.gemfile +26 -0
  27. data/lib/amoeba/class_methods.rb +2 -0
  28. data/lib/amoeba/cloner.rb +11 -4
  29. data/lib/amoeba/config.rb +25 -51
  30. data/lib/amoeba/instance_methods.rb +3 -0
  31. data/lib/amoeba/macros/base.rb +4 -1
  32. data/lib/amoeba/macros/has_and_belongs_to_many.rb +2 -0
  33. data/lib/amoeba/macros/has_many.rb +2 -0
  34. data/lib/amoeba/macros/has_one.rb +4 -0
  35. data/lib/amoeba/macros.rb +2 -0
  36. data/lib/amoeba/version.rb +3 -1
  37. data/lib/amoeba.rb +6 -2
  38. data/spec/lib/amoeba_spec.rb +76 -34
  39. data/spec/spec_helper.rb +13 -5
  40. data/spec/support/data.rb +22 -15
  41. data/spec/support/models.rb +39 -38
  42. metadata +66 -30
  43. data/.travis.yml +0 -20
  44. data/gemfiles/activerecord_4.0.gemfile +0 -17
  45. data/gemfiles/activerecord_4.1.gemfile +0 -17
  46. data/gemfiles/activerecord_4.2.gemfile +0 -17
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,21 @@
1
1
  require 'simplecov'
2
- require 'coveralls'
3
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
- SimpleCov::Formatter::HTMLFormatter,
5
- Coveralls::SimpleCov::Formatter
6
- ]
2
+
7
3
  SimpleCov.start do
8
4
  add_filter 'spec'
9
5
  minimum_coverage(76)
6
+
7
+ if ENV['CI']
8
+ require 'simplecov-lcov'
9
+
10
+ SimpleCov::Formatter::LcovFormatter.config do |c|
11
+ c.report_with_single_file = true
12
+ c.single_report_path = 'coverage/lcov.info'
13
+ end
14
+
15
+ formatter SimpleCov::Formatter::LcovFormatter
16
+ end
10
17
  end
18
+
11
19
  require 'active_record'
12
20
  require 'amoeba'
13
21
 
data/spec/support/data.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  u1 = User.create(name: 'Robert Johnson', email: 'bob@crossroads.com')
3
2
  u2 = User.create(name: 'Miles Davis', email: 'miles@kindofblue.com')
4
3
 
@@ -8,7 +7,8 @@ a2 = Author.create(full_name: 'Arthur Sees Clarck', nickname: 'strangewater')
8
7
  t = Topic.create(title: 'Ponies', description: 'Lets talk about my ponies.')
9
8
 
10
9
  # First Post {{{
11
- p1 = t.posts.create(owner: u1, author: a1, title: 'My little pony', contents: 'Lorum ipsum dolor rainbow bright. I like dogs, dogs are awesome.')
10
+ p1 = t.posts.create(owner: u1, author: a1, title: 'My little pony',
11
+ contents: 'Lorum ipsum dolor rainbow bright. I like dogs, dogs are awesome.')
12
12
  f1 = p1.create_post_config(is_visible: true, is_open: false, password: 'abcdefg123')
13
13
  a1 = p1.create_account(title: 'Foo')
14
14
  h1 = p1.account.create_history(some_stuff: 'Bar')
@@ -21,11 +21,15 @@ c2 = p1.comments.create(contents: 'I hate it!', nerf: 'whapaow')
21
21
  c3 = p1.comments.create(contents: 'kthxbbq!!11!!!1!eleven!!', nerf: 'bonk')
22
22
  [0, 0, 1, 2, 1, 0].each { |stars| c3.ratings.create(num_stars: stars) }
23
23
 
24
- %w(funny wtf cats).each { |value| p1.tags << Tag.create(value: value) }
24
+ %w[funny wtf cats].each { |value| p1.tags << Tag.create(value: value) }
25
25
 
26
- ['My Sidebar', 'Photo Gallery', 'Share & Like'].each { |value| p1.widgets << Widget.create(value: value) }
26
+ ['My Sidebar', 'Photo Gallery', 'Share & Like'].each do |value|
27
+ p1.widgets << Widget.create(value: value)
28
+ end
27
29
 
28
- ['This is important', "You've been warned", "Don't forget"].each { |value| p1.notes << Note.create(value: value) }
30
+ ['This is important', "You've been warned", "Don't forget"].each do |value|
31
+ p1.notes << Note.create(value: value)
32
+ end
29
33
 
30
34
  p1.save
31
35
 
@@ -85,15 +89,18 @@ necklace1.sections << jewelry
85
89
  necklace1.sections << accessories
86
90
  necklace1.save
87
91
 
88
-
89
- company = Company.create(name:'ABC Industries')
90
- employee = company.employees.create(name:'Joe',ssn:'1111111111',salary:10000.0)
91
- employee_address = employee.addresses.create(street: '123 My Street',unit:'103',city:'Hollywood',state:'CA',zip:'90210')
92
- employee_address_2 = employee.addresses.create(street: '124 My Street',unit:'103',city:'Follywood',state:'CA',zip:'90210')
93
- employee_photo = employee.photos.create(name: 'Portrait', size: 12345)
94
- customer = company.customers.create(email:'my@email.address',password:'password')
95
- customer_address = customer.addresses.create(street: '321 My Street',unit:'301',city:'Bollywood',state:'IN',zip:'11111')
96
- customer_address_2 = customer.addresses.create(street: '321 My Drive',unit:'311',city:'Mollywood',state:'IN',zip:'21111')
97
- customer_photo = customer.photos.create(name: 'Mug Shot', size: 54321)
92
+ company = Company.create(name: 'ABC Industries')
93
+ employee = company.employees.create(name: 'Joe', ssn: '1111111111', salary: 10_000.0)
94
+ employee_address = employee.addresses.create(street: '123 My Street', unit: '103', city: 'Hollywood',
95
+ state: 'CA', zip: '90210')
96
+ employee_address_2 = employee.addresses.create(street: '124 My Street', unit: '103', city: 'Follywood',
97
+ state: 'CA', zip: '90210')
98
+ employee_photo = employee.photos.create(name: 'Portrait', size: 12_345)
99
+ customer = company.customers.create(email: 'my@email.address', password: 'password')
100
+ customer_address = customer.addresses.create(street: '321 My Street', unit: '301', city: 'Bollywood',
101
+ state: 'IN', zip: '11111')
102
+ customer_address_2 = customer.addresses.create(street: '321 My Drive', unit: '311', city: 'Mollywood',
103
+ state: 'IN', zip: '21111')
104
+ customer_photo = customer.photos.create(name: 'Mug Shot', size: 54_321)
98
105
 
99
106
  # }}}
@@ -34,41 +34,41 @@ class Post < ActiveRecord::Base
34
34
 
35
35
  amoeba do
36
36
  enable
37
- clone [:widgets, :notes]
37
+ clone %i[widgets notes]
38
38
  prepend title: 'Copy of '
39
39
  append contents: ' (copied version)'
40
40
  regex contents: { replace: /dog/, with: 'cat' }
41
41
  customize([
42
- lambda do |orig_obj, copy_of_obj|
43
- orig_obj.comments.each do |oc|
44
- if oc.nerf == 'ratatat'
45
- hash = oc.attributes
46
- hash[:id] = nil
47
- hash[:post_id] = nil
48
- hash[:contents] = nil
49
-
50
- cc = Comment.new(hash)
51
-
52
- copy_of_obj.comments << cc
53
- end
54
- end
55
- end,
56
- lambda do |orig_obj, copy_of_obj|
57
- orig_obj.comments.each do |oc|
58
- if oc.nerf == 'bonk'
59
- hash = oc.attributes
60
- hash[:id] = nil
61
- hash[:post_id] = nil
62
- hash[:contents] = nil
63
- hash[:nerf] = 'bonkers'
64
-
65
- cc = Comment.new(hash)
66
-
67
- copy_of_obj.comments << cc
68
- end
69
- end
70
- end
71
- ])
42
+ lambda do |orig_obj, copy_of_obj|
43
+ orig_obj.comments.each do |oc|
44
+ next unless oc.nerf == 'ratatat'
45
+
46
+ hash = oc.attributes
47
+ hash[:id] = nil
48
+ hash[:post_id] = nil
49
+ hash[:contents] = nil
50
+
51
+ cc = Comment.new(hash)
52
+
53
+ copy_of_obj.comments << cc
54
+ end
55
+ end,
56
+ lambda do |orig_obj, copy_of_obj|
57
+ orig_obj.comments.each do |oc|
58
+ next unless oc.nerf == 'bonk'
59
+
60
+ hash = oc.attributes
61
+ hash[:id] = nil
62
+ hash[:post_id] = nil
63
+ hash[:contents] = nil
64
+ hash[:nerf] = 'bonkers'
65
+
66
+ cc = Comment.new(hash)
67
+
68
+ copy_of_obj.comments << cc
69
+ end
70
+ end
71
+ ])
72
72
  end
73
73
 
74
74
  def truthy?
@@ -97,11 +97,13 @@ class CustomThing < ActiveRecord::Base
97
97
  def self.load(str)
98
98
  return [] unless str.present?
99
99
  return str if str.is_a?(Array)
100
+
100
101
  str.split(',').map(&:to_i)
101
102
  end
102
103
 
103
104
  def self.dump(int_array)
104
105
  return '' unless int_array.present?
106
+
105
107
  int_array.join(',')
106
108
  end
107
109
  end
@@ -261,7 +263,7 @@ class Photo < ActiveRecord::Base
261
263
  belongs_to :imageable, polymorphic: true
262
264
 
263
265
  amoeba do
264
- customize(lambda { |original_photo,new_photo|
266
+ customize(lambda { |original_photo, new_photo|
265
267
  new_photo.name = original_photo.name.to_s + ' Copy'
266
268
  })
267
269
  end
@@ -273,7 +275,7 @@ class Company < ActiveRecord::Base
273
275
 
274
276
  amoeba do
275
277
  include_associations :employees,
276
- :customers
278
+ :customers
277
279
  end
278
280
  end
279
281
 
@@ -283,9 +285,8 @@ class Employee < ActiveRecord::Base
283
285
  belongs_to :company
284
286
 
285
287
  amoeba do
286
- include_associations [:addresses, :photos]
288
+ include_associations %i[addresses photos]
287
289
  end
288
-
289
290
  end
290
291
 
291
292
  class Customer < ActiveRecord::Base
@@ -313,7 +314,7 @@ class ObjectPrototype < MetalObject
313
314
  end
314
315
 
315
316
  def become_real
316
- self.dup.becomes RealObject
317
+ dup.becomes RealObject
317
318
  end
318
319
 
319
320
  def remap_subobjects(relation_name)
@@ -332,7 +333,7 @@ class SubobjectPrototype < MetalObject
332
333
  end
333
334
 
334
335
  def become_subobject
335
- self.dup.becomes Subobject
336
+ dup.becomes Subobject
336
337
  end
337
338
  end
338
339
 
@@ -360,7 +361,7 @@ class Box < ActiveRecord::Base
360
361
  end
361
362
 
362
363
  class BoxProduct < ActiveRecord::Base
363
- belongs_to :box, class_name: 'Box'
364
+ belongs_to :box, class_name: 'Box'
364
365
 
365
366
  amoeba do
366
367
  enable
metadata CHANGED
@@ -1,95 +1,137 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amoeba
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vaughn Draughon
8
+ - Oleksandr Simonov
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2017-04-22 00:00:00.000000000 Z
12
+ date: 2023-09-30 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
+ name: rspec
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: 1.6.0
20
+ version: 3.0.0
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
25
  - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: 1.6.0
27
+ version: 3.0.0
27
28
  - !ruby/object:Gem::Dependency
28
- name: rspec
29
+ name: rubocop
29
30
  requirement: !ruby/object:Gem::Requirement
30
31
  requirements:
31
- - - ">="
32
+ - - "~>"
32
33
  - !ruby/object:Gem::Version
33
- version: 3.0.0
34
+ version: '1.16'
34
35
  type: :development
35
36
  prerelease: false
36
37
  version_requirements: !ruby/object:Gem::Requirement
37
38
  requirements:
38
- - - ">="
39
+ - - "~>"
39
40
  - !ruby/object:Gem::Version
40
- version: 3.0.0
41
+ version: '1.16'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rubocop-rake
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '0.6'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '0.6'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop-rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '2.4'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.4'
41
70
  - !ruby/object:Gem::Dependency
42
71
  name: sqlite3
43
72
  requirement: !ruby/object:Gem::Requirement
44
73
  requirements:
45
74
  - - ">="
46
75
  - !ruby/object:Gem::Version
47
- version: '0'
76
+ version: '1.3'
48
77
  type: :development
49
78
  prerelease: false
50
79
  version_requirements: !ruby/object:Gem::Requirement
51
80
  requirements:
52
81
  - - ">="
53
82
  - !ruby/object:Gem::Version
54
- version: '0'
83
+ version: '1.3'
55
84
  - !ruby/object:Gem::Dependency
56
85
  name: activerecord
57
86
  requirement: !ruby/object:Gem::Requirement
58
87
  requirements:
59
88
  - - ">="
60
89
  - !ruby/object:Gem::Version
61
- version: 3.2.6
90
+ version: 5.2.0
62
91
  type: :runtime
63
92
  prerelease: false
64
93
  version_requirements: !ruby/object:Gem::Requirement
65
94
  requirements:
66
95
  - - ">="
67
96
  - !ruby/object:Gem::Version
68
- version: 3.2.6
97
+ version: 5.2.0
69
98
  description: |
70
99
  An extension to ActiveRecord to allow the duplication method to also copy associated children, with recursive support for nested of grandchildren. The behavior is controllable with a simple DSL both on your rails models and on the fly, i.e. per instance. Numerous configuration styles and preprocessing directives are included for power and flexibility. Supports preprocessing of field values to prepend strings such as "Copy of ", to nullify or process field values with regular expressions. Supports most association types including has_one :through and has_many :through.
71
100
 
72
101
  Tags: copy child associations, copy nested children, copy associated child records, nested copy, copy associations, copy relations, copy relationships, duplicate associations, duplicate associated records, duplicate child records, duplicate children, copy all, duplicate all, clone child associations, clone nested children, clone associated child records, nested clone, clone associations, clone relations, clone relationships, cloning child associations, cloning nested children, cloning associated child records, deep_cloning, nested cloning, cloning associations, cloning relations, cloning relationships, cloning child associations, cloning nested children, cloning associated child records, nested cloning, cloning associations, cloning relations, cloning relationships, cloning child associations, cloning nested children, cloning associated child records, deep_cloning, nested cloning, cloning associations, cloning relations, cloning relationships, duplicate child associations, duplicate nested children, duplicate associated child records, nested duplicate, duplicate associations, duplicate relations, duplicate relationships, duplicate child associations, duplicate nested children, duplicate associated child records, deep_duplicate, nested duplicate, duplicate associations, duplicate relations, duplicate relationships, deep_copy, deep_clone, deep_cloning, deep clone, deep cloning, has_one, has_many, has_and_belongs_to_many
73
- email: vaughn@rocksolidwebdesign.com
102
+ email: alex@simonov.me
74
103
  executables: []
75
104
  extensions: []
76
105
  extra_rdoc_files: []
77
106
  files:
78
107
  - ".cane"
108
+ - ".github/workflows/jruby.yml"
109
+ - ".github/workflows/ruby_25.yml"
110
+ - ".github/workflows/ruby_26.yml"
111
+ - ".github/workflows/ruby_27.yml"
112
+ - ".github/workflows/ruby_30.yml"
113
+ - ".github/workflows/ruby_31.yml"
114
+ - ".github/workflows/ruby_32.yml"
115
+ - ".github/workflows/ruby_head.yml"
79
116
  - ".gitignore"
80
117
  - ".rspec"
81
118
  - ".rubocop.yml"
82
- - ".travis.yml"
119
+ - ".rubocop_todo.yml"
83
120
  - Appraisals
121
+ - CHANGELOG.md
84
122
  - Gemfile
123
+ - LICENSE.md
85
124
  - README.md
86
125
  - Rakefile
87
126
  - amoeba.gemspec
88
127
  - defaults.reek
89
- - gemfiles/activerecord_4.0.gemfile
90
- - gemfiles/activerecord_4.1.gemfile
91
- - gemfiles/activerecord_4.2.gemfile
128
+ - gemfiles/activerecord_5.2.gemfile
129
+ - gemfiles/activerecord_6.0.gemfile
130
+ - gemfiles/activerecord_6.1.gemfile
131
+ - gemfiles/activerecord_7.0.gemfile
92
132
  - gemfiles/activerecord_head.gemfile
133
+ - gemfiles/jruby_activerecord_7.0.gemfile
134
+ - gemfiles/jruby_activerecord_head.gemfile
93
135
  - lib/amoeba.rb
94
136
  - lib/amoeba/class_methods.rb
95
137
  - lib/amoeba/cloner.rb
@@ -106,9 +148,9 @@ files:
106
148
  - spec/support/data.rb
107
149
  - spec/support/models.rb
108
150
  - spec/support/schema.rb
109
- homepage: http://github.com/rocksolidwebdesign/amoeba
151
+ homepage: http://github.com/amoeba-rb/amoeba
110
152
  licenses:
111
- - BSD
153
+ - BSD-2-Clause
112
154
  metadata: {}
113
155
  post_install_message:
114
156
  rdoc_options: []
@@ -118,21 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
118
160
  requirements:
119
161
  - - ">="
120
162
  - !ruby/object:Gem::Version
121
- version: '0'
163
+ version: '2.5'
122
164
  required_rubygems_version: !ruby/object:Gem::Requirement
123
165
  requirements:
124
166
  - - ">="
125
167
  - !ruby/object:Gem::Version
126
168
  version: '0'
127
169
  requirements: []
128
- rubyforge_project: amoeba
129
- rubygems_version: 2.5.1
170
+ rubygems_version: 3.4.10
130
171
  signing_key:
131
172
  specification_version: 4
132
173
  summary: Easy copying of rails models and their child associations.
133
- test_files:
134
- - spec/lib/amoeba_spec.rb
135
- - spec/spec_helper.rb
136
- - spec/support/data.rb
137
- - spec/support/models.rb
138
- - spec/support/schema.rb
174
+ test_files: []
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1
5
- - 2.2
6
- - 2.3
7
- - ruby-head
8
- - jruby-19mode # JRuby in 1.9 mode
9
- - rbx-2
10
- gemfile:
11
- - gemfiles/activerecord_4.0.gemfile
12
- - gemfiles/activerecord_4.1.gemfile
13
- - gemfiles/activerecord_4.2.gemfile
14
- - gemfiles/activerecord_head.gemfile
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-19mode
19
- bundler_args: --without local_development
20
- before_install: gem install bundler
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.0.0"
6
-
7
- group :development, :test do
8
- gem "rake"
9
- gem "coveralls", :require => false
10
- end
11
-
12
- group :local_development do
13
- gem "pry"
14
- gem "appraisal"
15
- end
16
-
17
- gemspec :path => "../"
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.1.0"
6
-
7
- group :development, :test do
8
- gem "rake"
9
- gem "coveralls", :require => false
10
- end
11
-
12
- group :local_development do
13
- gem "pry"
14
- gem "appraisal"
15
- end
16
-
17
- gemspec :path => "../"
@@ -1,17 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "activerecord", "~> 4.2.0"
6
-
7
- group :development, :test do
8
- gem "rake"
9
- gem "coveralls", :require => false
10
- end
11
-
12
- group :local_development do
13
- gem "pry"
14
- gem "appraisal"
15
- end
16
-
17
- gemspec :path => "../"