clowne 1.0.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec-jruby.yml +33 -0
  3. data/.github/workflows/rspec-truffle.yml +35 -0
  4. data/.github/workflows/rspec.yml +51 -0
  5. data/.github/workflows/rubocop.yml +20 -0
  6. data/.rubocop.yml +13 -52
  7. data/CHANGELOG.md +23 -0
  8. data/Gemfile +9 -9
  9. data/README.md +10 -10
  10. data/Rakefile +3 -3
  11. data/clowne.gemspec +15 -9
  12. data/docs/.nojekyll +0 -0
  13. data/docs/.rubocop.yml +5 -2
  14. data/docs/CNAME +1 -0
  15. data/docs/README.md +131 -0
  16. data/docs/_sidebar.md +25 -0
  17. data/docs/active_record.md +2 -5
  18. data/docs/after_clone.md +53 -0
  19. data/docs/after_persist.md +9 -12
  20. data/docs/architecture.md +2 -5
  21. data/docs/assets/docsify.min.js +1 -0
  22. data/docs/assets/prism-ruby.min.js +1 -0
  23. data/docs/assets/styles.css +348 -0
  24. data/docs/assets/vue.css +1 -0
  25. data/docs/clone_mapper.md +3 -6
  26. data/docs/customization.md +1 -4
  27. data/docs/exclude_association.md +1 -4
  28. data/docs/finalize.md +6 -10
  29. data/docs/from_v02_to_v1.md +2 -10
  30. data/docs/getting_started.md +171 -0
  31. data/docs/implicit_cloner.md +1 -4
  32. data/docs/include_association.md +14 -4
  33. data/docs/index.html +29 -0
  34. data/docs/init_as.md +4 -8
  35. data/docs/inline_configuration.md +1 -4
  36. data/docs/nullify.md +1 -5
  37. data/docs/operation.md +4 -7
  38. data/docs/parameters.md +7 -10
  39. data/docs/sequel.md +1 -4
  40. data/docs/supported_adapters.md +3 -6
  41. data/docs/testing.md +18 -21
  42. data/docs/traits.md +1 -4
  43. data/gemfiles/activerecord42.gemfile +5 -5
  44. data/gemfiles/jruby.gemfile +6 -6
  45. data/gemfiles/railsmaster.gemfile +6 -6
  46. data/lib/clowne/adapters/active_record/associations/base.rb +1 -1
  47. data/lib/clowne/adapters/active_record/associations/belongs_to.rb +28 -0
  48. data/lib/clowne/adapters/active_record/associations/has_one.rb +1 -2
  49. data/lib/clowne/adapters/active_record/associations.rb +7 -5
  50. data/lib/clowne/adapters/active_record/dsl.rb +2 -2
  51. data/lib/clowne/adapters/active_record/resolvers/association.rb +1 -2
  52. data/lib/clowne/adapters/active_record.rb +3 -3
  53. data/lib/clowne/adapters/base/association.rb +1 -1
  54. data/lib/clowne/adapters/base.rb +14 -8
  55. data/lib/clowne/adapters/sequel/associations/base.rb +2 -2
  56. data/lib/clowne/adapters/sequel/associations/many_to_many.rb +4 -4
  57. data/lib/clowne/adapters/sequel/associations/one_to_many.rb +1 -1
  58. data/lib/clowne/adapters/sequel/associations/one_to_one.rb +1 -1
  59. data/lib/clowne/adapters/sequel/associations.rb +5 -5
  60. data/lib/clowne/adapters/sequel/operation.rb +6 -3
  61. data/lib/clowne/adapters/sequel/resolvers/after_persist.rb +1 -1
  62. data/lib/clowne/adapters/sequel/resolvers/association.rb +1 -2
  63. data/lib/clowne/adapters/sequel/specifications/after_persist_does_not_support.rb +1 -1
  64. data/lib/clowne/adapters/sequel.rb +7 -7
  65. data/lib/clowne/cloner.rb +11 -11
  66. data/lib/clowne/declarations/after_clone.rb +21 -0
  67. data/lib/clowne/declarations/after_persist.rb +3 -3
  68. data/lib/clowne/declarations/exclude_association.rb +1 -1
  69. data/lib/clowne/declarations/finalize.rb +3 -3
  70. data/lib/clowne/declarations/include_association.rb +1 -1
  71. data/lib/clowne/declarations/init_as.rb +3 -3
  72. data/lib/clowne/declarations/nullify.rb +2 -2
  73. data/lib/clowne/declarations/trait.rb +1 -1
  74. data/lib/clowne/declarations.rb +15 -14
  75. data/lib/clowne/ext/orm_ext.rb +1 -1
  76. data/lib/clowne/ext/record_key.rb +1 -1
  77. data/lib/clowne/ext/string_constantize.rb +1 -1
  78. data/lib/clowne/ext/yield_self_then.rb +2 -2
  79. data/lib/clowne/planner.rb +1 -1
  80. data/lib/clowne/resolvers/after_clone.rb +18 -0
  81. data/lib/clowne/resolvers/after_persist.rb +1 -1
  82. data/lib/clowne/resolvers/finalize.rb +1 -1
  83. data/lib/clowne/resolvers/init_as.rb +0 -1
  84. data/lib/clowne/rspec/clone_association.rb +3 -4
  85. data/lib/clowne/rspec/clone_associations.rb +2 -2
  86. data/lib/clowne/rspec/helpers.rb +1 -1
  87. data/lib/clowne/rspec.rb +3 -3
  88. data/lib/clowne/utils/clone_mapper.rb +1 -1
  89. data/lib/clowne/utils/operation.rb +19 -7
  90. data/lib/clowne/utils/params.rb +1 -1
  91. data/lib/clowne/version.rb +1 -1
  92. data/lib/clowne.rb +10 -11
  93. metadata +60 -38
  94. data/.travis.yml +0 -55
  95. data/docs/alternatives.md +0 -26
  96. data/docs/basic_example.md +0 -83
  97. data/docs/installation.md +0 -46
  98. data/docs/overview.md +0 -24
  99. data/docs/web/.gitignore +0 -11
  100. data/docs/web/README.md +0 -6
  101. data/docs/web/core/Footer.js +0 -88
  102. data/docs/web/i18n/en.json +0 -140
  103. data/docs/web/package.json +0 -14
  104. data/docs/web/pages/en/help.js +0 -50
  105. data/docs/web/pages/en/index.js +0 -231
  106. data/docs/web/pages/en/users.js +0 -47
  107. data/docs/web/sidebars.json +0 -37
  108. data/docs/web/siteConfig.js +0 -46
  109. data/docs/web/static/css/custom.css +0 -235
  110. data/docs/web/static/fonts/FiraCode-Medium.woff +0 -0
  111. data/docs/web/static/fonts/FiraCode-Regular.woff +0 -0
  112. data/docs/web/static/img/favicon/favicon.ico +0 -0
  113. data/docs/web/yarn.lock +0 -1741
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clowne
4
+ module Adapters # :nodoc: all
5
+ class ActiveRecord
6
+ module Associations
7
+ class BelongsTo < Base
8
+ def call(record)
9
+ child = association
10
+ return record unless child
11
+
12
+ unless declaration.scope.nil?
13
+ warn(
14
+ "[Clowne] Belongs to association does not support scopes " \
15
+ "(#{@association_name} for #{@source.class})"
16
+ )
17
+ end
18
+
19
+ child_clone = clone_one(child)
20
+ record.__send__(:"#{association_name}=", child_clone)
21
+ record
22
+ end
23
+ # rubocop: enable Metrics/MethodLength
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -5,14 +5,13 @@ module Clowne
5
5
  class ActiveRecord
