clowne 0.1.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +11 -45
  3. data/.travis.yml +14 -21
  4. data/CHANGELOG.md +30 -0
  5. data/Gemfile +11 -7
  6. data/README.md +38 -18
  7. data/Rakefile +3 -3
  8. data/clowne.gemspec +17 -10
  9. data/docs/.nojekyll +0 -0
  10. data/docs/.rubocop.yml +8 -2
  11. data/docs/CNAME +1 -0
  12. data/docs/README.md +131 -0
  13. data/docs/_sidebar.md +25 -0
  14. data/docs/active_record.md +4 -7
  15. data/docs/after_clone.md +53 -0
  16. data/docs/after_persist.md +77 -0
  17. data/docs/architecture.md +2 -5
  18. data/docs/assets/docsify.min.js +1 -0
  19. data/docs/assets/prism-ruby.min.js +1 -0
  20. data/docs/assets/styles.css +348 -0
  21. data/docs/assets/vue.css +1 -0
  22. data/docs/clone_mapper.md +59 -0
  23. data/docs/customization.md +6 -7
  24. data/docs/exclude_association.md +6 -8
  25. data/docs/finalize.md +11 -15
  26. data/docs/from_v02_to_v1.md +83 -0
  27. data/docs/getting_started.md +171 -0
  28. data/docs/implicit_cloner.md +2 -5
  29. data/docs/include_association.md +24 -10
  30. data/docs/index.html +29 -0
  31. data/docs/init_as.md +13 -9
  32. data/docs/inline_configuration.md +5 -6
  33. data/docs/nullify.md +3 -7
  34. data/docs/operation.md +55 -0
  35. data/docs/parameters.md +112 -0
  36. data/docs/sequel.md +16 -22
  37. data/docs/supported_adapters.md +3 -6
  38. data/docs/testing.md +194 -0
  39. data/docs/traits.md +1 -4
  40. data/gemfiles/activerecord42.gemfile +7 -5
  41. data/gemfiles/jruby.gemfile +8 -6
  42. data/gemfiles/railsmaster.gemfile +8 -6
  43. data/lib/clowne.rb +12 -9
  44. data/lib/clowne/adapters/active_record.rb +4 -5
  45. data/lib/clowne/adapters/active_record/associations.rb +8 -6
  46. data/lib/clowne/adapters/active_record/associations/base.rb +1 -5
  47. data/lib/clowne/adapters/active_record/associations/belongs_to.rb +29 -0
  48. data/lib/clowne/adapters/active_record/associations/has_one.rb +3 -2
  49. data/lib/clowne/adapters/active_record/dsl.rb +2 -2
  50. data/lib/clowne/adapters/active_record/resolvers/association.rb +38 -0
  51. data/lib/clowne/adapters/base.rb +49 -44
  52. data/lib/clowne/adapters/base/association.rb +24 -15
  53. data/lib/clowne/adapters/registry.rb +49 -0
  54. data/lib/clowne/adapters/sequel.rb +14 -10
  55. data/lib/clowne/adapters/sequel/associations.rb +6 -6
  56. data/lib/clowne/adapters/sequel/associations/base.rb +9 -5
  57. data/lib/clowne/adapters/sequel/associations/many_to_many.rb +6 -2
  58. data/lib/clowne/adapters/sequel/associations/one_to_many.rb +7 -2
  59. data/lib/clowne/adapters/sequel/associations/one_to_one.rb +7 -2
  60. data/lib/clowne/adapters/sequel/operation.rb +35 -0
  61. data/lib/clowne/adapters/sequel/record_wrapper.rb +0 -16
  62. data/lib/clowne/adapters/sequel/resolvers/after_persist.rb +22 -0
  63. data/lib/clowne/adapters/sequel/resolvers/association.rb +51 -0
  64. data/lib/clowne/adapters/sequel/specifications/after_persist_does_not_support.rb +15 -0
  65. data/lib/clowne/cloner.rb +49 -21
  66. data/lib/clowne/declarations.rb +15 -12
  67. data/lib/clowne/declarations/after_clone.rb +21 -0
  68. data/lib/clowne/declarations/after_persist.rb +21 -0
  69. data/lib/clowne/declarations/base.rb +13 -0
  70. data/lib/clowne/declarations/exclude_association.rb +2 -2
  71. data/lib/clowne/declarations/finalize.rb +5 -4
  72. data/lib/clowne/declarations/include_association.rb +16 -2
  73. data/lib/clowne/declarations/init_as.rb +5 -4
  74. data/lib/clowne/declarations/nullify.rb +4 -3
  75. data/lib/clowne/declarations/trait.rb +1 -0
  76. data/lib/clowne/dsl.rb +9 -0
  77. data/lib/clowne/ext/lambda_as_proc.rb +17 -0
  78. data/lib/clowne/ext/orm_ext.rb +1 -1
  79. data/lib/clowne/ext/record_key.rb +12 -0
  80. data/lib/clowne/ext/string_constantize.rb +9 -3
  81. data/lib/clowne/ext/yield_self_then.rb +25 -0
  82. data/lib/clowne/planner.rb +16 -3
  83. data/lib/clowne/resolvers/after_clone.rb +17 -0
  84. data/lib/clowne/resolvers/after_persist.rb +18 -0
  85. data/lib/clowne/resolvers/finalize.rb +12 -0
  86. data/lib/clowne/resolvers/init_as.rb +13 -0
  87. data/lib/clowne/resolvers/nullify.rb +15 -0
  88. data/lib/clowne/rspec.rb +5 -0
  89. data/lib/clowne/rspec/clone_association.rb +99 -0
  90. data/lib/clowne/rspec/clone_associations.rb +26 -0
  91. data/lib/clowne/rspec/helpers.rb +35 -0
  92. data/lib/clowne/utils/clone_mapper.rb +26 -0
  93. data/lib/clowne/utils/operation.rb +95 -0
  94. data/lib/clowne/utils/options.rb +39 -0
  95. data/lib/clowne/utils/params.rb +64 -0
  96. data/lib/clowne/utils/plan.rb +90 -0
  97. data/lib/clowne/version.rb +1 -1
  98. metadata +99 -45
  99. data/docs/alternatives.md +0 -26
  100. data/docs/basic_example.md +0 -66
  101. data/docs/configuration.md +0 -29
  102. data/docs/execution_order.md +0 -14
  103. data/docs/installation.md +0 -16
  104. data/docs/web/.gitignore +0 -11
  105. data/docs/web/core/Footer.js +0 -92
  106. data/docs/web/i18n/en.json +0 -134
  107. data/docs/web/package.json +0 -14
  108. data/docs/web/pages/en/help.js +0 -50
  109. data/docs/web/pages/en/index.js +0 -231
  110. data/docs/web/pages/en/users.js +0 -47
  111. data/docs/web/sidebars.json +0 -30
  112. data/docs/web/siteConfig.js +0 -44
  113. data/docs/web/static/css/custom.css +0 -229
  114. data/docs/web/static/fonts/FiraCode-Medium.woff +0 -0
  115. data/docs/web/static/fonts/FiraCode-Regular.woff +0 -0
  116. data/docs/web/static/fonts/StemText.woff +0 -0
  117. data/docs/web/static/fonts/StemTextBold.woff +0 -0
  118. data/docs/web/static/img/favicon/favicon.ico +0 -0
  119. data/docs/web/yarn.lock +0 -1741
  120. data/lib/clowne/adapters/active_record/association.rb +0 -34
  121. data/lib/clowne/adapters/base/finalize.rb +0 -19
  122. data/lib/clowne/adapters/base/init_as.rb +0 -21
  123. data/lib/clowne/adapters/base/nullify.rb +0 -19
  124. data/lib/clowne/adapters/sequel/association.rb +0 -47
  125. data/lib/clowne/plan.rb +0 -81
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cb07a988be474d61f3bbf9360cfc4ab25de047be
4
- data.tar.gz: 1a4763ae4bd1537ab0a254d4a0ebcb5ddd56930d
2
+ SHA256:
3
+ metadata.gz: 3f0d72961e8144605b8f0dbd7953161f17ec4c585c67b3e5bde80d84b3664f1b
4
+ data.tar.gz: 5981d937f60d54993ab6bee595598dbc0b52ac99e38e29ef84f5007661929c5b
5
5
  SHA512:
