clowne 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/clowne.gemspec +1 -1
- data/docs/README.md +1 -1
- data/docs/after_persist.md +2 -2
- data/docs/clone_mapper.md +1 -1
- data/docs/finalize.md +2 -2
- data/docs/getting_started.md +1 -1
- data/docs/operation.md +2 -2
- data/docs/parameters.md +3 -3
- data/lib/clowne/adapters/active_record/dsl.rb +2 -2
- data/lib/clowne/adapters/base/association.rb +1 -1
- data/lib/clowne/cloner.rb +2 -2
- data/lib/clowne/declarations.rb +2 -2
- data/lib/clowne/declarations/after_clone.rb +3 -3
- data/lib/clowne/declarations/after_persist.rb +3 -3
- data/lib/clowne/declarations/exclude_association.rb +1 -1
- data/lib/clowne/declarations/finalize.rb +3 -3
- data/lib/clowne/declarations/init_as.rb +3 -3
- data/lib/clowne/declarations/nullify.rb +1 -1
- data/lib/clowne/resolvers/after_persist.rb +1 -1
- data/lib/clowne/resolvers/finalize.rb +1 -1
- data/lib/clowne/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f0d72961e8144605b8f0dbd7953161f17ec4c585c67b3e5bde80d84b3664f1b
|
4
|
+
data.tar.gz: 5981d937f60d54993ab6bee595598dbc0b52ac99e38e29ef84f5007661929c5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd7010d94b67e2f0c9f19d2dbde4b6b302481156be2657199d6d9fa98c142807f1b006ddb306a2fd8cb3b2d72b3fd4e1708e34c5fe3541ddd0b2320b5e63112
|
7
|
+
data.tar.gz: d56c783b4eed7af9ac5e478cfc2b2154b74644ea03fcc84f9fb7bd54c4e2ac8505355bd0ba0405c96255046232f3eee12c83671ef64173f29097ab859a9e428f
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -9,7 +9,7 @@ gem "sqlite3", "~> 1.4.1", platform: :ruby
|
|
9
9
|
gem "activerecord-jdbcsqlite3-adapter", "~> 50.0", platform: :jruby
|
10
10
|
gem "jdbc-sqlite3", platform: :jruby
|
11
11
|
|
12
|
-
gem "activerecord", "
|
12
|
+
gem "activerecord", ">= 6.0", "< 6.2.0"
|
13
13
|
gem "sequel", ">= 5.0"
|
14
14
|
gem "simplecov"
|
15
15
|
|
data/README.md
CHANGED
data/clowne.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
29
29
|
spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
|
30
30
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
-
spec.add_development_dependency 'factory_bot', '~>
|
31
|
+
spec.add_development_dependency 'factory_bot', '~> 5'
|
32
32
|
spec.add_development_dependency 'rubocop', '~> 0.75.0'
|
33
33
|
spec.add_development_dependency 'rubocop-md', '~> 0.3.0'
|
34
34
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.36.0'
|
data/docs/README.md
CHANGED
data/docs/after_persist.md
CHANGED
@@ -30,7 +30,7 @@ class UserCloner < Clowne::Cloner
|
|
30
30
|
|
31
31
|
after_persist do |origin, clone, mapper:, **|
|
32
32
|
cloned_bio = mapper.clone_of(origin.bio)
|
33
|
-
clone.
|
33
|
+
clone.update(bio_id: cloned_bio.id)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
@@ -50,7 +50,7 @@ end
|
|
50
50
|
user = User.create
|
51
51
|
posts = Array.new(3) { Post.create(user: user) }
|
52
52
|
bio = posts.sample
|
53
|
-
user.
|
53
|
+
user.update(bio_id: bio.id)
|
54
54
|
|
55
55
|
operation = UserCloner.call(user, run_job: true)
|
56
56
|
# => <#Clowne::Utils::Operation ...>
|
data/docs/clone_mapper.md
CHANGED
data/docs/finalize.md
CHANGED
@@ -4,12 +4,12 @@ To apply custom transformations to the cloned record, you can use the `finalize`
|
|
4
4
|
|
5
5
|
```ruby
|
6
6
|
class UserCloner < Clowne::Cloner
|
7
|
-
finalize do |_source, record, _params|
|
7
|
+
finalize do |_source, record, **_params|
|
8
8
|
record.name = "This is copy!"
|
9
9
|
end
|
10
10
|
|
11
11
|
trait :change_email do
|
12
|
-
finalize do |_source, record, params|
|
12
|
+
finalize do |_source, record, **params|
|
13
13
|
record.email = params[:email]
|
14
14
|
end
|
15
15
|
end
|
data/docs/getting_started.md
CHANGED
data/docs/operation.md
CHANGED
@@ -11,7 +11,7 @@ class UserCloner < Clowne::Cloner
|
|
11
11
|
nullify :email
|
12
12
|
|
13
13
|
after_persist do |_origin, cloned, **|
|
14
|
-
cloned.
|
14
|
+
cloned.update(email: "evl-#{cloned.id}.ms")
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -34,7 +34,7 @@ operation.to_record
|
|
34
34
|
# Call only after_persist callbacks:
|
35
35
|
user2 = operation.to_record
|
36
36
|
# => <#User id: 2, email: 'evl-2.ms', ...>
|
37
|
-
user2.
|
37
|
+
user2.update(email: "admin@example.com")
|
38
38
|
# => <#User id: 2, email: 'admin@example.com' ...>
|
39
39
|
operation.run_after_persist
|
40
40
|
# => <#User id: 2, email: 'evl-2.ms', ...>
|
data/docs/parameters.md
CHANGED
@@ -8,7 +8,7 @@ Example:
|
|
8
8
|
class UserCloner < Clowne::Cloner
|
9
9
|
include_association :posts, ->(params) { where(state: params[:state]) }
|
10
10
|
|
11
|
-
finalize do |_source, record, params|
|
11
|
+
finalize do |_source, record, **params|
|
12
12
|
record.email = params[:email]
|
13
13
|
end
|
14
14
|
end
|
@@ -27,7 +27,7 @@ As result we strongly recommend to use ruby keyword arguments instead of params
|
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
# Bad
|
30
|
-
finalize do |_source, record, params|
|
30
|
+
finalize do |_source, record, **params|
|
31
31
|
record.email = params[:email]
|
32
32
|
end
|
33
33
|
|
@@ -82,7 +82,7 @@ class UserCloner < Clowne::Cloner
|
|
82
82
|
end
|
83
83
|
|
84
84
|
class ProfileCloner < Clowne::Cloner
|
85
|
-
finalize do |_source, record, params|
|
85
|
+
finalize do |_source, record, **params|
|
86
86
|
record.jsonb_field = params
|
87
87
|
end
|
88
88
|
end
|
@@ -6,8 +6,8 @@ module Clowne
|
|
6
6
|
module ActiveRecordDSL
|
7
7
|
module InstanceMethods # :nodoc:
|
8
8
|
# Shortcut to call class's cloner call with self
|
9
|
-
def clowne(
|
10
|
-
self.class.cloner_class.call(self,
|
9
|
+
def clowne(**args, &block)
|
10
|
+
self.class.cloner_class.call(self, **args, &block)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
data/lib/clowne/cloner.rb
CHANGED
@@ -44,7 +44,7 @@ module Clowne # :nodoc: all
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# rubocop: disable Metrics/AbcSize, Metrics/MethodLength
|
47
|
-
def call(object, **options)
|
47
|
+
def call(object, **options, &block)
|
48
48
|
raise(UnprocessableSourceError, "Nil is not cloneable object") if object.nil?
|
49
49
|
|
50
50
|
options = Clowne::Utils::Options.new(options)
|
@@ -59,7 +59,7 @@ module Clowne # :nodoc: all
|
|
59
59
|
plan_with_traits(options.traits, current_adapter: current_adapter)
|
60
60
|
end
|
61
61
|
|
62
|
-
plan = Clowne::Planner.enhance(plan,
|
62
|
+
plan = Clowne::Planner.enhance(plan, block) if block
|
63
63
|
|
64
64
|
plan = Clowne::Planner.filter_declarations(plan, options.only)
|
65
65
|
|
data/lib/clowne/declarations.rb
CHANGED
@@ -11,8 +11,8 @@ module Clowne
|
|
11
11
|
declaration = block if block_given?
|
12
12
|
|
13
13
|
if declaration.is_a?(Class)
|
14
|
-
DSL.send(:define_method, id) do |*args, &inner_block|
|
15
|
-
declarations.push declaration.new(*args, &inner_block)
|
14
|
+
DSL.send(:define_method, id) do |*args, **hargs, &inner_block|
|
15
|
+
declarations.push declaration.new(*args, **hargs, &inner_block)
|
16
16
|
end
|
17
17
|
elsif declaration.is_a?(Proc)
|
18
18
|
DSL.send(:define_method, id, &declaration)
|
@@ -5,10 +5,10 @@ module Clowne
|
|
5
5
|
class AfterClone < Base # :nodoc: all
|
6
6
|
attr_reader :block
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
raise ArgumentError, "Block is required for after_clone" unless
|
8
|
+
def initialize(*, &block)
|
9
|
+
raise ArgumentError, "Block is required for after_clone" unless block
|
10
10
|
|
11
|
-
@block =
|
11
|
+
@block = block
|
12
12
|
end
|
13
13
|
|
14
14
|
def compile(plan)
|
@@ -5,10 +5,10 @@ module Clowne
|
|
5
5
|
class AfterPersist < Base # :nodoc: all
|
6
6
|
attr_reader :block
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
raise ArgumentError, "Block is required for after_persist" unless
|
8
|
+
def initialize(*, &block)
|
9
|
+
raise ArgumentError, "Block is required for after_persist" unless block
|
10
10
|
|
11
|
-
@block =
|
11
|
+
@block = block
|
12
12
|
end
|
13
13
|
|
14
14
|
def compile(plan)
|
@@ -5,10 +5,10 @@ module Clowne
|
|
5
5
|
class Finalize < Base # :nodoc: all
|
6
6
|
attr_reader :block
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
raise ArgumentError, "Block is required for finalize" unless
|
8
|
+
def initialize(*, &block)
|
9
|
+
raise ArgumentError, "Block is required for finalize" unless block
|
10
10
|
|
11
|
-
@block =
|
11
|
+
@block = block
|
12
12
|
end
|
13
13
|
|
14
14
|
def compile(plan)
|
@@ -5,10 +5,10 @@ module Clowne
|
|
5
5
|
class InitAs < Base # :nodoc: all
|
6
6
|
attr_reader :block
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
raise ArgumentError, "Block is required for init_as" unless
|
8
|
+
def initialize(*, &block)
|
9
|
+
raise ArgumentError, "Block is required for init_as" unless block
|
10
10
|
|
11
|
-
@block =
|
11
|
+
@block = block
|
12
12
|
end
|
13
13
|
|
14
14
|
def compile(plan)
|
data/lib/clowne/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clowne
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-05-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -65,14 +65,14 @@ dependencies:
|
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '5'
|
69
69
|
type: :development
|
70
70
|
prerelease: false
|
71
71
|
version_requirements: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '5'
|
76
76
|
- !ruby/object:Gem::Dependency
|
77
77
|
name: rubocop
|
78
78
|
requirement: !ruby/object:Gem::Requirement
|