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
@@ -20,10 +20,9 @@ module Clowne
20
20
  extract_options! options
21
21
  end
22
22
 
23
- # rubocop: disable Metrics/AbcSize
24
23
  def match(expected, _actual)
25
24
  @actual = plan.declarations
26
- .find { |key, decl| key == :association && decl.name == expected }
25
+ .find { |key, decl| key == :association && decl.name == expected }
27
26
 
28
27
  return false if @actual.nil?
29
28
 
@@ -60,10 +59,10 @@ module Clowne
60
59
  expected_params[param] = options.fetch(param, UNDEFINED)
61
60
  end
62
61
 
63
- raise ArgumentError, 'Lambda scope is not supported' if
62
+ raise ArgumentError, "Lambda scope is not supported" if
64
63
  expected_params[:scope].is_a?(Proc)
65
64
 
66
- raise ArgumentError, 'Lambda params is not supported' if
65
+ raise ArgumentError, "Lambda params is not supported" if
67
66
  expected_params[:params].is_a?(Proc)
68
67
  end
69
68
 
@@ -9,8 +9,8 @@ module Clowne
9
9
 
10
10
  def convert_actual_to_an_array
11
11
  @actual = plan.declarations
12
- .select { |key, _| key == :association }
13
- .map { |_, decl| decl.name }
12
+ .select { |key, _| key == :association }
13
+ .map { |_, decl| decl.name }
14
14
  end
15
15
  end
16
16
  end
@@ -27,7 +27,7 @@ module Clowne
27
27
  end
28
28
 
29
29
  def non_cloner_message
30
- 'expected a cloner to be passed to `expect(...)`, ' \
30
+ "expected a cloner to be passed to `expect(...)`, " \
31
31
  "but got #{actual_formatted}"
32
32
  end
33
33
  end
data/lib/clowne/rspec.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/rspec/helpers'
4
- require 'clowne/rspec/clone_associations'
5
- require 'clowne/rspec/clone_association'
3
+ require "clowne/rspec/helpers"
4
+ require "clowne/rspec/clone_associations"
5
+ require "clowne/rspec/clone_association"
@@ -1,6 +1,6 @@
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 Utils
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/utils/clone_mapper'
3
+ require "clowne/utils/clone_mapper"
4
4
 
5
5
  module Clowne
6
6
  module Utils
@@ -35,12 +35,17 @@ module Clowne
35
35
  attr_reader :mapper
36
36
 
37
37
  def initialize(mapper)
38
- @blocks = []
38
+ @after_clone_blocks = []
39
+ @after_persist_blocks = []
39
40
  @mapper = mapper
40
41
  end
41
42
 
42
43
  def add_after_persist(block)
43
- @blocks.unshift(block)
44
+ @after_persist_blocks.unshift(block)
45
+ end
46
+
47
+ def add_after_clone(block)
48
+ @after_clone_blocks.unshift(block)
44
49
  end
45
50
 
46
51
  def add_mapping(origin, clone)
@@ -48,7 +53,10 @@ module Clowne
48
53
  end
49
54
 
50
55
  def to_record
51
- @clone
56
+ return @_record if defined?(@_record)
57
+
58
+ run_after_clone
59
+ @_record = @clone
52
60
  end
53
61
 
54
62
  def persist!
@@ -66,17 +74,21 @@ module Clowne
66
74
  end
67
75
 
68
76
  def save
69
- warn '[DEPRECATION] `save` is deprecated. Please use `persist` instead.'
77
+ warn "[DEPRECATION] `save` is deprecated. Please use `persist` instead."
70
78
  @clone.save
71
79
  end
72
80
 
73
81
  def save!
74
- warn '[DEPRECATION] `save!` is deprecated. Please use `persist!` instead.'
82
+ warn "[DEPRECATION] `save!` is deprecated. Please use `persist!` instead."
75
83
  @clone.save!
76
84
  end
77
85
 
78
86
  def run_after_persist