6
- metadata.gz: 1ff3270acfabe0aebebfd272b3cb6eb27c9c7faea337fb59489898e008095d71dbfb835062e6c99c3b0fbc4b63e909073dd7e9e46231a6c3a0ecf5762f7204ef
7
- data.tar.gz: 53e267bcb71f9283a64bb95df753e26b38058d5283c0b0b01276209fe6a27a07b3906cfbae881734875fca9a987e25fcbda6b3143f44956ef361102296821860
6
+ metadata.gz: ecd7010d94b67e2f0c9f19d2dbde4b6b302481156be2657199d6d9fa98c142807f1b006ddb306a2fd8cb3b2d72b3fd4e1708e34c5fe3541ddd0b2320b5e63112
7
+ data.tar.gz: d56c783b4eed7af9ac5e478cfc2b2154b74644ea03fcc84f9fb7bd54c4e2ac8505355bd0ba0405c96255046232f3eee12c83671ef64173f29097ab859a9e428f
data/.rubocop.yml CHANGED
@@ -1,62 +1,28 @@
1
1
  require:
2
- - 'rubocop-md'
2
+ # add after moving docs to another tool
3
+ - 'standard/cop/semantic_blocks'
4
+ - 'rubocop-md'
5
+
6
+ inherit_gem:
7
+ standard: config/base.yml
8
+
3
9
  AllCops:
4
10
  Exclude:
5
11
  - 'bin/**/*'
6
12
  - 'tmp/**/*'
7
- - 'docs/web/**/*'
8
13
  - 'vendor/**/*'
9
14
  - 'gemfiles/vendor/**/*'
15
+ - 'clowne.gemspec'
10
16
  DisplayCopNames: true
11
- StyleGuideCopsOnly: false
12
- TargetRubyVersion: 2.3
17
+ TargetRubyVersion: 2.5
13
18
 
14
19
  Markdown:
15
20
  WarnInvalid: true
16
21
 
17
- Rails:
18
- Enabled: false
19
-
20
- Naming/AccessorMethodName:
21
- Enabled: false
22
-
23
- Naming/ClassAndModuleCamelCase:
24
- Exclude:
25
- - 'spec/**/*.rb'
26
-
27
- Style/TrivialAccessors:
28
- Enabled: false
29
-
30
- Metrics/LineLength:
31
- Max: 100
32
-
33
- Style/Documentation:
34
- Exclude:
35
- - 'spec/**/*.rb'
36
- - 'README.md'
37
-
38
- Style/SymbolArray:
39
- Enabled: false
40
-
41
- Style/FrozenStringLiteralComment:
42
- Exclude:
43
- - 'spec/**/*.rb'
44
- - 'Gemfile'
45
- - 'Rakefile'
46
- - '*.gemspec'
47
- - 'CHANGELOG.md'
48
- - 'README.md'
49
-
50
- Metrics/BlockLength:
51
- Exclude:
52
- - 'spec/**/*.rb'
53
-
54
- Bundler/OrderedGems:
55
- Enabled: false
56
-
57
- Gemspec/OrderedDependencies:
22
+ Standard/SemanticBlocks:
58
23
  Enabled: false
59
24
 
60
25
  Lint/Void:
61
26
  Exclude:
27
+ - 'docs/README.md'
62
28
  - 'README.md'
data/.travis.yml CHANGED
@@ -1,11 +1,12 @@
1
1
  sudo: false
2
2
  language: ruby
3
+ cache: bundler
3
4
 
4
5
  notifications:
5
6
  email: false
6
7
 
7
8
  before_install:
8
- gem update --system
9
+ - gem install bundler
9
10
 
10
11
  before_script:
11
12
  # Only generate coverage report for the specified job
@@ -15,38 +16,30 @@ before_script:
15
16
  script:
16
17
  - bundle exec rake
17
18
  - if [ "$CC_REPORT" == "true" ]; then ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT; fi
18
- - if [ "$DEPLOY_ME" == "true" ]; then (cd ./docs/web && yarn && yarn run build); fi
19
19
 
20
20
  matrix:
21
21
  fast_finish: true
22
22
  include:
23
23
  - rvm: ruby-head
24
24
  gemfile: gemfiles/railsmaster.gemfile
25
- - rvm: jruby-9.1.0.0
25
+ - rvm: jruby-9.2.8.0
26
26
  gemfile: gemfiles/jruby.gemfile
27
- - rvm: 2.5.0
27
+ - rvm: 3.0
28
28
  gemfile: Gemfile