6
6
  module Associations
7
7
  class HasOne < Base
8
- # rubocop: disable Metrics/MethodLength
9
8
  def call(record)
10
9
  child = association
11
10
  return record unless child
12
11
 
13
12
  unless declaration.scope.nil?
14
13
  warn(
15
- '[Clowne] Has one association does not support scopes ' \
14
+ "[Clowne] Has one association does not support scopes " \
16
15
  "(#{@association_name} for #{@source.class})"
17
16
  )
18
17
  end
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/adapters/active_record/associations/base'
4
- require 'clowne/adapters/active_record/associations/noop'
5
- require 'clowne/adapters/active_record/associations/has_one'
6
- require 'clowne/adapters/active_record/associations/has_many'
7
- require 'clowne/adapters/active_record/associations/has_and_belongs_to_many'
3
+ require "clowne/adapters/active_record/associations/base"
4
+ require "clowne/adapters/active_record/associations/noop"
5
+ require "clowne/adapters/active_record/associations/belongs_to"
6
+ require "clowne/adapters/active_record/associations/has_one"
7
+ require "clowne/adapters/active_record/associations/has_many"
8
+ require "clowne/adapters/active_record/associations/has_and_belongs_to_many"
8
9
 
9
10
  module Clowne
10
11
  module Adapters # :nodoc: all
