clowne 1.2.0 → 1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0815485e47677a65023e13711ad70570b79c97057ad8d09bed83f45aa293f939'
4
- data.tar.gz: d1f8a39135462f1bca941515d055f19f44cdf92c0152ea0c49d8dd3f39475fb7
3
+ metadata.gz: 3f0d72961e8144605b8f0dbd7953161f17ec4c585c67b3e5bde80d84b3664f1b
4
+ data.tar.gz: 5981d937f60d54993ab6bee595598dbc0b52ac99e38e29ef84f5007661929c5b
5
5
  SHA512:
6
- metadata.gz: 809ecabf16dc071eda96f03853baaa42b5736804864e417e2d9a03ee3d37425b7e01c649cee2a2b8728813ffb09a3a4fb61a59e53ebdbf5f3da0b0a435a91807
7
- data.tar.gz: 9c186a3f86f85f2a08eaea4612329a86f104328c99aa561f82a9b42f9b69f50b159f15b1426aec68585aca6f24c937b0967876689b84a0d04a64ac041169c175
6
+ metadata.gz: ecd7010d94b67e2f0c9f19d2dbde4b6b302481156be2657199d6d9fa98c142807f1b006ddb306a2fd8cb3b2d72b3fd4e1708e34c5fe3541ddd0b2320b5e63112
7
+ data.tar.gz: d56c783b4eed7af9ac5e478cfc2b2154b74644ea03fcc84f9fb7bd54c4e2ac8505355bd0ba0405c96255046232f3eee12c83671ef64173f29097ab859a9e428f
data/.travis.yml CHANGED
@@ -24,6 +24,8 @@ matrix:
24
24
  gemfile: gemfiles/railsmaster.gemfile
25
25
  - rvm: jruby-9.2.8.0
26
26
  gemfile: gemfiles/jruby.gemfile
27
+ - rvm: 3.0
28
+ gemfile: Gemfile
27
29
  - rvm: 2.7
28
30
  gemfile: Gemfile
29
31
  - rvm: 2.6.5
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", "~> 5.2"
12
+ gem "activerecord", ">= 6.0", "< 6.2.0"
13
13
  gem "sequel", ">= 5.0"
14
14
  gem "simplecov"
15
15
 
data/README.md CHANGED
@@ -69,7 +69,7 @@ class UserCloner < Clowne::Cloner
69
69
  nullify :login
70
70
 
71
71
  # params here is an arbitrary Hash passed into cloner
72
- finalize do |_source, record, params|
72
+ finalize do |_source, record, **params|
73
73
  record.email = params[:email]
74
74
  end
75
75
  end
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', '~> 4.8'
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
@@ -69,7 +69,7 @@ class UserCloner < Clowne::Cloner
69
69
  nullify :login
70
70
 
71
71
  # params here is an arbitrary Hash passed into cloner
72
- finalize do |_source, record, params|
72
+ finalize do |_source, record, **params|
73
73
  record.email = params[:email]
74
74
  end
75
75
  end
@@ -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.update_attributes(bio_id: cloned_bio.id)
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.update_attributes(bio_id: bio.id)
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
@@ -9,7 +9,7 @@ class UserCloner < Clowne::Cloner
9
9
  # ...
10
10
  after_persist do |origin, clone, mapper:, **|
11
11
  cloned_bio = mapper.clone_of(origin.bio)
12
- clone.update_attributes(bio_id: cloned_bio.id)
12
+ clone.update(bio_id: cloned_bio.id)
13
13
  end
14
14
  end
15
15
  ```
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
@@ -81,7 +81,7 @@ class UserCloner < Clowne::Cloner
81
81
  nullify :login
82
82
 
83
83
  # params here is an arbitrary Hash passed into cloner
84
- finalize do |_source, record, params|
84
+ finalize do |_source, record, **params|
85
85
  record.email = params[:email]
86
86
  end
87
87
  end
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.update_attributes(email: "evl-#{cloned.id}.ms")
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.update_attributes(email: "admin@example.com")
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(*args, &block)
10
- self.class.cloner_class.call(self, *args, &block)
9
+ def clowne(**args, &block)
10
+ self.class.cloner_class.call(self, **args, &block)
11
11
  end
12
12
  end
13
13
 
@@ -30,7 +30,7 @@ module Clowne
30
30
 
31
31
  def clone_one(child)
32
32
  cloner = cloner_for(child)
33
- cloner ? cloner.call(child, cloner_options) : dup_record(child)
33
+ cloner ? cloner.call(child, **cloner_options) : dup_record(child)
34
34
  end
35
35
 
36
36
  def with_scope
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, Proc.new) if block_given?
62
+ plan = Clowne::Planner.enhance(plan, block) if block
63
63
 
64
64
  plan = Clowne::Planner.filter_declarations(plan, options.only)
65
65
 
@@ -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 block_given?
8
+ def initialize(*, &block)
9
+ raise ArgumentError, "Block is required for after_clone" unless block
10
10
 
11
- @block = Proc.new
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 block_given?
8
+ def initialize(*, &block)
9
+ raise ArgumentError, "Block is required for after_persist" unless block
10
10
 
11
- @block = Proc.new
11
+ @block = block
12
12
  end
13
13
 
14
14
  def compile(plan)
@@ -5,7 +5,7 @@ module Clowne
5
5
  class ExcludeAssociation < Base # :nodoc: all
6
6
  attr_accessor :name
7
7
 
8
- def initialize(name)
8
+ def initialize(name, **)
9
9
  @name = name.to_sym
10
10
  end
11
11
 
@@ -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 block_given?
8
+ def initialize(*, &block)
9
+ raise ArgumentError, "Block is required for finalize" unless block
10
10
 
11
- @block = Proc.new
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 block_given?
8
+ def initialize(*, &block)
9
+ raise ArgumentError, "Block is required for init_as" unless block
10
10
 
11
- @block = Proc.new
11
+ @block = block
12
12
  end
13
13
 
14
14
  def compile(plan)
@@ -5,7 +5,7 @@ module Clowne
5
5
  class Nullify < Base # :nodoc: all
6
6
  attr_reader :attributes
7
7
 
8
- def initialize(*attributes)
8
+ def initialize(*attributes, **)
9
9
  raise ArgumentError, "At least one attribute required" if attributes.empty?
10
10
 
11
11
  @attributes = attributes
@@ -8,7 +8,7 @@ module Clowne
8
8
  params ||= {}
9
9
  operation.add_after_persist(
10
10
  proc do
11
- declaration.block.call(source, record, params.merge(mapper: operation.mapper))
11
+ declaration.block.call(source, record, **params.merge(mapper: operation.mapper))
12
12
  end
13
13
  )
14
14
  record
@@ -4,7 +4,7 @@ module Clowne
4
4
  class Resolvers
5
5
  module Finalize # :nodoc: all
6
6
  def self.call(source, record, declaration, params:, **_options)
7
- declaration.block.call(source, record, params)
7
+ declaration.block.call(source, record, **params)
8
8
  record
9
9
  end
10
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clowne
4
- VERSION = "1.2.0"
4
+ VERSION = "1.3.0"
5
5
  end
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.2.0
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: 2020-07-03 00:00:00.000000000 Z
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: '4.8'
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: '4.8'
75
+ version: '5'
76
76
  - !ruby/object:Gem::Dependency
77
77
  name: rubocop
78
78
  requirement: !ruby/object:Gem::Requirement