deep_cloneable_checked 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d4e5dde0e5922d0b2eb088d978ac52a98e18d71f1bfd84d0a660d4e9118d6a9f
4
+ data.tar.gz: d5e02afde0d474a5f9d1059de864899505670d57e93c6c0b91b153474d5f6058
5
+ SHA512:
6
+ metadata.gz: 4b355de3f95ba257137c67346fb9144d5d31757a50d5379cf20d0c2e35c3755b160ae400bbbf287196ef03310964aa78bda80ed866accfadac7cff3c3b9a9c23
7
+ data.tar.gz: 21bc6b8c52a092b392cc032f1396870f7ebb7bab72ed8adc692e49f9ee2f8c5904803a1d3cc64077987c3577f0f66e358d4ff880bfa9bbd9f4b7a9c3cc248b4d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.4
6
+ before_install: gem install bundler -v 2.1.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2017-06-20
10
+ ### Added
11
+ - Deep clone checked method by [@kaori-kk](https://github.com/kaori-kk) [@tinco](https://github.com/tinco).
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kaori@aeroscan.nl. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in deep_cloneable_checked.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "sqlite3"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ deep_cloneable_checked (0.1.0)
5
+ deep_cloneable (~> 3.2.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activemodel (7.0.3.1)
11
+ activesupport (= 7.0.3.1)
12
+ activerecord (7.0.3.1)
13
+ activemodel (= 7.0.3.1)
14
+ activesupport (= 7.0.3.1)
15
+ activesupport (7.0.3.1)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
+ i18n (>= 1.6, < 2)
18
+ minitest (>= 5.1)
19
+ tzinfo (~> 2.0)
20
+ concurrent-ruby (1.1.10)
21
+ deep_cloneable (3.2.0)
22
+ activerecord (>= 3.1.0, < 8)
23
+ diff-lcs (1.5.0)
24
+ i18n (1.12.0)
25
+ concurrent-ruby (~> 1.0)
26
+ minitest (5.16.2)
27
+ rake (12.3.3)
28
+ rspec (3.11.0)
29
+ rspec-core (~> 3.11.0)
30
+ rspec-expectations (~> 3.11.0)
31
+ rspec-mocks (~> 3.11.0)
32
+ rspec-core (3.11.0)
33
+ rspec-support (~> 3.11.0)
34
+ rspec-expectations (3.11.0)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.11.0)
37
+ rspec-mocks (3.11.1)
38
+ diff-lcs (>= 1.2.0, < 2.0)
39
+ rspec-support (~> 3.11.0)
40
+ rspec-support (3.11.0)
41
+ sqlite3 (1.4.4)
42
+ tzinfo (2.0.5)
43
+ concurrent-ruby (~> 1.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ deep_cloneable_checked!
50
+ rake (~> 12.0)
51
+ rspec (~> 3.0)
52
+ sqlite3
53
+
54
+ BUNDLED WITH
55
+ 2.1.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Kaori Kohama
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # DeepCloneableChecked
2
+
3
+ Use this gem to enforce explicit mentions of all associations of model you want to `deep_clone` using the `deep_clone_checked` method.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'deep_cloneable_checked'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install deep_cloneable_checked
20
+
21
+ ## Usage
22
+
23
+ Call the `deep_clone_checked` method as you would normally call the `deep_clone` method from [deep_cloneable](https://github.com/moiristo/deep_cloneable) with `:include` and add `:exclude` for any associations you do not want to clone.
24
+
25
+ ```ruby
26
+ human = Animal::Human.create :name => 'Michael'
27
+ human2 = Animal::Human.create :name => 'Jack'
28
+ chicken1 = Animal::Chicken.create :name => 'Chick1'
29
+ chicken2 = Animal::Chicken.create :name => 'Chick2'
30
+ human.chickens << [chicken1, chicken2]
31
+ human2.chickens << [chicken1, chicken2]
32
+
33
+ deep_clone_human = human.deep_clone_checked(:include => :ownerships, :exclude => [:pigs, {:ownerships=>[:human, :chicken]}, :chickens])
34
+ ```
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/aeroscan-nl/deep_cloneable_checked. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/aeroscan-nl/deep_cloneable_checked/blob/main/CODE_OF_CONDUCT.md).
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
50
+
51
+ ## Code of Conduct
52
+
53
+ Everyone interacting in the DeepCloneableChecked project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/aeroscan-nl/deep_cloneable_checked/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "deep_cloneable_checked"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/deep_cloneable_checked/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "deep_cloneable_checked"
5
+ spec.version = DeepCloneableChecked::VERSION
6
+ spec.authors = ["Kaori Kohama", "Tinco Andringa"]
7
+ spec.email = ["kaori@aeroscan.nl", "tinco@aeroscan.nl"]
8
+
9
+ spec.summary = %q{Use this gem to enforce all associations are explicitly cloned or excluded with deep_clone}
10
+ spec.description = %q{Use this gem to enforce all associations are explicitly cloned or excluded with deep_clone}
11
+ spec.homepage = "https://github.com/aeroscan-nl/deep_cloneable_checked"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+ spec.metadata["source_code_uri"] = "https://github.com/aeroscan-nl/deep_cloneable_checked"
17
+ spec.metadata["changelog_uri"] = "https://github.com/aeroscan-nl/deep_cloneable_checked/blob/main/CHANGELOG.md"
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
22
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.add_runtime_dependency('deep_cloneable', '~> 3.2.0')
28
+ end
@@ -0,0 +1,84 @@
1
+ module DeepCloneableChecked
2
+ module DeepCloneChecked
3
+ def deep_clone_checked(options)
4
+ if options[:include].is_a?(Hash) || options[:include].is_a?(Symbol)
5
+ options[:include] = [options[:include]]
6
+ end
7
+
8
+ if options[:exclude].is_a?(Hash) || options[:exclude].is_a?(Symbol)
9
+ options[:exclude] = [options[:exclude]]
10
+ end
11
+
12
+ missing = validate_clone_check(options)
13
+
14
+ unless missing.empty?
15
+ raise MissingAssociationError, "Not all associations cloned: #{missing.inspect}"
16
+ end
17
+
18
+ deep_clone(options)
19
+ end
20
+
21
+ def validate_clone_check(options)
22
+ find_symbol_or_hash = lambda do |options, association_name|
23
+
24
+ result = options.find do |option|
25
+ if option.is_a? Symbol
26
+ option.to_s == association_name
27
+ elsif option.is_a? Hash
28
+ option[association_name.to_sym]
29
+ else
30
+ nil
31
+ end
32
+ end
33
+ result
34
+ end
35
+
36
+ check_missing = lambda do |klass, includes, excludes|
37
+ # puts "-----------\n klass: #{klass.name}, includes: #{includes.inspect}, excludes: #{excludes.inspect}"
38
+ associations = klass.reflections
39
+
40
+ associations.map do |association_name, reflection|
41
+
42
+ to_exclude = find_symbol_or_hash[excludes, association_name]
43
+ if to_exclude.is_a? Symbol
44
+ next_excludes = []
45
+ elsif to_exclude.is_a? Array
46
+ next_excludes = to_exclude
47
+ elsif to_exclude.nil?
48
+ next_excludes = []
49
+ else
50
+ next_excludes = to_exclude[association_name.to_sym]
51
+ end
52
+
53
+ inclusion = find_symbol_or_hash[includes, association_name]
54
+
55
+ if inclusion.is_a? Symbol
56
+ # puts "inclusion: #{inclusion.inspect}, association_name: #{association_name}"
57
+ result = check_missing[reflection.klass, [], next_excludes]
58
+ if !result.blank?
59
+ # puts "missing from #{reflection.klass.name}, #{association_name}"
60
+ Hash[association_name.to_sym, result]
61
+ end
62
+ elsif inclusion.is_a? Hash
63
+ # puts "inclusion: #{inclusion.inspect}, association_name: #{association_name}"
64
+ result = check_missing[reflection.klass, [inclusion[association_name.to_sym]], next_excludes]
65
+ if !result.blank?
66
+ # puts "missing from #{reflection.klass.name}, #{association_name}"
67
+ Hash[association_name.to_sym, result]
68
+ end
69
+ else
70
+ # puts "No inclusion for #{association_name}, inclusion: #{inclusion.inspect}, to_exclude: #{to_exclude.inspect}"
71
+ if to_exclude.is_a? Symbol
72
+ nil
73
+ else
74
+ # puts "No exclusion either"
75
+ association_name.to_sym
76
+ end
77
+ end
78
+ end.compact
79
+ end
80
+
81
+ check_missing[self.class, options[:include] || [], options[:exclude] || []]
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module DeepCloneableChecked
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "deep_cloneable_checked/version"
2
+ require 'deep_cloneable'
3
+ require 'deep_cloneable_checked/deep_clone_checked'
4
+
5
+ module DeepCloneableChecked
6
+ class MissingAssociationError < StandardError; end
7
+ end
8
+
9
+ ActiveSupport.on_load :active_record do
10
+ include DeepCloneableChecked::DeepCloneChecked
11
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: deep_cloneable_checked
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kaori Kohama
8
+ - Tinco Andringa
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2022-08-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: deep_cloneable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 3.2.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 3.2.0
28
+ description: Use this gem to enforce all associations are explicitly cloned or excluded
29
+ with deep_clone
30
+ email:
31
+ - kaori@aeroscan.nl
32
+ - tinco@aeroscan.nl
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - ".gitignore"
38
+ - ".rspec"
39
+ - ".travis.yml"
40
+ - CHANGELOG.md
41
+ - CODE_OF_CONDUCT.md
42
+ - Gemfile
43
+ - Gemfile.lock
44
+ - LICENSE.txt
45
+ - README.md
46
+ - Rakefile
47
+ - bin/console
48
+ - bin/setup
49
+ - deep_cloneable_checked.gemspec
50
+ - lib/deep_cloneable_checked.rb
51
+ - lib/deep_cloneable_checked/deep_clone_checked.rb
52
+ - lib/deep_cloneable_checked/version.rb
53
+ homepage: https://github.com/aeroscan-nl/deep_cloneable_checked
54
+ licenses:
55
+ - MIT
56
+ metadata:
57
+ homepage_uri: https://github.com/aeroscan-nl/deep_cloneable_checked
58
+ source_code_uri: https://github.com/aeroscan-nl/deep_cloneable_checked
59
+ changelog_uri: https://github.com/aeroscan-nl/deep_cloneable_checked/blob/main/CHANGELOG.md
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.1.6
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Use this gem to enforce all associations are explicitly cloned or excluded
79
+ with deep_clone
80
+ test_files: []