79
- @blocks.each(&:call)
87
+ @after_persist_blocks.each(&:call)
88
+ end
89
+
90
+ def run_after_clone
91
+ @after_clone_blocks.each(&:call)
80
92
  end
81
93
  end
82
94
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/ext/lambda_as_proc'
3
+ require "clowne/ext/lambda_as_proc"
4
4
 
5
5
  module Clowne
6
6
  module Utils
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clowne
4
- VERSION = '1.0.0'
4
+ VERSION = "1.4.0"
5
5
  end
data/lib/clowne.rb CHANGED
@@ -1,21 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'clowne/version'
4
- require 'clowne/declarations'
5
- require 'clowne/cloner'
3
+ require "clowne/version"
4
+ require "clowne/declarations"
5
+ require "clowne/cloner"
6
6
 
7
- require 'clowne/adapters/base'
7
+ require "clowne/adapters/base"
8
8
 
9
9
  # Declarative models cloning
10
10
  module Clowne
11
11
  # List of built-in adapters
12
- # rubocop:disable AlignHash
13
12
  ADAPTERS = {
14
- base: 'Base',
15
- active_record: 'ActiveRecord',
16
- sequel: 'Sequel'
13
+ base: "Base",
14
+ active_record: "ActiveRecord",
15
+ sequel: "Sequel"
17
16
  }.freeze
18
- # rubocop:enable AlignHash
17
+ # rubocop:enable Layout/AlignHash
19
18
 
20
19
  class << self
21
20
  attr_reader :default_adapter, :raise_on_override
@@ -40,5 +39,5 @@ module Clowne
40
39
  end
41
40
  end
42
41
 
43
- require 'clowne/adapters/active_record' if defined?(::ActiveRecord)
44
- require 'clowne/adapters/sequel' if defined?(::Sequel)
42
+ require "clowne/adapters/active_record" if defined?(::ActiveRecord)
43
+ require "clowne/adapters/sequel" if defined?(::Sequel)
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clowne
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dementyev
8
8
  - Sverchkov Nikolay
9
9
  autorequire:
10
- bindir: exe
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-26 00:00:00.000000000 Z
12
+ date: 2022-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -31,14 +31,20 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '10.0'
34
+ version: '12.3'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 12.3.3
35
38
  type: :development
36
39
  prerelease: false
37
40
  version_requirements: !ruby/object:Gem::Requirement
38
41
  requirements:
39
42
  - - "~>"
40
43
  - !ruby/object:Gem::Version
41
- version: '10.0'
44
+ version: '12.3'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 12.3.3
42
48
  - !ruby/object:Gem::Dependency
43
49
  name: rspec
44
50
  requirement: !ruby/object:Gem::Requirement
@@ -59,56 +65,70 @@ dependencies:
59
65
  requirements:
60
66
  - - "~>"
61
67
  - !ruby/object:Gem::Version
62
- version: '4.8'
68
+ version: '5'
63
69
  type: :development
64
70
  prerelease: false
65
71
  version_requirements: !ruby/object:Gem::Requirement
66
72
  requirements:
67
73
  - - "~>"
68
74
  - !ruby/object:Gem::Version
69
- version: '4.8'
75
+ version: '5'
70
76
  - !ruby/object:Gem::Dependency
71
77
  name: rubocop
72
78
  requirement: !ruby/object:Gem::Requirement
73
79
  requirements:
74
80
  - - "~>"
75
81
  - !ruby/object:Gem::Version
76
- version: '0.61'
82
+ version: '1.22'
77
83
  type: :development
78
84
  prerelease: false
79
85
  version_requirements: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - "~>"
82
88
  - !ruby/object:Gem::Version
83
- version: '0.61'
89
+ version: '1.22'
84
90
  - !ruby/object:Gem::Dependency
85
91
  name: rubocop-md
86
92
  requirement: !ruby/object:Gem::Requirement
87
93
  requirements:
88
94
  - - "~>"
89
95
  - !ruby/object:Gem::Version
90
- version: '0.2'
96
+ version: '1'
91
97
  type: :development
92
98
  prerelease: false
93
99
  version_requirements: !ruby/object:Gem::Requirement