29
- - rvm: 2.4.3
29
+ - rvm: 2.7
30
30
  gemfile: Gemfile
31
- env:
32
- - CC_REPORT=true
33
- - DEPLOY_ME=true
34
- - rvm: 2.4.1
35
- gemfile: gemfiles/activerecord42.gemfile
36
- - rvm: 2.3.1
31
+ - rvm: 2.6.5
32
+ gemfile: Gemfile
33
+ - rvm: 2.5.7
37
34
  gemfile: Gemfile
38
- - rvm: 2.2.0
35
+ - rvm: 2.4.9
39
36
  gemfile: gemfiles/activerecord42.gemfile
37
+ - rvm: truffleruby-head
38
+ gemfile: Gemfile
40
39
  allow_failures:
41
40
  - rvm: ruby-head
42
41
  gemfile: gemfiles/railsmaster.gemfile
43
- - rvm: jruby-9.1.0.0
42
+ - rvm: jruby-9.2.8.0
44
43
  gemfile: gemfiles/jruby.gemfile
45
- deploy:
46
- provider: pages
47
- skip_cleanup: true
48
- github_token: $GITHUB_TOKEN
49
- local_dir: "./docs/web/build/clowne"
50
- on:
51
- branch: master
52
- condition: $DEPLOY_ME = true
44
+ - rvm: truffleruby-head
45
+ gemfile: Gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Change log
2
2
 
