clowne 1.0.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec-jruby.yml +33 -0
- data/.github/workflows/rspec-truffle.yml +35 -0
- data/.github/workflows/rspec.yml +51 -0
- data/.github/workflows/rubocop.yml +20 -0
- data/.rubocop.yml +13 -52
- data/CHANGELOG.md +23 -0
- data/Gemfile +9 -9
- data/README.md +10 -10
- data/Rakefile +3 -3
- data/clowne.gemspec +15 -9
- data/docs/.nojekyll +0 -0
- data/docs/.rubocop.yml +5 -2
- data/docs/CNAME +1 -0
- data/docs/README.md +131 -0
- data/docs/_sidebar.md +25 -0
- data/docs/active_record.md +2 -5
- data/docs/after_clone.md +53 -0
- data/docs/after_persist.md +9 -12
- data/docs/architecture.md +2 -5
- data/docs/assets/docsify.min.js +1 -0
- data/docs/assets/prism-ruby.min.js +1 -0
- data/docs/assets/styles.css +348 -0
- data/docs/assets/vue.css +1 -0
- data/docs/clone_mapper.md +3 -6
- data/docs/customization.md +1 -4
- data/docs/exclude_association.md +1 -4
- data/docs/finalize.md +6 -10
- data/docs/from_v02_to_v1.md +2 -10
- data/docs/getting_started.md +171 -0
- data/docs/implicit_cloner.md +1 -4
- data/docs/include_association.md +14 -4
- data/docs/index.html +29 -0
- data/docs/init_as.md +4 -8
- data/docs/inline_configuration.md +1 -4
- data/docs/nullify.md +1 -5
- data/docs/operation.md +4 -7
- data/docs/parameters.md +7 -10
- data/docs/sequel.md +1 -4
- data/docs/supported_adapters.md +3 -6
- data/docs/testing.md +18 -21
- data/docs/traits.md +1 -4
- data/gemfiles/activerecord42.gemfile +5 -5
- data/gemfiles/jruby.gemfile +6 -6
- data/gemfiles/railsmaster.gemfile +6 -6
- data/lib/clowne/adapters/active_record/associations/base.rb +1 -1
- data/lib/clowne/adapters/active_record/associations/belongs_to.rb +28 -0
- data/lib/clowne/adapters/active_record/associations/has_one.rb +1 -2
- data/lib/clowne/adapters/active_record/associations.rb +7 -5
- data/lib/clowne/adapters/active_record/dsl.rb +2 -2
- data/lib/clowne/adapters/active_record/resolvers/association.rb +1 -2
- data/lib/clowne/adapters/active_record.rb +3 -3
- data/lib/clowne/adapters/base/association.rb +1 -1
- data/lib/clowne/adapters/base.rb +14 -8
- data/lib/clowne/adapters/sequel/associations/base.rb +2 -2
- data/lib/clowne/adapters/sequel/associations/many_to_many.rb +4 -4
- data/lib/clowne/adapters/sequel/associations/one_to_many.rb +1 -1
- data/lib/clowne/adapters/sequel/associations/one_to_one.rb +1 -1
- data/lib/clowne/adapters/sequel/associations.rb +5 -5
- data/lib/clowne/adapters/sequel/operation.rb +6 -3
- data/lib/clowne/adapters/sequel/resolvers/after_persist.rb +1 -1
- data/lib/clowne/adapters/sequel/resolvers/association.rb +1 -2
- data/lib/clowne/adapters/sequel/specifications/after_persist_does_not_support.rb +1 -1
- data/lib/clowne/adapters/sequel.rb +7 -7
- data/lib/clowne/cloner.rb +11 -11
- data/lib/clowne/declarations/after_clone.rb +21 -0
- 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/include_association.rb +1 -1
- data/lib/clowne/declarations/init_as.rb +3 -3
- data/lib/clowne/declarations/nullify.rb +2 -2
- data/lib/clowne/declarations/trait.rb +1 -1
- data/lib/clowne/declarations.rb +15 -14
- data/lib/clowne/ext/orm_ext.rb +1 -1
- data/lib/clowne/ext/record_key.rb +1 -1
- data/lib/clowne/ext/string_constantize.rb +1 -1
- data/lib/clowne/ext/yield_self_then.rb +2 -2
- data/lib/clowne/planner.rb +1 -1
- data/lib/clowne/resolvers/after_clone.rb +18 -0
- data/lib/clowne/resolvers/after_persist.rb +1 -1
- data/lib/clowne/resolvers/finalize.rb +1 -1
- data/lib/clowne/resolvers/init_as.rb +0 -1
- data/lib/clowne/rspec/clone_association.rb +3 -4
- data/lib/clowne/rspec/clone_associations.rb +2 -2
- data/lib/clowne/rspec/helpers.rb +1 -1
- data/lib/clowne/rspec.rb +3 -3
- data/lib/clowne/utils/clone_mapper.rb +1 -1
- data/lib/clowne/utils/operation.rb +19 -7
- data/lib/clowne/utils/params.rb +1 -1
- data/lib/clowne/version.rb +1 -1
- data/lib/clowne.rb +10 -11
- metadata +60 -38
- data/.travis.yml +0 -55
- data/docs/alternatives.md +0 -26
- data/docs/basic_example.md +0 -83
- data/docs/installation.md +0 -46
- data/docs/overview.md +0 -24
- data/docs/web/.gitignore +0 -11
- data/docs/web/README.md +0 -6
- data/docs/web/core/Footer.js +0 -88
- data/docs/web/i18n/en.json +0 -140
- data/docs/web/package.json +0 -14
- data/docs/web/pages/en/help.js +0 -50
- data/docs/web/pages/en/index.js +0 -231
- data/docs/web/pages/en/users.js +0 -47
- data/docs/web/sidebars.json +0 -37
- data/docs/web/siteConfig.js +0 -46
- data/docs/web/static/css/custom.css +0 -235
- data/docs/web/static/fonts/FiraCode-Medium.woff +0 -0
- data/docs/web/static/fonts/FiraCode-Regular.woff +0 -0
- data/docs/web/static/img/favicon/favicon.ico +0 -0
- 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
|
-
|
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
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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(
|
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
|
|
@@ -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
|
-
|
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
|
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
|
17
|
-
require
|
16
|
+
require "clowne/adapters/active_record/associations"
|
17
|
+
require "clowne/adapters/active_record/resolvers/association"
|
data/lib/clowne/adapters/base.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "clowne/adapters/registry"
|
4
4
|
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
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
|
-
#
|
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
|
-
#
|
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
|
-
:
|
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
|
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,
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
|
@@ -9,7 +9,7 @@ module Clowne
|
|
9
9
|
child = association
|
10
10
|
return record unless child
|
11
11
|
|
12
|
-
warn
|
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
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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
|
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
|
-
|
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
|
@@ -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
|
38
|
+
source.respond_to?(:"#{declaration.name}_attributes=")
|
40
39
|
end
|
41
40
|
end
|
42
41
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
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
|
25
|
-
require
|
26
|
-
require
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
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
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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
|
-
|
47
|
-
|
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,
|
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,
|
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,
|
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,
|
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,
|
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)
|
@@ -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,
|
8
|
+
def initialize(*attributes, **)
|
9
|
+
raise ArgumentError, "At least one attribute required" if attributes.empty?
|
10
10
|
|
11
11
|
@attributes = attributes
|
12
12
|
end
|
data/lib/clowne/declarations.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
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 =
|
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, &
|
15
|
-
declarations.push declaration.new(*args, &
|
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
|
27
|
-
require
|
28
|
-
require
|
29
|
-
require
|
30
|
-
require
|
31
|
-
require
|
32
|
-
require
|
33
|
-
require
|
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"
|
data/lib/clowne/ext/orm_ext.rb
CHANGED
@@ -11,11 +11,11 @@ module Clowne
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
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
|
18
|
+
::Object.include(Ext) if RUBY_PLATFORM.match?(/java/i)
|
19
19
|
|
20
20
|
refine Object do
|
21
21
|
include Ext
|
data/lib/clowne/planner.rb
CHANGED
@@ -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
|