11
12
  class ActiveRecord
12
13
  module Associations
13
14
  AR_2_CLONER = {
15
+ belongs_to: BelongsTo,
14
16
  has_one: HasOne,
15
17
  has_many: HasMany,
16
18
  has_and_belongs_to_many: HABTM
@@ -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
 
@@ -8,13 +8,12 @@ module Clowne
8
8
 
9
9
  class Association
10
10
  class << self
11
- # rubocop: disable Metrics/ParameterLists
12
11
  def call(source, record, declaration, adapter:, params:, **_options)
13
12
  reflection = source.class.reflections[declaration.name.to_s]
14
13
 
15
14
  if reflection.nil?
16
15
  raise UnknownAssociation,
17
- "Association #{declaration.name} couldn't be found for #{source.class}"
16
+ "Association #{declaration.name} couldn't be found for #{source.class}"
18
17
  end
19
18
 
20
19
  cloner_class = Associations.cloner_for(reflection)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/orm_ext'
3
+ require "clowne/ext/orm_ext"
4
4
 
5
5
  module Clowne
6
6
  module Adapters
@@ -13,5 +13,5 @@ ActiveSupport.on_load(:active_record) do
13
13
  ::ActiveRecord::Base.extend Clowne::Ext::ORMExt
14
14
  end
15
15
 
16
- require 'clowne/adapters/active_record/associations'
17
- require 'clowne/adapters/active_record/resolvers/association'
16
+ require "clowne/adapters/active_record/associations"
17
+ require "clowne/adapters/active_record/resolvers/association"
@@ -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
@@ -1,11 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/adapters/registry'
3
+ require "clowne/adapters/registry"
4
4
 
5
- require 'clowne/resolvers/init_as'
6
- require 'clowne/resolvers/nullify'
7
- require 'clowne/resolvers/finalize'
8
- require 'clowne/resolvers/after_persist'
5
+ require "clowne/resolvers/init_as"
6
+ require "clowne/resolvers/nullify"
7
+ require "clowne/resolvers/finalize"
8
+ require "clowne/resolvers/after_persist"
9
+ require "clowne/resolvers/after_clone"
9
10
 
10
11
  module Clowne
11
12
  module Adapters
@@ -16,7 +17,7 @@ module Clowne
16
17
 
17
18
  class << self
18
19
  # Duplicate record and remember record <-> clone relationship in operation
19
- # Cab be overrided in special adapter
20
+ # Can be overrided in special adapter
20
21
  # +record+:: Instance of record (ActiveRecord or Sequel)
21
22
  def dup_record(record)
22
23
  record.dup.tap do |clone|
@@ -26,7 +27,7 @@ module Clowne
26
27
  end
27
28
 
28
29
  # Operation class which using for cloning
29
- # Cab be overrided in special adapter
30
+ # Can be overrided in special adapter
30
31
  def operation_class
31
32
  Clowne::Utils::Operation
32
33
  end
@@ -70,6 +71,11 @@ Clowne::Adapters::Base.register_resolver(
70
71
  )
71
72
 
72
73
  Clowne::Adapters::Base.register_resolver(
73
- :after_persist, Clowne::Resolvers::AfterPersist,
74
+ :after_clone, Clowne::Resolvers::AfterClone,
74
75
  after: :finalize
75
76
  )
77
+
78
+ Clowne::Adapters::Base.register_resolver(
79
+ :after_persist, Clowne::Resolvers::AfterPersist,
80
+ after: :after_clone
81
+ )
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/adapters/base/association'
3
+ require "clowne/adapters/base/association"
4
4
 
5
5
  module Clowne
6
6
  module Adapters # :nodoc: all
@@ -10,7 +10,7 @@ module Clowne
10
10
  private
11
11
 
12
12
  def init_scope
13
- @_init_scope ||= source.__send__([association_name, 'dataset'].join('_'))
13
+ @_init_scope ||= source.__send__([association_name, "dataset"].join("_"))
14
14
  end
15
15
 
16
16
  def record_wrapper(record)
@@ -7,10 +7,10 @@ module Clowne
7
7
  class ManyToMany < Base
8
8
  def call(record)
9
9
  clones = with_scope
10
- .lazy
11
- .map(&method(:clone_one))
12
- .map(&method(:record_wrapper))
13
- .to_a
10
+ .lazy
11
+ .map(&method(:clone_one))
12
+ .map(&method(:record_wrapper))
13
+ .to_a
14
14
 
15
15
  record_wrapper(record).remember_assoc(:"#{association_name}_attributes", clones)
16
16
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/yield_self_then'
3
+ require "clowne/ext/yield_self_then"
4
4
 
5
5
  using Clowne::Ext::YieldSelfThen
6
6
 
@@ -9,7 +9,7 @@ module Clowne
9
9
  child = association
10
10
  return record unless child
11
11
 
12
- warn '[Clowne] Has one association does not support scope' unless declaration.scope.nil?
12
+ warn "[Clowne] Has one association does not support scope" unless declaration.scope.nil?
13
13
 
14
14
  child_clone = clone_one(child)
15
15
  child_clone[:"#{reflection[:key]}"] = nil
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/adapters/sequel/associations/base'
4
- require 'clowne/adapters/sequel/associations/noop'
5
- require 'clowne/adapters/sequel/associations/one_to_one'
6
- require 'clowne/adapters/sequel/associations/one_to_many'
7
- require 'clowne/adapters/sequel/associations/many_to_many'
3
+ require "clowne/adapters/sequel/associations/base"
4
+ require "clowne/adapters/sequel/associations/noop"
5
+ require "clowne/adapters/sequel/associations/one_to_one"
6
+ require "clowne/adapters/sequel/associations/one_to_many"
7
+ require "clowne/adapters/sequel/associations/many_to_many"
8
8
 
9
9
  module Clowne
10
10
  module Adapters # :nodoc: all
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/record_key'
3
+ require "clowne/ext/record_key"
4
4
 
5
5
  module Clowne
6
6
  module Adapters
7
7
  class Sequel # :nodoc: all
8
8
  class Operation < Clowne::Utils::Operation
9
9
  include Clowne::Ext::RecordKey
10
-
11
10
  def initialize(mapper)
12
11
  super
13
12
  @records = {}
@@ -24,7 +23,11 @@ module Clowne
24
23
  def to_record
25
24
  return @_record if defined?(@_record)
26
25
 
27
- @_record = @records[key(@clone)].to_model
26
+ record_wrapper(@clone)
27
+
28
+ @_record = @records[key(@clone)].to_model.tap do
29
+ run_after_clone
30
+ end
28
31
  end
29
32
  end
30
33
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/adapters/sequel/specifications/after_persist_does_not_support'
3
+ require "clowne/adapters/sequel/specifications/after_persist_does_not_support"
4
4
 
5
5
  module Clowne
6
6
  module Adapters # :nodoc: all
@@ -6,7 +6,6 @@ module Clowne
6
6
  module Resolvers
7
7
  class Association
8
8
  class << self
9
- # rubocop: disable Metrics/ParameterLists
10
9
  def call(source, record, declaration, adapter:, params:, **_options)
11
10
  with_clonable(source, record, declaration) do
12
11
  reflection = source.class.association_reflections[declaration.name.to_sym]
@@ -36,7 +35,7 @@ module Clowne
36
35
 
37
36
  def clonable_assoc?(source, declaration)
38
37
  source.class.plugins.include?(::Sequel::Plugins::NestedAttributes) &&
39
- source.respond_to?(:"#{declaration.name.to_s}_attributes=")
38
+ source.respond_to?(:"#{declaration.name}_attributes=")
40
39
  end
41
40
  end
42
41
  end
@@ -6,7 +6,7 @@ module Clowne
6
6
  module Specifications # :nodoc: all
7
7
  class AfterPersistDoesNotSupportException < StandardError
8
8
  def message
9
- 'Sequel adapter does not support after_persist callback'
9
+ "Sequel adapter does not support after_persist callback"
10
10
  end
11
11
  end
12
12
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/orm_ext'
3
+ require "clowne/ext/orm_ext"
4
4
 
5
5
  module Clowne
6
6
  module Adapters
@@ -21,9 +21,9 @@ end
21
21
 
22
22
  ::Sequel::Model.extend Clowne::Ext::ORMExt
23
23
 
24
- require 'clowne/adapters/sequel/operation'
25
- require 'clowne/adapters/sequel/associations'
26
- require 'clowne/adapters/sequel/copier'
27
- require 'clowne/adapters/sequel/record_wrapper'
28
- require 'clowne/adapters/sequel/resolvers/association'
29
- require 'clowne/adapters/sequel/resolvers/after_persist'
24
+ require "clowne/adapters/sequel/operation"
25
+ require "clowne/adapters/sequel/associations"
26
+ require "clowne/adapters/sequel/copier"
27
+ require "clowne/adapters/sequel/record_wrapper"
28
+ require "clowne/adapters/sequel/resolvers/association"
29
+ require "clowne/adapters/sequel/resolvers/after_persist"
data/lib/clowne/cloner.rb CHANGED
@@ -1,13 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/planner'
4
- require 'clowne/dsl'
5
- require 'clowne/utils/options'
6
- require 'clowne/utils/params'
7
- require 'clowne/utils/operation'
3
+ require "clowne/planner"
4
+ require "clowne/dsl"
5
+ require "clowne/utils/options"
6
+ require "clowne/utils/params"
7
+ require "clowne/utils/operation"
8
8
 
9
9
  module Clowne # :nodoc: all
10
10
  class UnprocessableSourceError < StandardError; end
11
+
11
12
  class ConfigurationError < StandardError; end
12
13
 
13
14
  class Cloner
@@ -43,14 +44,13 @@ module Clowne # :nodoc: all
43
44
  @traits[name].extend_with(block)
44
45
  end
45
46
 
46
- # rubocop: disable Metrics/AbcSize, Metrics/MethodLength
47
- def call(object, **options)
48
- raise(UnprocessableSourceError, 'Nil is not cloneable object') if object.nil?
47
+ def call(object, **options, &block)
48
+ raise(UnprocessableSourceError, "Nil is not cloneable object") if object.nil?
49
49
 
50
50
  options = Clowne::Utils::Options.new(options)
51
51
  current_adapter = current_adapter(options.adapter)
52
52
 
53
- raise(ConfigurationError, 'Adapter is not defined') if current_adapter.nil?
53
+ raise(ConfigurationError, "Adapter is not defined") if current_adapter.nil?
54
54
 
55
55
  plan =
56
56
  if options.traits.empty?
@@ -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
 
@@ -79,7 +79,7 @@ module Clowne # :nodoc: all
79
79
 
80
80
  def plan_with_traits(ids, current_adapter: adapter)
81
81
  # Cache plans for combinations of traits
82
- traits_id = ids.map(&:to_s).join(':')
82
+ traits_id = ids.map(&:to_s).join(":")
83
83
  return traits_plans[traits_id] if traits_plans.key?(traits_id)
84
84
 
85
85
  traits_plans[traits_id] = Clowne::Planner.compile(
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clowne
4
+ module Declarations
5
+ class AfterClone < Base # :nodoc: all
6
+ attr_reader :block
7
+
8
+ def initialize(*, &block)
9
+ raise ArgumentError, "Block is required for after_clone" unless block
10
+
11
+ @block = block
12
+ end
13
+
14
+ def compile(plan)
15
+ plan.add(:after_clone, self)
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ Clowne::Declarations.add :after_clone, Clowne::Declarations::AfterClone
@@ -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)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/string_constantize'
3
+ require "clowne/ext/string_constantize"
4
4
 
5
5
  module Clowne
6
6
  module Declarations
@@ -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,8 +5,8 @@ module Clowne
5
5
  class Nullify < Base # :nodoc: all
6
6
  attr_reader :attributes
7
7
 
8
- def initialize(*attributes)
9
- raise ArgumentError, 'At least one attribute required' if attributes.empty?
8
+ def initialize(*attributes, **)
9
+ raise ArgumentError, "At least one attribute required" if attributes.empty?
10
10
 
11
11
  @attributes = attributes
12
12
  end
@@ -17,7 +17,7 @@ module Clowne
17
17
  @compiled = compile
18
18
  end
19
19
 
20
- alias declarations compiled
20
+ alias_method :declarations, :compiled
21
21
 
22
22
  def dup
23
23
  self.class.new.tap do |duped|
@@ -1,18 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/dsl'
4
- require 'clowne/utils/plan'
3
+ require "clowne/dsl"
4
+ require "clowne/utils/plan"
5
5
 
6
6
  module Clowne
7
7
  module Declarations # :nodoc:
8
8
  module_function
9
9
 
10
- def add(id, declaration = nil)
11
- declaration = Proc.new if block_given?
10
+ def add(id, declaration = nil, &block)
11
+ declaration = block if block
12
12
 
13
13
  if declaration.is_a?(Class)
14
- DSL.send(:define_method, id) do |*args, &block|
15
- declarations.push declaration.new(*args, &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)
@@ -23,11 +23,12 @@ module Clowne
23
23
  end
24
24
  end
25
25
 
26
- require 'clowne/declarations/base'
27
- require 'clowne/declarations/init_as'
28
- require 'clowne/declarations/exclude_association'
29
- require 'clowne/declarations/finalize'
30
- require 'clowne/declarations/include_association'
31
- require 'clowne/declarations/nullify'
32
- require 'clowne/declarations/trait'
33
- require 'clowne/declarations/after_persist'
26
+ require "clowne/declarations/base"
27
+ require "clowne/declarations/init_as"
28
+ require "clowne/declarations/exclude_association"
29
+ require "clowne/declarations/finalize"
30
+ require "clowne/declarations/include_association"
31
+ require "clowne/declarations/nullify"
32
+ require "clowne/declarations/trait"
33
+ require "clowne/declarations/after_persist"
34
+ require "clowne/declarations/after_clone"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/string_constantize'
3
+ require "clowne/ext/string_constantize"
4
4
 
5
5
  module Clowne
6
6
  module Ext
@@ -5,7 +5,7 @@ module Clowne
5
5
  module RecordKey # :nodoc: all
6
6
  def key(record)
7
7
  id = record.respond_to?(:id) && record.id ? record.id : record.__id__
8
- [record.class.name, id].join('#')
8
+ [record.class.name, id].join("#")
9
9
  end
10
10
  end
11
11
  end
@@ -6,7 +6,7 @@ module Clowne
6
6
  module StringConstantize
7
7
  refine String do
8
8
  def constantize
9
- names = split('::')
9
+ names = split("::")
10
10
 
11
11
  return nil if names.empty?
12
12
 
@@ -11,11 +11,11 @@ module Clowne
11
11
  end
12
12
  end
13
13
 
14
- alias then yield_self
14
+ alias_method :then, :yield_self
15
15
  end
16
16
 
17
17
  # See https://github.com/jruby/jruby/issues/5220
18
- ::Object.include(Ext) if RUBY_PLATFORM =~ /java/i
18
+ ::Object.include(Ext) if RUBY_PLATFORM.match?(/java/i)
19
19
 
20
20
  refine Object do
21
21
  include Ext
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/utils/plan'
3
+ require "clowne/utils/plan"
4
4
 
5
5
  module Clowne
6
6
  class Planner # :nodoc: all
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Clowne
4
+ class Resolvers
5
+ module AfterClone # :nodoc: all
6
+ def self.call(source, record, declaration, params:, **_options)
7
+ operation = Clowne::Utils::Operation.current
8
+ params ||= {}
9
+ operation.add_after_clone(
10
+ proc do
11
+ declaration.block.call(source, record, **params.merge(mapper: operation.mapper))
12
+ end
13
+ )
14
+ record
15
+ end
16
+ end
17
+ end
18
+ end
@@ -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
@@ -3,7 +3,6 @@
3
3
  module Clowne
4
4
  class Resolvers
5
5
  module InitAs # :nodoc: all
6
- # rubocop: disable Metrics/ParameterLists
7
6
  def self.call(source, _record, declaration, params:, adapter:, **_options)
8
7
  adapter.init_record(declaration.block.call(source, **params))
9
8
  end