record_diff 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 29c632816fed5fc31fda26b8bcb9c0d30b519d8c9b6d60b9f24d678e1d21710b
4
+ data.tar.gz: ff03c14cd3d88e7337469c09087e1ab03f7393deb0d85e4ce3c44695d2917ea7
5
+ SHA512:
6
+ metadata.gz: c0065a822e6a303a54bcdba9d8fec50f68bf150a5921613212d4fcc0d4aaec747332b100ce1e9931c273adcd361fa16dc3e9be47c51426ff29ba8fd0dff242cf
7
+ data.tar.gz: 679afedd3fe3e20a7e37b4181cc0263b474f79af7605bc40756a24c140192db1fbcce0d8b2c220042d9d4aa27486dafd1449c3acef83caacc28e16d66e49440a
@@ -0,0 +1,78 @@
1
+ # Ruby CircleCI 2.0 configuration file
2
+ #
3
+ # Check https://circleci.com/docs/2.0/language-ruby/ for more details
4
+ #
5
+ version: 2
6
+ jobs:
7
+ build:
8
+ docker:
9
+ # specify the version you desire here
10
+ - image: circleci/ruby:2.5.1-node-browsers
11
+
12
+ # Specify service dependencies here if necessary
13
+ # CircleCI maintains a library of pre-built images
14
+ # documented at https://circleci.com/docs/2.0/circleci-images/
15
+ # - image: circleci/postgres:9.4
16
+
17
+ working_directory: ~/repo
18
+
19
+ steps:
20
+ - checkout
21
+ - run:
22
+ name: Configure Bundler
23
+ command: |
24
+ echo 'export BUNDLER_VERSION=$(cat Gemfile.lock | tail -1 | tr -d " ")' >> $BASH_ENV
25
+ source $BASH_ENV
26
+ gem install bundler
27
+ - run:
28
+ name: Which bundler?
29
+ command: bundle -v
30
+
31
+ # Download and cache dependencies
32
+ - restore_cache:
33
+ keys:
34
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
35
+ # fallback to using the latest cache if no exact match is found
36
+ - v1-dependencies-
37
+
38
+ - run:
39
+ name: install dependencies
40
+ command: |
41
+ bundle install --jobs=4 --retry=3 --path vendor/bundle
42
+
43
+ - save_cache:
44
+ paths:
45
+ - ./vendor/bundle
46
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
47
+
48
+ - run:
49
+ name: Rubocop
50
+ command: |
51
+ test_reports_dir=/tmp/test-results
52
+ mkdir -p $test_reports_dir
53
+ junit_formatter_ruby=$(bundle show rubocop-junit-formatter)/lib/rubocop/formatter/junit_formatter.rb
54
+ bundle exec rubocop -L | \
55
+ circleci tests split --split-by=timings --timings-type=filename | \
56
+ xargs bundle exec rubocop -D -r $junit_formatter_ruby -c .rubocop.yml --format RuboCop::Formatter::JUnitFormatter --out $test_reports_dir/rubocop.xml
57
+
58
+ # run tests!
59
+ - run:
60
+ name: RSpec
61
+ command: |
62
+ mkdir -p /tmp/test-results
63
+ TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | \
64
+ circleci tests split --split-by=timings)"
65
+
66
+ bundle exec rspec \
67
+ --format progress \
68
+ --format RspecJunitFormatter \
69
+ --out /tmp/test-results/rspec.xml \
70
+ --format progress \
71
+ $TEST_FILES
72
+
73
+ # collect reports
74
+ - store_test_results:
75
+ path: /tmp/test-results
76
+ - store_artifacts:
77
+ path: /tmp/test-results
78
+ destination: test-results
data/.gitignore ADDED
@@ -0,0 +1,62 @@
1
+ # rspec failure tracking
2
+ .rspec_status
3
+ ### Ruby template
4
+ *.gem
5
+ *.rbc
6
+ /.config
7
+ /coverage/
8
+ /InstalledFiles
9
+ /pkg/
10
+ /spec/reports/
11
+ /spec/examples.txt
12
+ /test/tmp/
13
+ /test/version_tmp/
14
+ /tmp/
15
+
16
+ # Used by dotenv library to load environment variables.
17
+ # .env
18
+
19
+ # Ignore Byebug command history file.
20
+ .byebug_history
21
+
22
+ ## Specific to RubyMotion:
23
+ .dat*
24
+ .repl_history
25
+ build/
26
+ *.bridgesupport
27
+ build-iPhoneOS/
28
+ build-iPhoneSimulator/
29
+
30
+ ## Specific to RubyMotion (use of CocoaPods):
31
+ #
32
+ # We recommend against adding the Pods directory to your .gitignore. However
33
+ # you should judge for yourself, the pros and cons are mentioned at:
34
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
35
+ #
36
+ # vendor/Pods/
37
+
38
+ ## Documentation cache and generated files:
39
+ /.yardoc/
40
+ /_yardoc/
41
+ /doc/
42
+ /rdoc/
43
+
44
+ ## Environment normalization:
45
+ /.bundle/
46
+ /vendor/bundle
47
+ /lib/bundler/man/
48
+
49
+ # for a library or gem, you might want to ignore these files since the code is
50
+ # intended to run in multiple environments; otherwise, check them in:
51
+ # Gemfile.lock
52
+ # .ruby-version
53
+ # .ruby-gemset
54
+
55
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
56
+ .rvmrc
57
+
58
+ ### JetBrains template
59
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
60
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
61
+ .idea
62
+
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ Metrics/BlockLength:
5
+ Exclude:
6
+ - spec/**/*
7
+ - "*.gemspec"
8
+ RSpec/FilePath:
9
+ Enabled: false
10
+ RSpec/ExampleLength:
11
+ Max: 10
12
+ RSpec/MultipleExpectations:
13
+ Max: 3
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 2.0.2
@@ -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 richard.seviora@gmail.com. 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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in record_diff.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,65 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ record_diff (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ jaro_winkler (1.5.3)
13
+ method_source (0.9.2)
14
+ parallel (1.17.0)
15
+ parser (2.6.3.0)
16
+ ast (~> 2.4.0)
17
+ pry (0.12.2)
18
+ coderay (~> 1.1.0)
19
+ method_source (~> 0.9.0)
20
+ rainbow (3.0.0)
21
+ rake (10.5.0)
22
+ rspec (3.8.0)
23
+ rspec-core (~> 3.8.0)
24
+ rspec-expectations (~> 3.8.0)
25
+ rspec-mocks (~> 3.8.0)
26
+ rspec-core (3.8.2)
27
+ rspec-support (~> 3.8.0)
28
+ rspec-expectations (3.8.4)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.8.0)
31
+ rspec-mocks (3.8.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.8.0)
34
+ rspec-support (3.8.2)
35
+ rspec_junit_formatter (0.4.1)
36
+ rspec-core (>= 2, < 4, != 2.12.0)
37
+ rubocop (0.74.0)
38
+ jaro_winkler (~> 1.5.1)
39
+ parallel (~> 1.10)
40
+ parser (>= 2.6)
41
+ rainbow (>= 2.2.2, < 4.0)
42
+ ruby-progressbar (~> 1.7)
43
+ unicode-display_width (>= 1.4.0, < 1.7)
44
+ rubocop-junit-formatter (0.1.4)
45
+ rubocop-rspec (1.35.0)
46
+ rubocop (>= 0.60.0)
47
+ ruby-progressbar (1.10.1)
48
+ unicode-display_width (1.6.0)
49
+
50
+ PLATFORMS
51
+ ruby
52
+
53
+ DEPENDENCIES
54
+ bundler (~> 2.0)
55
+ pry (~> 0.12)
56
+ rake (~> 10.0)
57
+ record_diff!
58
+ rspec (~> 3.0)
59
+ rspec_junit_formatter
60
+ rubocop (~> 0.74)
61
+ rubocop-junit-formatter (~> 0.1.4)
62
+ rubocop-rspec (~> 1.35)
63
+
64
+ BUNDLED WITH
65
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Rich Seviora
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,54 @@
1
+ [![CircleCI](https://circleci.com/gh/richseviora/record-diff/tree/develop.svg?style=svg)](https://circleci.com/gh/richseviora/record-diff/tree/develop)
2
+
3
+ # Record Diff
4
+
5
+ The Record Diff gem allows you to compare and diff two enumerables using a key method. The records can also be transformed and filtered.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'record_diff'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install record_diff
22
+
23
+ ## Usage
24
+
25
+ ### Comparing two enumerables
26
+
27
+
28
+ ### Comparing Two Hashes
29
+ ```ruby
30
+ a = { unchanged: 1, dropped: 2, changed: 3}
31
+ b = { added: 1, unchanged: 1, changed: 4 }
32
+ result = RecordDiff::Matcher.diff_hash(a, b)
33
+ first_change = result.changed.first # => ResultSet::ChangedResult
34
+ first_change.id # :changed
35
+ first_change.before_compare # { unchanged: 1, dropped: 2, changed: 3}
36
+ ```
37
+
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/richseviora/record_diff. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the Record Diff project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/richseviora/record_diff/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'record_diff'
6
+ require 'pry'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ Pry.start
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,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+ require 'record_diff/matcher_options'
5
+
6
+ module RecordDiff
7
+ # Handles matching results.
8
+ class Matcher
9
+ extend Forwardable
10
+ attr_reader :before, :after, :before_grouped, :after_grouped
11
+ # @return [RecordDiff::ResultSet] - the results of the diff operation.
12
+ attr_reader :results
13
+ attr_reader :options
14
+
15
+ def_delegators :options, :before_id, :after_id,
16
+ :before_transform, :after_transform
17
+
18
+ def_delegators :results, :changed, :unchanged, :dropped, :added, :all
19
+
20
+ def self.diff_hash(before:, after:)
21
+ new before: before, after: after,
22
+ options: { before_id: :first, after_id: :first,
23
+ before_transform: :second, after_transform: :second }
24
+ end
25
+
26
+ def initialize(before:, after:, options: {})
27
+ @options = MatcherOptions.new(options)
28
+ @before = before
29
+ @after = after
30
+ process
31
+ end
32
+
33
+ def process
34
+ group_records
35
+ generate_results
36
+ self
37
+ end
38
+
39
+ def key_for_record(record)
40
+ id_method.call(record)
41
+ end
42
+
43
+ def group_records
44
+ @before_grouped = before.group_by { |r| before_id.call r }
45
+ @after_grouped = after.group_by { |r| after_id.call r }
46
+ end
47
+
48
+ def generate_results
49
+ keys = (before_grouped.keys + after_grouped.keys).uniq
50
+ result_ary = keys.map do |key|
51
+ generate_result key, before_grouped[key] || [], after_grouped[key] || []
52
+ end
53
+ result_ary.flatten!
54
+ @results = ResultSet.new(result_ary)
55
+ end
56
+
57
+ # @param [Array] before_ary
58
+ # @param [Array] after_ary
59
+ # @return [Array<RecordDiff::Results::AbstractResult>]
60
+ def generate_result(key, before_ary, after_ary)
61
+ raise "Multiple records to compare with same Key #{key}" if
62
+ before_ary.count > 1 || after_ary.count > 1
63
+
64
+ before_obj = before_ary[0]
65
+ after_obj = after_ary[0]
66
+ [generate_result_obj(key, before_obj, after_obj)]
67
+ end
68
+
69
+ # @return
70
+ def generate_result_obj(key, before, after) # rubocop:disable MethodLength
71
+ before_compare = before ? before_transform.call(before) : nil
72
+ after_compare = after ? after_transform.call(after) : nil
73
+ if before_compare.nil?
74
+ return Results::AddedResult.new id: key,
75
+ after: after,
76
+ after_compare: after_compare
77
+ end
78
+ if after_compare.nil?
79
+ return Results::DroppedResult.new id: key, before: before,
80
+ before_compare: before_compare
81
+ end
82
+
83
+ if before_compare == after_compare
84
+ return Results::UnchangedResult.new(
85
+ id: key,
86
+ before: before, before_compare: before_compare,
87
+ after: after, after_compare: after_compare
88
+ )
89
+ end
90
+
91
+ Results::ChangedResult.new(
92
+ id: key, before: before, before_compare: before_compare,
93
+ after: after, after_compare: after_compare
94
+ )
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ # Handles the creation of Matcher options.
5
+ class MatcherOptions
6
+ DEFAULT_OPTIONS = {
7
+ before_id: :id,
8
+ after_id: :id,
9
+ before_transform: :itself,
10
+ after_transform: :itself
11
+ }.freeze
12
+
13
+ # @return [Proc]
14
+ # @param [Proc,Symbol,Object] arg - symbol or proc
15
+ def self.create_transform_method(arg = :itself)
16
+ return proc { |ary| ary[1] } if arg == :second
17
+ return transform_from_hsh arg if arg.is_a?(Hash)
18
+ return create_proc_chain arg if arg.is_a?(Array)
19
+
20
+ arg.to_proc
21
+ end
22
+
23
+ def self.create_proc_chain(ary)
24
+ procs = ary.map { |a| create_transform_method a }
25
+ proc do |input|
26
+ procs.reduce(input) do |result, next_proc|
27
+ next_proc.call(result)
28
+ end
29
+ end
30
+ end
31
+
32
+ # Creates a proc based on the hash provided.
33
+ def self.transform_from_hsh(hsh)
34
+ return proc { |hash| hash.slice(*hsh[:keys]) } if hsh.keys == [:keys]
35
+
36
+ if hsh.keys == [:attrs]
37
+ return proc do |obj|
38
+ attrs = hsh[:attrs]
39
+ Hash[attrs.collect { |k| [k, obj.send(k)] }]
40
+ end
41
+ end
42
+
43
+ raise StandardError, 'Unexpected Hash Config'
44
+ end
45
+
46
+ attr_reader :before_id, :after_id, :options
47
+
48
+ def initialize(options = {})
49
+ @options = DEFAULT_OPTIONS.merge options
50
+ @before_id = @options[:before_id].to_proc
51
+ @after_id = @options[:after_id].to_proc
52
+ end
53
+
54
+ def before_transform
55
+ @before_transform ||=
56
+ self.class.create_transform_method options[:before_transform]
57
+ end
58
+
59
+ def after_transform
60
+ @after_transform ||=
61
+ self.class.create_transform_method options[:after_transform]
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ # Convenience wrapper for result array.
5
+ class ResultSet < Array
6
+ def initialize(results)
7
+ super results
8
+ end
9
+
10
+ def unchanged
11
+ select(&:unchanged?)
12
+ end
13
+
14
+ def changed
15
+ select(&:changed?)
16
+ end
17
+
18
+ def added
19
+ select(&:added?)
20
+ end
21
+
22
+ def dropped
23
+ select(&:dropped?)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ module Results
5
+ # Abstract result implementation.
6
+ class AbstractResult
7
+ attr_reader :id, :before_original, :after_original
8
+ # @return [Hash]
9
+ attr_reader :before_compare, :after_compare
10
+ # @return [Array<Symbol>, Proc]
11
+ attr_reader :before_transform, :record_diff
12
+
13
+ alias before before_compare
14
+ alias after after_compare
15
+
16
+ def added?
17
+ false
18
+ end
19
+
20
+ def unchanged?
21
+ false
22
+ end
23
+
24
+ def changed?
25
+ false
26
+ end
27
+
28
+ def dropped?
29
+ false
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ module Results
5
+ # When a record has been added.
6
+ class AddedResult < AbstractResult
7
+ def initialize(id:, after:, after_compare:)
8
+ @id = id
9
+ @after_original = after
10
+ @after_compare = after_compare
11
+ end
12
+
13
+ def added?
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ module Results
5
+ # If the ID can be matched, but the two records have changed.
6
+ class ChangedResult < AbstractResult
7
+ def initialize(id:, after:, before:, after_compare:, before_compare:)
8
+ @id = id
9
+ @after_original = after
10
+ @after_compare = after_compare
11
+ @before_original = before
12
+ @before_compare = before_compare
13
+ end
14
+
15
+ def changed?
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ module Results
5
+ # Dropped result, if the ID is not matched in the new data.
6
+ class DroppedResult < AbstractResult
7
+ def initialize(id:, before:, before_compare:)
8
+ @id = id
9
+ @before_original = before
10
+ @before_compare = before_compare
11
+ end
12
+
13
+ def dropped?
14
+ true
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ module Results
5
+ # If the ID can be matched and the records haven't changed.
6
+ class UnchangedResult < AbstractResult
7
+ def initialize(id:, after:, before:, after_compare:, before_compare:)
8
+ @id = id
9
+ @before_original = before
10
+ @before_compare = before_compare
11
+ @after_original = after
12
+ @after_compare = after_compare
13
+ end
14
+
15
+ def unchanged?
16
+ true
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'results/abstract_result'
4
+ require_relative 'results/added_result'
5
+ require_relative 'results/changed_result'
6
+ require_relative 'results/dropped_result'
7
+ require_relative 'results/unchanged_result'
8
+
9
+ module RecordDiff
10
+ # Contains Result types.
11
+ module Results
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RecordDiff
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'record_diff/version'
4
+ require_relative 'record_diff/results'
5
+ require_relative 'record_diff/result_set'
6
+ require_relative 'record_diff/matcher'
7
+
8
+ module RecordDiff
9
+ class Error < StandardError; end
10
+ # Your code goes here...
11
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'record_diff/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'record_diff'
9
+ spec.version = RecordDiff::VERSION
10
+ spec.authors = ['Rich Seviora']
11
+ spec.email = ['richard.seviora@gmail.com']
12
+
13
+ spec.summary = 'Reconciles items'
14
+ spec.homepage = 'http://www.canada.com'
15
+ spec.license = 'MIT'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'http://canada.com'
19
+ spec.metadata['changelog_uri'] = 'http://canada.com'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added
23
+ # into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ end
29
+ spec.bindir = 'exe'
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_development_dependency 'bundler', '~> 2.0'
34
+ spec.add_development_dependency 'pry', '~> 0.12'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec_junit_formatter'
38
+ spec.add_development_dependency 'rubocop', '~> 0.74'
39
+ spec.add_development_dependency 'rubocop-junit-formatter', '~> 0.1.4'
40
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.35'
41
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: record_diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rich Seviora
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec_junit_formatter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.74'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.74'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-junit-formatter
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.4
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.1.4
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '1.35'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '1.35'
125
+ description:
126
+ email:
127
+ - richard.seviora@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".circleci/config.yml"
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".ruby-version"
137
+ - ".travis.yml"
138
+ - CODE_OF_CONDUCT.md
139
+ - Gemfile
140
+ - Gemfile.lock
141
+ - LICENSE.txt
142
+ - README.md
143
+ - Rakefile
144
+ - bin/console
145
+ - bin/setup
146
+ - lib/record_diff.rb
147
+ - lib/record_diff/matcher.rb
148
+ - lib/record_diff/matcher_options.rb
149
+ - lib/record_diff/result_set.rb
150
+ - lib/record_diff/results.rb
151
+ - lib/record_diff/results/abstract_result.rb
152
+ - lib/record_diff/results/added_result.rb
153
+ - lib/record_diff/results/changed_result.rb
154
+ - lib/record_diff/results/dropped_result.rb
155
+ - lib/record_diff/results/unchanged_result.rb
156
+ - lib/record_diff/version.rb
157
+ - record_diff.gemspec
158
+ homepage: http://www.canada.com
159
+ licenses:
160
+ - MIT
161
+ metadata:
162
+ homepage_uri: http://www.canada.com
163
+ source_code_uri: http://canada.com
164
+ changelog_uri: http://canada.com
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.7.6
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: Reconciles items
185
+ test_files: []