94
100
  requirements:
95
101
  - - "~>"
96
102
  - !ruby/object:Gem::Version
97
- version: '0.2'
103
+ version: '1'
98
104
  - !ruby/object:Gem::Dependency
99
105
  name: rubocop-rspec
100
106
  requirement: !ruby/object:Gem::Requirement
101
107
  requirements:
102
108
  - - "~>"
103
109
  - !ruby/object:Gem::Version
104
- version: '1.31'
110
+ version: '2.5'
111
+ type: :development
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.5'
118
+ - !ruby/object:Gem::Dependency
119
+ name: standard
120
+ requirement: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.4.0
105
125
  type: :development
106
126
  prerelease: false
107
127
  version_requirements: !ruby/object:Gem::Requirement
108
128
  requirements:
109
129
  - - "~>"
110
130
  - !ruby/object:Gem::Version
111
- version: '1.31'
131
+ version: 1.4.0
112
132
  description: A flexible gem for cloning your models.
113
133
  email:
114
134
  - palkan@evilmartians.com
@@ -119,11 +139,14 @@ extra_rdoc_files: []
119
139
  files:
120
140
  - ".codeclimate.yml"
121
141
  - ".gitattributes"
142
+ - ".github/workflows/rspec-jruby.yml"
143
+ - ".github/workflows/rspec-truffle.yml"
144
+ - ".github/workflows/rspec.yml"
145
+ - ".github/workflows/rubocop.yml"
122
146
  - ".gitignore"
123
147
  - ".rspec"
124
148
  - ".rubocop.yml"
125
149
  - ".rufo"
126
- - ".travis.yml"
127
150
  - CHANGELOG.md
128
151
  - Gemfile
129
152
  - LICENSE.txt
@@ -132,45 +155,37 @@ files:
132
155
  - bin/console
133
156
  - bin/setup
134
157
  - clowne.gemspec
158
+ - docs/.nojekyll
135
159
  - docs/.rubocop.yml
160
+ - docs/CNAME
161
+ - docs/README.md
162
+ - docs/_sidebar.md
136
163
  - docs/active_record.md
164
+ - docs/after_clone.md
137
165
  - docs/after_persist.md
138
- - docs/alternatives.md
139
166
  - docs/architecture.md
140
- - docs/basic_example.md
167
+ - docs/assets/docsify.min.js
168
+ - docs/assets/prism-ruby.min.js
169
+ - docs/assets/styles.css
170
+ - docs/assets/vue.css
141
171
  - docs/clone_mapper.md
142
172
  - docs/customization.md
143
173
  - docs/exclude_association.md
144
174
  - docs/finalize.md
145
175
  - docs/from_v02_to_v1.md
176
+ - docs/getting_started.md
146
177
  - docs/implicit_cloner.md
147
178
  - docs/include_association.md
179
+ - docs/index.html
148
180
  - docs/init_as.md
149
181
  - docs/inline_configuration.md
150
- - docs/installation.md
151
182
  - docs/nullify.md
152
183
  - docs/operation.md
153
- - docs/overview.md
154
184
  - docs/parameters.md
155
185
  - docs/sequel.md
156
186
  - docs/supported_adapters.md
157
187
  - docs/testing.md
158
188
  - docs/traits.md
159
- - docs/web/.gitignore
160
- - docs/web/README.md
161
- - docs/web/core/Footer.js
162
- - docs/web/i18n/en.json
163
- - docs/web/package.json
164
- - docs/web/pages/en/help.js
165
- - docs/web/pages/en/index.js
166
- - docs/web/pages/en/users.js
167
- - docs/web/sidebars.json
168
- - docs/web/siteConfig.js
169
- - docs/web/static/css/custom.css
170
- - docs/web/static/fonts/FiraCode-Medium.woff
171
- - docs/web/static/fonts/FiraCode-Regular.woff
172
- - docs/web/static/img/favicon/favicon.ico
173
- - docs/web/yarn.lock
174
189
  - gemfiles/activerecord42.gemfile
