clowne 0.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +11 -45
- data/.travis.yml +14 -21
- data/CHANGELOG.md +30 -0
- data/Gemfile +11 -7
- data/README.md +38 -18
- data/Rakefile +3 -3
- data/clowne.gemspec +17 -10
- data/docs/.nojekyll +0 -0
- data/docs/.rubocop.yml +8 -2
- data/docs/CNAME +1 -0
- data/docs/README.md +131 -0
- data/docs/_sidebar.md +25 -0
- data/docs/active_record.md +4 -7
- data/docs/after_clone.md +53 -0
- data/docs/after_persist.md +77 -0
- 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 +59 -0
- data/docs/customization.md +6 -7
- data/docs/exclude_association.md +6 -8
- data/docs/finalize.md +11 -15
- data/docs/from_v02_to_v1.md +83 -0
- data/docs/getting_started.md +171 -0
- data/docs/implicit_cloner.md +2 -5
- data/docs/include_association.md +24 -10
- data/docs/index.html +29 -0
- data/docs/init_as.md +13 -9
- data/docs/inline_configuration.md +5 -6
- data/docs/nullify.md +3 -7
- data/docs/operation.md +55 -0
- data/docs/parameters.md +112 -0
- data/docs/sequel.md +16 -22
- data/docs/supported_adapters.md +3 -6
- data/docs/testing.md +194 -0
- data/docs/traits.md +1 -4
- data/gemfiles/activerecord42.gemfile +7 -5
- data/gemfiles/jruby.gemfile +8 -6
- data/gemfiles/railsmaster.gemfile +8 -6
- data/lib/clowne.rb +12 -9
- data/lib/clowne/adapters/active_record.rb +4 -5
- data/lib/clowne/adapters/active_record/associations.rb +8 -6
- data/lib/clowne/adapters/active_record/associations/base.rb +1 -5
- data/lib/clowne/adapters/active_record/associations/belongs_to.rb +29 -0
- data/lib/clowne/adapters/active_record/associations/has_one.rb +3 -2
- data/lib/clowne/adapters/active_record/dsl.rb +2 -2
- data/lib/clowne/adapters/active_record/resolvers/association.rb +38 -0
- data/lib/clowne/adapters/base.rb +49 -44
- data/lib/clowne/adapters/base/association.rb +24 -15
- data/lib/clowne/adapters/registry.rb +49 -0
- data/lib/clowne/adapters/sequel.rb +14 -10
- data/lib/clowne/adapters/sequel/associations.rb +6 -6
- data/lib/clowne/adapters/sequel/associations/base.rb +9 -5
- data/lib/clowne/adapters/sequel/associations/many_to_many.rb +6 -2
- data/lib/clowne/adapters/sequel/associations/one_to_many.rb +7 -2
- data/lib/clowne/adapters/sequel/associations/one_to_one.rb +7 -2
- data/lib/clowne/adapters/sequel/operation.rb +35 -0
- data/lib/clowne/adapters/sequel/record_wrapper.rb +0 -16
- data/lib/clowne/adapters/sequel/resolvers/after_persist.rb +22 -0
- data/lib/clowne/adapters/sequel/resolvers/association.rb +51 -0
- data/lib/clowne/adapters/sequel/specifications/after_persist_does_not_support.rb +15 -0
- data/lib/clowne/cloner.rb +49 -21
- data/lib/clowne/declarations.rb +15 -12
- data/lib/clowne/declarations/after_clone.rb +21 -0
- data/lib/clowne/declarations/after_persist.rb +21 -0
- data/lib/clowne/declarations/base.rb +13 -0
- data/lib/clowne/declarations/exclude_association.rb +2 -2
- data/lib/clowne/declarations/finalize.rb +5 -4
- data/lib/clowne/declarations/include_association.rb +16 -2
- data/lib/clowne/declarations/init_as.rb +5 -4
- data/lib/clowne/declarations/nullify.rb +4 -3
- data/lib/clowne/declarations/trait.rb +1 -0
- data/lib/clowne/dsl.rb +9 -0
- data/lib/clowne/ext/lambda_as_proc.rb +17 -0
- data/lib/clowne/ext/orm_ext.rb +1 -1
- data/lib/clowne/ext/record_key.rb +12 -0
- data/lib/clowne/ext/string_constantize.rb +9 -3
- data/lib/clowne/ext/yield_self_then.rb +25 -0
- data/lib/clowne/planner.rb +16 -3
- data/lib/clowne/resolvers/after_clone.rb +17 -0
- data/lib/clowne/resolvers/after_persist.rb +18 -0
- data/lib/clowne/resolvers/finalize.rb +12 -0
- data/lib/clowne/resolvers/init_as.rb +13 -0
- data/lib/clowne/resolvers/nullify.rb +15 -0
- data/lib/clowne/rspec.rb +5 -0
- data/lib/clowne/rspec/clone_association.rb +99 -0
- data/lib/clowne/rspec/clone_associations.rb +26 -0
- data/lib/clowne/rspec/helpers.rb +35 -0
- data/lib/clowne/utils/clone_mapper.rb +26 -0
- data/lib/clowne/utils/operation.rb +95 -0
- data/lib/clowne/utils/options.rb +39 -0
- data/lib/clowne/utils/params.rb +64 -0
- data/lib/clowne/utils/plan.rb +90 -0
- data/lib/clowne/version.rb +1 -1
- metadata +99 -45
- data/docs/alternatives.md +0 -26
- data/docs/basic_example.md +0 -66
- data/docs/configuration.md +0 -29
- data/docs/execution_order.md +0 -14
- data/docs/installation.md +0 -16
- data/docs/web/.gitignore +0 -11
- data/docs/web/core/Footer.js +0 -92
- data/docs/web/i18n/en.json +0 -134
- 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 -30
- data/docs/web/siteConfig.js +0 -44
- data/docs/web/static/css/custom.css +0 -229
- data/docs/web/static/fonts/FiraCode-Medium.woff +0 -0
- data/docs/web/static/fonts/FiraCode-Regular.woff +0 -0
- data/docs/web/static/fonts/StemText.woff +0 -0
- data/docs/web/static/fonts/StemTextBold.woff +0 -0
- data/docs/web/static/img/favicon/favicon.ico +0 -0
- data/docs/web/yarn.lock +0 -1741
- data/lib/clowne/adapters/active_record/association.rb +0 -34
- data/lib/clowne/adapters/base/finalize.rb +0 -19
- data/lib/clowne/adapters/base/init_as.rb +0 -21
- data/lib/clowne/adapters/base/nullify.rb +0 -19
- data/lib/clowne/adapters/sequel/association.rb +0 -47
- data/lib/clowne/plan.rb +0 -81
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
module Adapters # :nodoc: all
|
5
|
-
class ActiveRecord
|
6
|
-
class UnknownAssociation < StandardError; end
|
7
|
-
|
8
|
-
class Association
|
9
|
-
class << self
|
10
|
-
def call(source, record, declaration, params:, **_options)
|
11
|
-
reflection = source.class.reflections[declaration.name.to_s]
|
12
|
-
|
13
|
-
if reflection.nil?
|
14
|
-
raise UnknownAssociation,
|
15
|
-
"Association #{declaration.name} couldn't be found for #{source.class}"
|
16
|
-
end
|
17
|
-
|
18
|
-
cloner_class = Associations.cloner_for(reflection)
|
19
|
-
|
20
|
-
cloner_class.new(reflection, source, declaration, params).call(record)
|
21
|
-
|
22
|
-
record
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
Clowne::Adapters::ActiveRecord.register_resolver(
|
31
|
-
:association,
|
32
|
-
Clowne::Adapters::ActiveRecord::Association,
|
33
|
-
before: :nullify
|
34
|
-
)
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
module Adapters
|
5
|
-
class Base
|
6
|
-
module Finalize # :nodoc: all
|
7
|
-
def self.call(source, record, declaration, params:, **_options)
|
8
|
-
declaration.block.call(source, record, params)
|
9
|
-
record
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Clowne::Adapters::Base.register_resolver(
|
17
|
-
:finalize, Clowne::Adapters::Base::Finalize,
|
18
|
-
after: :nullify
|
19
|
-
)
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
module Adapters
|
5
|
-
class Base
|
6
|
-
module InitAs # :nodoc: all
|
7
|
-
# rubocop: disable Metrics/ParameterLists
|
8
|
-
def self.call(source, _record, declaration, params:, adapter:, **_options)
|
9
|
-
adapter.init_record(declaration.block.call(source, params))
|
10
|
-
end
|
11
|
-
# rubocop: enable Metrics/ParameterLists
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Clowne::Adapters::Base.register_resolver(
|
18
|
-
:init_as,
|
19
|
-
Clowne::Adapters::Base::InitAs,
|
20
|
-
prepend: true
|
21
|
-
)
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
module Adapters
|
5
|
-
class Base
|
6
|
-
module Nullify # :nodoc: all
|
7
|
-
def self.call(_source, record, declaration, **_options)
|
8
|
-
declaration.attributes.each do |attr|
|
9
|
-
record.__send__("#{attr}=", nil)
|
10
|
-
end
|
11
|
-
|
12
|
-
record
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
Clowne::Adapters::Base.register_resolver(:nullify, Clowne::Adapters::Base::Nullify)
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
module Adapters # :nodoc: all
|
5
|
-
class Sequel
|
6
|
-
class Association
|
7
|
-
class << self
|
8
|
-
def call(source, record, declaration, params:, **_options)
|
9
|
-
with_clonable(source, record, declaration) do
|
10
|
-
reflection = source.class.association_reflections[declaration.name.to_sym]
|
11
|
-
|
12
|
-
cloner_class = Associations.cloner_for(reflection)
|
13
|
-
|
14
|
-
cloner_class.new(reflection, source, declaration, params).call(record)
|
15
|
-
|
16
|
-
record
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def with_clonable(source, record, declaration)
|
23
|
-
if clonable_assoc?(source, declaration)
|
24
|
-
yield(record)
|
25
|
-
else
|
26
|
-
warn <<-WARN
|
27
|
-
Relation #{declaration.name} of #{source.class.name} does not configure for Sequel::Plugins::NestedAttributes
|
28
|
-
WARN
|
29
|
-
end
|
30
|
-
|
31
|
-
record
|
32
|
-
end
|
33
|
-
|
34
|
-
def clonable_assoc?(source, declaration)
|
35
|
-
source.class.plugins.include?(::Sequel::Plugins::NestedAttributes) &&
|
36
|
-
source.respond_to?(:"#{declaration.name.to_s}_attributes=")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
Clowne::Adapters::Sequel.register_resolver(
|
45
|
-
:association,
|
46
|
-
Clowne::Adapters::Sequel::Association
|
47
|
-
)
|
data/lib/clowne/plan.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Clowne
|
4
|
-
class Plan # :nodoc: all
|
5
|
-
class TwoPhaseSet
|
6
|
-
def initialize
|
7
|
-
@added = {}
|
8
|
-
@removed = []
|
9
|
-
end
|
10
|
-
|
11
|
-
def []=(k, v)
|
12
|
-
return if @removed.include?(k)
|
13
|
-
@added[k] = v
|
14
|
-
end
|
15
|
-
|
16
|
-
def delete(k)
|
17
|
-
return if @removed.include?(k)
|
18
|
-
@removed << k
|
19
|
-
@added.delete(k)
|
20
|
-
end
|
21
|
-
|
22
|
-
def values
|
23
|
-
@added.values
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def initialize(registry)
|
28
|
-
@registry = registry
|
29
|
-
@data = {}
|
30
|
-
end
|
31
|
-
|
32
|
-
def add(type, declaration)
|
33
|
-
data[type] = [] unless data.key?(type)
|
34
|
-
data[type] << declaration
|
35
|
-
end
|
36
|
-
|
37
|
-
def add_to(type, id, declaration)
|
38
|
-
data[type] = TwoPhaseSet.new unless data.key?(type)
|
39
|
-
data[type][id] = declaration
|
40
|
-
end
|
41
|
-
|
42
|
-
def set(type, declaration)
|
43
|
-
data[type] = declaration
|
44
|
-
end
|
45
|
-
|
46
|
-
def get(type)
|
47
|
-
data[type]
|
48
|
-
end
|
49
|
-
|
50
|
-
def remove(type)
|
51
|
-
data.delete(type)
|
52
|
-
end
|
53
|
-
|
54
|
-
def remove_from(type, id)
|
55
|
-
return unless data[type]
|
56
|
-
data[type].delete(id)
|
57
|
-
end
|
58
|
-
|
59
|
-
def declarations
|
60
|
-
registry.actions.flat_map do |type|
|
61
|
-
value = data[type]
|
62
|
-
next if value.nil?
|
63
|
-
value = value.values if value.is_a?(TwoPhaseSet)
|
64
|
-
value = Array(value)
|
65
|
-
value.map { |v| [type, v] }
|
66
|
-
end.compact
|
67
|
-
end
|
68
|
-
|
69
|
-
def dup
|
70
|
-
self.class.new(registry).tap do |duped|
|
71
|
-
data.each do |k, v|
|
72
|
-
duped.set(k, v.dup)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
attr_reader :data, :registry
|
80
|
-
end
|
81
|
-
end
|