3
+ ## 1.1.0 (2019-03-20)
4
+
5
+
6
+ - Add `after_clone` declaration. ([@elardo][])
7
+ - Add opporotunity to include belongs_to association for active_record adapter. ([@madding][])
8
+
9
+ ## 1.0.0 (2019-02-26)
10
+
11
+ - Return `Operation` instance as a rusult of cloning. ([@ssnickolay][])
12
+
13
+ See [migration guide](https://clowne.evilmartians.io/docs/from_v02_to_v10.html)
14
+
15
+ - Add `after_persist` declaration. ([@ssnickolay][], [@palkan][])
16
+
17
+ - Unify interface between adapters. ([@ssnickolay][])
18
+
19
+ - Deprecate `Operation#save` and `Operation#save!` methods. ([@ssnickolay][])
20
+
21
+ - Improve Docs ([@ssnickolay][], [@palkan][])
22
+
23
+ ## 0.2.0 (2018-02-21)
24
+
25
+ - Add `Cloner#partial_apply` method. ([@palkan][])
26
+
27
+ - Add RSpec matchers `clone_association` / `clone_associations`. ([@palkan][])
28
+
29
+ - [[#15](https://github.com/palkan/clowne/issues/15)] Add control over nested params. ([@ssnickolay][])
30
+
3
31
  ## 0.1.0 (2018-02-01)
4
32
 
5
33
  - Add `init_as` declaration. ([@palkan][])
@@ -14,3 +42,5 @@
14
42
 
15
43
  [@palkan]: https://github.com/palkan
16
44
  [@ssnickolay]: https://github.com/ssnickolay
45
+ [@elardo]: https://github.com/elardo
46
+ [@madding]: https://github.com/madding
data/Gemfile CHANGED
@@ -1,15 +1,19 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in clowne.gemspec
4
4
  gemspec
5
5
 
6
- gem 'pry-byebug'
7
- gem 'sqlite3'
8
- gem 'activerecord', '>= 5.0'
9
- gem 'sequel', '>= 5.0'
10
- gem 'simplecov'
6
+ gem "pry-byebug", platform: :mri
11
7
 
12
- local_gemfile = 'Gemfile.local'
8
+ gem "sqlite3", "~> 1.4.1", platform: :ruby
9
+ gem "activerecord-jdbcsqlite3-adapter", "~> 50.0", platform: :jruby
10
+ gem "jdbc-sqlite3", platform: :jruby
11
+
12
+ gem "activerecord", ">= 6.0", "< 6.2.0"
13
+ gem "sequel", ">= 5.0"
14
+ gem "simplecov"
15
+
16
+ local_gemfile = "Gemfile.local"
13
17
 
14
18
  if File.exist?(local_gemfile)
15
19
  eval(File.read(local_gemfile)) # rubocop:disable Security/Eval
data/README.md CHANGED
@@ -1,14 +1,17 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/clowne.svg)](https://badge.fury.io/rb/clowne)
2
- [![Build Status](https://travis-ci.org/palkan/clowne.svg?branch=master)](https://travis-ci.org/palkan/clowne)
3
- [![Test Coverage](https://codeclimate.com/github/palkan/clowne/badges/coverage.svg)](https://codeclimate.com/github/palkan/clowne/coverage)
4
- [![Docs](https://img.shields.io/readthedocs/pip.svg)](https://palkan.github.io/clowne)
2
+ [![Build Status](https://travis-ci.org/clowne-rb/clowne.svg?branch=master)](https://travis-ci.org/clowne-rb/clowne)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/9143c4f91e9d1d2a4bd1/test_coverage)](https://codeclimate.com/github/clowne-rb/clowne/test_coverage)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/9143c4f91e9d1d2a4bd1/maintainability)](https://codeclimate.com/github/clowne-rb/clowne/maintainability)
5
+ [![Docs](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://clowne.evilmartians.io)
5
6
 
6
7
  # Clowne
7
8
 
8
- **NOTE**: this is the documentation for pre-release version **0.1.0.beta1**.
9
-
10
9
  A flexible gem for cloning your models. Clowne focuses on ease of use and provides the ability to connect various ORM adapters.
11
10
 
11
+ 📖 Read [Evil Martians Chronicles](https://evilmartians.com/chronicles/clowne-clone-ruby-models-with-a-smile) to learn about possible use cases.
12
+
13
+ 📑 [Documentation](https://clowne.evilmartians.io)
14
+
12
15
  <a href="https://evilmartians.com/">
13
16
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
14
17
 
@@ -24,7 +27,7 @@ gem install clowne
24
27
  Or add this line to your application's Gemfile:
25
28
 
26
29
  ```ruby
27
- gem 'clowne'
30
+ gem "clowne"
28
31
  ```
29
32
 
30
33
  ## Quick Start
@@ -42,6 +45,16 @@ class User < ActiveRecord::Base
42
45
  has_one :profile
43
46
  has_many :posts
44
47
  end
48
+
49
+ class Profile < ActiveRecord::Base
50
+ # create_table :profiles do |t|
51
+ # t.string :name
52
+ # end
53
+ end
54
+
55
+ class Post < ActiveRecord::Base
56
+ # create_table :posts
57
+ end
45
58
  ```
46
59
 
47
60
  Let's declare our cloners first:
@@ -56,7 +69,7 @@ class UserCloner < Clowne::Cloner
56
69
  nullify :login
57
70
 
58
71
  # params here is an arbitrary Hash passed into cloner
59
- finalize do |_source, record, params|
72
+ finalize do |_source, record, **params|
60
73
  record.email = params[:email]
61
74
  end
62
75
  end
@@ -72,13 +85,20 @@ Now you can use `UserCloner` to clone existing records:
72
85
 
73
86
  ```ruby
74
87
  user = User.last
75
- #=> <#User(login: 'clown', email: 'clown@circus.example.com')>
88
+ # => <#User id: 1, login: 'clown', email: 'clown@circus.example.com'>
89
+
90
+ operation = UserCloner.call(user, email: "fake@example.com")
91
+ # => <#Clowne::Utils::Operation...>
92
+
93
+ operation.to_record
94
+ # => <#User id: nil, login: nil, email: 'fake@example.com'>
95
+
96
+ operation.persist!
97
+ # => true
76
98
 
77
- cloned = UserCloner.call(user, email: 'fake@example.com')
78
- cloned.persisted?
79
- # => false
99
+ cloned = operation.to_record
100
+ # => <#User id: 2, login: nil, email: 'fake@example.com'>
80
101
 
81
- cloned.save!
82
102
  cloned.login
83
103
  # => nil
84
104
  cloned.email
@@ -91,20 +111,20 @@ cloned.profile.name
91
111
  # => nil
92
112
  ```
93
113
 
94
- Take a look at our [documentation](https://palkan.github.io/clowne) for more information!
114
+ Take a look at our [documentation](https://clowne.evilmartians.io) for more info!
95
115
 
96
116
  ### Supported ORM adapters
97
117
 
98
- Adapter |1:1 | 1:M | M:M |
99
- ------------------------------------------|------------|-------------|-------------------------|
100
- [Active Record](https://palkan.github.io/clowne/docs/active_record.html) | has_one | has_many | has_and_belongs_to_many |
101
- [Sequel](https://palkan.github.io/clowne/docs/sequel.html) | one_to_one | one_to_many | many_to_many |
118
+ Adapter |1:1 |*:1 | 1:M | M:M |
119
+ ------------------------------------------|------------|------------|-------------|-------------------------|
120
+ [Active Record](https://clowne.evilmartians.io/#/active_record) | has_one | belongs_to | has_many | has_and_belongs_to|
121
+ [Sequel](https://clowne.evilmartians.io/#/sequel) | one_to_one | - | one_to_many | many_to_many |
102
122
 
103
123
  ## Maintainers
104
124
 
105
125
  - [Vladimir Dementyev](https://github.com/palkan)
106
126
 
107
- - [Sverchkov Nikolay](https://github.com/ssnickolay)
127
+ - [Nikolay Sverchkov](https://github.com/ssnickolay)
108
128
 
109
129
  ## License
110
130
 
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'rubocop/rake_task'
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+ require "rubocop/rake_task"
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
6
  RuboCop::RakeTask.new
data/clowne.gemspec CHANGED
@@ -1,4 +1,4 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'clowne/version'
4
4
 
@@ -8,22 +8,29 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Vladimir Dementyev', 'Sverchkov Nikolay']
9
9
  spec.email = ['palkan@evilmartians.com', 'ssnikolay@gmail.com']
10
10
 
11
- spec.summary = 'A flexible gem for cloning your models.'
11
+ spec.summary = 'A flexible gem for cloning your models'
12
12
  spec.description = 'A flexible gem for cloning your models.'
13
- spec.homepage = 'https://github.com/palkan/clowne'
13
+ spec.homepage = 'https://github.com/clowne-rb/clowne'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
18
18
  end
19
- spec.bindir = 'exe'
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.metadata = {
20
+ "bug_tracker_uri" => "http://github.com/clowne-rb/clowne/issues",
21
+ "changelog_uri" => "https://github.com/clowne-rb/clowne/blob/master/CHANGELOG.md",
22
+ "documentation_uri" => "https://clowne.evilmartians.io/",
23
+ "homepage_uri" => "https://clowne.evilmartians.io/",
24
+ "source_code_uri" => "http://github.com/clowne-rb/clowne"
25
+ }
21
26
  spec.require_paths = ['lib']
22
27
 
23
- spec.add_development_dependency 'bundler', '~> 1.14'
24
- spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'bundler', '~> 2.0'
29
+ spec.add_development_dependency 'rake', '~> 12.3', '>= 12.3.3'
25
30
  spec.add_development_dependency 'rspec', '~> 3.0'
26
- spec.add_development_dependency 'factory_bot', '~> 4.8'
27
- spec.add_development_dependency 'rubocop', '~> 0.51'
28
- spec.add_development_dependency 'rubocop-md', '~> 0.2'
31
+ spec.add_development_dependency 'factory_bot', '~> 5'
32
+ spec.add_development_dependency 'rubocop', '~> 0.75.0'
33
+ spec.add_development_dependency 'rubocop-md', '~> 0.3.0'
34
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.36.0'
35
+ spec.add_development_dependency 'standard', '~> 0.1.5'
29
36
  end
data/docs/.nojekyll ADDED
File without changes
data/docs/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
- Metrics/LineLength:
2
- Max: 100
1
+ inherit_gem:
2
+ standard: config/base.yml
3
3
 
4
4
  Lint/Void:
5
5
  Exclude:
@@ -8,5 +8,11 @@ Lint/Void:
8
8
  Metrics/AbcSize:
9
9
  Enabled: false
10
10
 
11
+ Standard/SemanticBlocks:
12
+ Enabled: false
13
+
11
14
  Metrics/BlockLength:
12
15
  Enabled: false
16
+
17
+ Metrics/LineLength:
18
+ Enabled: false
data/docs/CNAME ADDED
@@ -0,0 +1 @@
1
+ clowne.evilmartians.io
data/docs/README.md ADDED
@@ -0,0 +1,131 @@
1
+ [![Gem Version](https://badge.fury.io/rb/clowne.svg)](https://badge.fury.io/rb/clowne)
2
+ [![Build Status](https://travis-ci.org/clowne-rb/clowne.svg?branch=master)](https://travis-ci.org/clowne-rb/clowne)
3
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/9143c4f91e9d1d2a4bd1/test_coverage)](https://codeclimate.com/github/clowne-rb/clowne/test_coverage)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/9143c4f91e9d1d2a4bd1/maintainability)](https://codeclimate.com/github/clowne-rb/clowne/maintainability)
5
+ [![Docs](https://img.shields.io/badge/docs-link-brightgreen.svg)](https://clowne.evilmartians.io)
6
+
7
+ # Clowne
8
+
9
+ A flexible gem for cloning your models. Clowne focuses on ease of use and provides the ability to connect various ORM adapters.
10
+
11
+ 📖 Read [Evil Martians Chronicles](https://evilmartians.com/chronicles/clowne-clone-ruby-models-with-a-smile) to learn about possible use cases.
12
+
13
+ 📑 [Documentation](https://clowne.evilmartians.io)
14
+
15
+ <a href="https://evilmartians.com/">
16
+ <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
17
+
18
+
19
+ ## Installation
20
+
21
+ To install Clowne with RubyGems:
22
+
23
+ ```ruby
24
+ gem install clowne
25
+ ```
26
+
27
+ Or add this line to your application's Gemfile:
28
+
29
+ ```ruby
30
+ gem "clowne"
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ Assume that you have the following model:
36
+
37
+ ```ruby
38
+ class User < ActiveRecord::Base
39
+ # create_table :users do |t|
40
+ # t.string :login
41
+ # t.string :email
42
+ # t.timestamps null: false
43
+ # end
44
+
45
+ has_one :profile
46
+ has_many :posts
47
+ end
48
+
49
+ class Profile < ActiveRecord::Base
50
+ # create_table :profiles do |t|
51
+ # t.string :name
52
+ # end
53
+ end
54
+
55
+ class Post < ActiveRecord::Base
56
+ # create_table :posts
57
+ end
58
+ ```
59
+
60
+ Let's declare our cloners first:
61
+
62
+ ```ruby
63
+ class UserCloner < Clowne::Cloner
64
+ adapter :active_record
65
+
66
+ include_association :profile, clone_with: SpecialProfileCloner
67
+ include_association :posts
68
+
69
+ nullify :login
70
+
71
+ # params here is an arbitrary Hash passed into cloner
72
+ finalize do |_source, record, **params|
73
+ record.email = params[:email]
74
+ end
75
+ end
76
+
77
+ class SpecialProfileCloner < Clowne::Cloner
78
+ adapter :active_record
79
+
80
+ nullify :name
81
+ end
82
+ ```
83
+
84
+ Now you can use `UserCloner` to clone existing records:
85
+
86
+ ```ruby
87
+ user = User.last
88
+ # => <#User id: 1, login: 'clown', email: 'clown@circus.example.com'>
89
+
90
+ operation = UserCloner.call(user, email: "fake@example.com")
91
+ # => <#Clowne::Utils::Operation...>
92
+
93
+ operation.to_record
94
+ # => <#User id: nil, login: nil, email: 'fake@example.com'>
95
+
96
+ operation.persist!
97
+ # => true
98
+
99
+ cloned = operation.to_record
100
+ # => <#User id: 2, login: nil, email: 'fake@example.com'>
101
+
102
+ cloned.login
103
+ # => nil
104
+ cloned.email
105
+ # => "fake@example.com"
106
+
107
+ # associations:
108
+ cloned.posts.count == user.posts.count
109
+ # => true
110
+ cloned.profile.name
111
+ # => nil
112
+ ```
113
+
114
+ Take a look at our [documentation](https://clowne.evilmartians.io) for more info!
115
+
116
+ ### Supported ORM adapters
117
+
118
+ Adapter |1:1 |*:1 | 1:M | M:M |
119
+ ------------------------------------------|------------|------------|-------------|-------------------------|
120
+ [Active Record](active_record) | has_one | belongs_to | has_many | has_and_belongs_to|
121
+ [Sequel](sequel) | one_to_one | - | one_to_many | many_to_many |
122
+
123
+ ## Maintainers
124
+
125
+ - [Vladimir Dementyev](https://github.com/palkan)
126
+
127
+ - [Nikolay Sverchkov](https://github.com/ssnickolay)
128
+
129
+ ## License
130
+
131
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).