175
190
  - gemfiles/jruby.gemfile
176
191
  - gemfiles/railsmaster.gemfile
@@ -178,6 +193,7 @@ files:
178
193
  - lib/clowne/adapters/active_record.rb
179
194
  - lib/clowne/adapters/active_record/associations.rb
180
195
  - lib/clowne/adapters/active_record/associations/base.rb
196
+ - lib/clowne/adapters/active_record/associations/belongs_to.rb
181
197
  - lib/clowne/adapters/active_record/associations/has_and_belongs_to_many.rb
182
198
  - lib/clowne/adapters/active_record/associations/has_many.rb
183
199
  - lib/clowne/adapters/active_record/associations/has_one.rb
@@ -202,6 +218,7 @@ files:
202
218
  - lib/clowne/adapters/sequel/specifications/after_persist_does_not_support.rb
203
219
  - lib/clowne/cloner.rb
204
220
  - lib/clowne/declarations.rb
221
+ - lib/clowne/declarations/after_clone.rb
205
222
  - lib/clowne/declarations/after_persist.rb
206
223
  - lib/clowne/declarations/base.rb
207
224
  - lib/clowne/declarations/exclude_association.rb
@@ -217,6 +234,7 @@ files:
217
234
  - lib/clowne/ext/string_constantize.rb
218
235
  - lib/clowne/ext/yield_self_then.rb
219
236
  - lib/clowne/planner.rb
237
+ - lib/clowne/resolvers/after_clone.rb
220
238
  - lib/clowne/resolvers/after_persist.rb
221
239
  - lib/clowne/resolvers/finalize.rb
222
240
  - lib/clowne/resolvers/init_as.rb
@@ -231,10 +249,15 @@ files:
231
249
  - lib/clowne/utils/params.rb
232
250
  - lib/clowne/utils/plan.rb
233
251
  - lib/clowne/version.rb
234
- homepage: https://github.com/palkan/clowne
252
+ homepage: https://github.com/clowne-rb/clowne
235
253
  licenses:
236
254
  - MIT
237
- metadata: {}
255
+ metadata:
256
+ bug_tracker_uri: http://github.com/clowne-rb/clowne/issues
257
+ changelog_uri: https://github.com/clowne-rb/clowne/blob/master/CHANGELOG.md
258
+ documentation_uri: https://clowne.evilmartians.io/
259
+ homepage_uri: https://clowne.evilmartians.io/
260
+ source_code_uri: http://github.com/clowne-rb/clowne
238
261
  post_install_message:
239
262
  rdoc_options: []
240
263
  require_paths:
@@ -250,9 +273,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
273
  - !ruby/object:Gem::Version
251
274
  version: '0'
252
275
  requirements: []
253
- rubyforge_project:
254
- rubygems_version: 2.7.6
276
+ rubygems_version: 3.0.3.1
255
277
  signing_key:
256
278
  specification_version: 4
257
- summary: A flexible gem for cloning your models.
279
+ summary: A flexible gem for cloning your models
258
280
  test_files: []
data/.travis.yml DELETED
@@ -1,55 +0,0 @@
1
- sudo: false
2
- language: ruby
3
-
4
- notifications:
5
- email: false
6
-
7
- before_install:
8
- - gem update --system
9
- - gem install bundler
10
-
11
- before_script:
12
- # Only generate coverage report for the specified job
13
- - if [ "$CC_REPORT" == "true" ]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter; fi
14
- - if [ "$CC_REPORT" == "true" ]; then chmod +x ./cc-test-reporter; fi
15
- - if [ "$CC_REPORT" == "true" ]; then ./cc-test-reporter before-build; fi
16
- script:
17
- - bundle exec rake
18
- - if [ "$CC_REPORT" == "true" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
19
- - if [ "$DEPLOY_ME" == "true" ]; then (cd ./docs/web && yarn && yarn run build); fi
20
-
21
- matrix:
22
- fast_finish: true
23
- include:
24
- - rvm: ruby-head
25
- gemfile: gemfiles/railsmaster.gemfile
26
- - rvm: jruby-9.2.5.0
27
- gemfile: gemfiles/jruby.gemfile
28
- - rvm: jruby-9.1.15.0
29
- gemfile: gemfiles/jruby.gemfile
30
- - rvm: 2.5.0
31
- gemfile: Gemfile
32
- - rvm: 2.4.3
33
- gemfile: Gemfile
34
- env:
35
- - CC_REPORT=true
36
- - DEPLOY_ME=true
37
- - rvm: 2.4.1
38
- gemfile: gemfiles/activerecord42.gemfile
39
- - rvm: 2.3.1
40
- gemfile: Gemfile
41
- allow_failures:
42
- - rvm: ruby-head
43
- gemfile: gemfiles/railsmaster.gemfile
44
- - rvm: jruby-9.2.5.0
45
- gemfile: gemfiles/jruby.gemfile
46
- - rvm: jruby-9.1.15.0
47
- gemfile: gemfiles/jruby.gemfile
48
- deploy:
49
- provider: pages
50
- skip_cleanup: true
51
- github_token: $GITHUB_TOKEN
52
- local_dir: "./docs/web/build/clowne"
53
- on:
54
- branch: master
55
- condition: $DEPLOY_ME = true
data/docs/alternatives.md DELETED
@@ -1,26 +0,0 @@
1
- ---
2
- id: alternatives
3
- title: Motivation & Alternatives
4
- ---
5
-
6
- ### Why did we decide to build our own cloning gem instead of using the existing solutions?
7
-
8
- First, the existing solutions turned out not to be stable and flexible enough for us.
9
-
10
- Secondly, they are Rails-only (or, more precisely, ActiveRecord-only).
11
-
12
- Nevertheless, thanks to [amoeba](https://github.com/amoeba-rb/amoeba) and [deep_cloneable](https://github.com/moiristo/deep_cloneable) for inspiration.
13
-
14
- For ActiveRecord we support amoeba-like [in-model configuration](active_record.md) and you can add missing DSL declarations yourself [easily](customization.md).
15
-
16
- We also provide an ability to specify cloning [configuration in-place](inline_configuration.md) like `deep_clonable` does.
17
-
18
- So, we took the best of these too and brought to the outside-of-Rails world.
19
-
20
- ### Why build a gem to clone models at all?
21
-
22
- That's a good question. Of course, you can write plain old Ruby services do handle the cloning logic. But for complex models hierarchies, this approach has major disadvantages: high code complexity and lack of re-usability.
23
-
24
- The things become even worse when you deal with STI models and different cloning contexts.
25
-
26
- That's why we decided to build a specific cloning tool.
@@ -1,83 +0,0 @@
1
- ---
2
- id: basic_example
3
- title: Basic Example
4
- ---
5
-
6
- Assume that you have the following model:
7
-
8
- ```ruby
9
- class User < ActiveRecord::Base
10
- # create_table :users do |t|
11
- # t.string :login
12
- # t.string :email
13
- # t.timestamps null: false
14
- # end
15
-
16
- has_one :profile
17
- has_many :posts
18
- end
19
-
20
- class Profile < ActiveRecord::Base
21
- # create_table :profiles do |t|
22
- # t.string :name
23
- # end
24
- end
25
-
26
- class Post < ActiveRecord::Base
27
- # create_table :posts
28
- end
29
- ```
30
-
31
- Let's declare our cloners first:
32
-
33
- ```ruby
34
- class UserCloner < Clowne::Cloner
35
- adapter :active_record
36
-
37
- include_association :profile, clone_with: SpecialProfileCloner
38
- include_association :posts
39
-
40
- nullify :login
41
-
42
- # params here is an arbitrary Hash passed into cloner
43
- finalize do |_source, record, params|
44
- record.email = params[:email]
45
- end
46
- end
47
-
48
- class SpecialProfileCloner < Clowne::Cloner
49
- adapter :active_record
50
-
51
- nullify :name
52
- end
53
- ```
54
-
55
- Now you can use `UserCloner` to clone existing records:
56
-
57
- ```ruby
58
- user = User.last
59
- # => <#User id: 1, login: 'clown', email: 'clown@circus.example.com'>
60
-
61
- operation = UserCloner.call(user, email: 'fake@example.com')
62
- # => <#Clowne::Utils::Operation...>
63
-
64
- operation.to_record
65
- # => <#User id: nil, login: nil, email: 'fake@example.com'>
66
-
67
- operation.persist!
68
- # => true
69
-
70
- cloned = operation.to_record
71
- # => <#User id: 2, login: nil, email: 'fake@example.com'>
72
-
73
- cloned.login
74
- # => nil
75
- cloned.email
76
- # => "fake@example.com"
77
-
78
- # associations:
79
- cloned.posts.count == user.posts.count
80
- # => true
81
- cloned.profile.name
82
- # => nil
83
- ```
data/docs/installation.md DELETED
@@ -1,46 +0,0 @@
1
- ---
2
- id: installation
3
- title: Installation & Configuration
4
- ---
5
-
6
- ## Installation
7
-
8
- To install Clowne with RubyGems:
9
-
10
- ```ruby
11
- gem install clowne
12
- ```
13
-
14
- Or add this line to your application's Gemfile:
15
-
16
- ```ruby
17
- gem 'clowne'
18
- ```
19
-
20
- ## Configuration
21
-
22
- Basic cloner implementation looks like:
23
-
24
- ```ruby
25
- class SomeCloner < Clowne::Cloner
26
- adapter :active_record # or adapter Clowne::Adapters::ActiveRecord
27
- # some implementation ...
28
- end
29
- ```
30
-
31
- You can configure the default adapter for cloners:
32
-
33
- ```ruby
34
- # put to initializer
35
- # e.g. config/initializers/clowne.rb
36
- Clowne.default_adapter = :active_record
37
- ```
38
-
39
- and skip explicit adapter declaration
40
-
41
- ```ruby
42
- class SomeCloner < Clowne::Cloner
43
- # some implementation ...
44
- end
45
- ```
46
- See the list of [available adapters](supported_adapters.md).
data/docs/overview.md DELETED
@@ -1,24 +0,0 @@
1
- ---
2
- id: overview
3
- title: Overview
4
- ---
5
-
6
- In [the basic example](basic_example.md), you can see that Clowne consists of flexible DSL which is used in a class inherited of `Clowne::Cloner`.
7
-
8
- You can combinate this DSL via [`traits`](traits.md) and make a cloning plan which exactly you want.
9
-
10
- **We strongly recommend [`write tests`](testing.md) to cover resulting cloner logic**
11
-
12
- Cloner class returns [`Operation`](operation.md) instance as a result of cloning. The operation provides methods to save cloned record. You can wrap this call to a transaction if it is necessary.
13
-
14
- ## Execution Order
15
-
16
- The order of cloning actions depends on the adapter (i.e., could be customized).
17
-
18
- All built-in adapters have the same order and what happens when you call `Operation#persist`:
19
- - init clone (see [`init_as`](init_as.md)) (empty by default)
20
- - [`clone associations`](include_association.md)
21
- - [`nullify`](nullify.md) attributes
22
- - run [`finalize`](finalize.md) blocks. _The order of [`finalize`](finalize.md) blocks is the order they've been written._
23
- - __SAVE CLONED RECORD__
24
- - run [`after_persist`](after_persist.md) callbacks
data/docs/web/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- node_modules
2
- .DS_Store
3
- lib/core/metadata.js
4
- lib/core/MetadataBlog.js
5
- website/translated_docs
6
- website/build/
7
- website/yarn.lock
8
- website/node_modules
9
-
10
- website/i18n/*
11
- !website/i18n/en.json
data/docs/web/README.md DELETED
@@ -1,6 +0,0 @@
1
- # Clowne Docs
2
-
3
- 1. Install `node` and `yarn`
4
- 2. `$ yarn` - install frontend deps
5
- 3. `$ yarn run start --port 3002`
6
- 4. `$ open http://localhost:3002`