Skip to content

Commit

Permalink
Do some reorganizing
Browse files Browse the repository at this point in the history
* Rename "function" classes to Main, e.g., Differ -> Differs::Main.
  This makes it easier to Ctrl-P for the right files (if you were
  looking for differ.rb you might get differs/something_else.rb).
* Change inspector classes so that what they return match what they're
  named after. That is, previously an Inspector actually was an
  InspectionTree object, and now the InspectionTree lives inside the
  Inspector.
* Remove the inspector Map, as well as the MapExtensions which are used
  by extension modules such as `super_diff/rspec`,
  `super_diff/active_record`, etc., in favor of the same registry
  mechanism that differs, operational sequencers, etc. use.
* Pluralize extension points in the Configuration object so that you can
  provide more than one custom differ, operational sequencer, etc., at a
  time.

This reorganization is in preparation for introducing new classes in the
future around eliding diff output.
  • Loading branch information
mcmire committed May 23, 2020
1 parent ce1bb2f commit 8845c20
Show file tree
Hide file tree
Showing 85 changed files with 957 additions and 691 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ source "https://rubygems.org"
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

gem "appraisal"
gem(
"attr_extras",
github: "mcmire/attr_extras",
branch: "pass-kwargs-in-explicit-static-facade",
)
gem "childprocess"
gem "pry-byebug", platform: :mri
gem "pry-nav", platform: :jruby
Expand Down
1 change: 1 addition & 0 deletions gemfiles/no_rails.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ gem "pry-nav", platform: :jruby
gem "rake"
gem "rspec"
gem "rubocop"
gem "attr_extras", branch: "pass-kwargs-in-explicit-static-facade", git: "https://github.com/mcmire/attr_extras"

gemspec path: "../"
10 changes: 8 additions & 2 deletions gemfiles/no_rails.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
GIT
remote: https://github.com/mcmire/attr_extras
revision: 6073a1d6c7ac2d1b7331a34a09ed2779c4fec83c
branch: pass-kwargs-in-explicit-static-facade
specs:
attr_extras (6.2.3)

PATH
remote: ..
specs:
super_diff (0.4.2)
attr_extras
diff-lcs
patience_diff

Expand All @@ -14,7 +20,6 @@ GEM
rake
thor (>= 0.14.0)
ast (2.4.0)
attr_extras (6.2.3)
byebug (11.1.3)
childprocess (3.0.0)
coderay (1.1.2)
Expand Down Expand Up @@ -64,6 +69,7 @@ PLATFORMS

DEPENDENCIES
appraisal
attr_extras!
childprocess
pry-byebug
pry-nav
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "pry-nav", platform: :jruby
gem "rake"
gem "rspec"
gem "rubocop"
gem "attr_extras", branch: "pass-kwargs-in-explicit-static-facade", git: "https://github.com/mcmire/attr_extras"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.0.0"
Expand Down
10 changes: 8 additions & 2 deletions gemfiles/rails_5_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
GIT
remote: https://github.com/mcmire/attr_extras
revision: 6073a1d6c7ac2d1b7331a34a09ed2779c4fec83c
branch: pass-kwargs-in-explicit-static-facade
specs:
attr_extras (6.2.3)

PATH
remote: ..
specs:
super_diff (0.4.2)
attr_extras
diff-lcs
patience_diff

Expand All @@ -26,7 +32,6 @@ GEM
thor (>= 0.14.0)
arel (7.1.4)
ast (2.4.0)
attr_extras (6.2.3)
byebug (11.1.3)
childprocess (3.0.0)
coderay (1.1.2)
Expand Down Expand Up @@ -86,6 +91,7 @@ DEPENDENCIES
activerecord (~> 5.0.0)
activerecord-jdbcsqlite3-adapter
appraisal
attr_extras!
childprocess
jdbc-sqlite3
pry-byebug
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_1.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "pry-nav", platform: :jruby
gem "rake"
gem "rspec"
gem "rubocop"
gem "attr_extras", branch: "pass-kwargs-in-explicit-static-facade", git: "https://github.com/mcmire/attr_extras"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.1.0"
Expand Down
10 changes: 8 additions & 2 deletions gemfiles/rails_5_1.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
GIT
remote: https://github.com/mcmire/attr_extras
revision: 6073a1d6c7ac2d1b7331a34a09ed2779c4fec83c
branch: pass-kwargs-in-explicit-static-facade
specs:
attr_extras (6.2.3)

PATH
remote: ..
specs:
super_diff (0.4.2)
attr_extras
diff-lcs
patience_diff

Expand All @@ -26,7 +32,6 @@ GEM
thor (>= 0.14.0)
arel (8.0.0)
ast (2.4.0)
attr_extras (6.2.3)
byebug (11.1.3)
childprocess (3.0.0)
coderay (1.1.2)
Expand Down Expand Up @@ -86,6 +91,7 @@ DEPENDENCIES
activerecord (~> 5.1.0)
activerecord-jdbcsqlite3-adapter
appraisal
attr_extras!
childprocess
jdbc-sqlite3
pry-byebug
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_5_2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "pry-nav", platform: :jruby
gem "rake"
gem "rspec"
gem "rubocop"
gem "attr_extras", branch: "pass-kwargs-in-explicit-static-facade", git: "https://github.com/mcmire/attr_extras"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 5.2.0"
Expand Down
10 changes: 8 additions & 2 deletions gemfiles/rails_5_2.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
GIT
remote: https://github.com/mcmire/attr_extras
revision: 6073a1d6c7ac2d1b7331a34a09ed2779c4fec83c
branch: pass-kwargs-in-explicit-static-facade
specs:
attr_extras (6.2.3)

PATH
remote: ..
specs:
super_diff (0.4.2)
attr_extras
diff-lcs
patience_diff

Expand All @@ -26,7 +32,6 @@ GEM
thor (>= 0.14.0)
arel (9.0.0)
ast (2.4.0)
attr_extras (6.2.3)
byebug (11.1.3)
childprocess (3.0.0)
coderay (1.1.2)
Expand Down Expand Up @@ -86,6 +91,7 @@ DEPENDENCIES
activerecord (~> 5.2.0)
activerecord-jdbcsqlite3-adapter
appraisal
attr_extras!
childprocess
jdbc-sqlite3
pry-byebug
Expand Down
1 change: 1 addition & 0 deletions gemfiles/rails_6_0.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gem "pry-nav", platform: :jruby
gem "rake"
gem "rspec"
gem "rubocop"
gem "attr_extras", branch: "pass-kwargs-in-explicit-static-facade", git: "https://github.com/mcmire/attr_extras"
gem "activerecord-jdbcsqlite3-adapter", platform: :jruby
gem "jdbc-sqlite3", platform: :jruby
gem "activerecord", "~> 6.0"
Expand Down
10 changes: 8 additions & 2 deletions gemfiles/rails_6_0.gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
GIT
remote: https://github.com/mcmire/attr_extras
revision: 6073a1d6c7ac2d1b7331a34a09ed2779c4fec83c
branch: pass-kwargs-in-explicit-static-facade
specs:
attr_extras (6.2.3)

PATH
remote: ..
specs:
super_diff (0.4.2)
attr_extras
diff-lcs
patience_diff

Expand All @@ -25,7 +31,6 @@ GEM
rake
thor (>= 0.14.0)
ast (2.4.0)
attr_extras (6.2.3)
byebug (11.1.3)
childprocess (3.0.0)
coderay (1.1.2)
Expand Down Expand Up @@ -86,6 +91,7 @@ DEPENDENCIES
activerecord (~> 6.0)
activerecord-jdbcsqlite3-adapter
appraisal
attr_extras!
childprocess
jdbc-sqlite3
pry-byebug
Expand Down
22 changes: 8 additions & 14 deletions lib/super_diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,14 @@ module SuperDiff
)
autoload :Configuration, "super_diff/configuration"
autoload :Csi, "super_diff/csi"
autoload :DiffFormatter, "super_diff/diff_formatter"
autoload :DiffFormatters, "super_diff/diff_formatters"
autoload :Differ, "super_diff/differ"
autoload :Differs, "super_diff/differs"
autoload :EqualityMatcher, "super_diff/equality_matcher"
autoload :EqualityMatchers, "super_diff/equality_matchers"
autoload :Errors, "super_diff/errors"
autoload :Helpers, "super_diff/helpers"
autoload :ImplementationChecks, "super_diff/implementation_checks"
autoload :NoDifferAvailableError, "super_diff/no_differ_available_error"
autoload(
:NoDiffFormatterAvailableError,
"super_diff/no_diff_formatter_available_error",
)
autoload(
:NoOperationalSequencerAvailableError,
"super_diff/no_operational_sequencer_available_error",
)
autoload :ObjectInspection, "super_diff/object_inspection"
autoload :OperationSequence, "super_diff/operation_sequence"
autoload :OperationSequences, "super_diff/operation_sequences"
autoload :OperationalSequencer, "super_diff/operational_sequencer"
autoload :OperationalSequencers, "super_diff/operational_sequencers"
autoload :Operations, "super_diff/operations"
autoload :RecursionGuard, "super_diff/recursion_guard"
Expand All @@ -48,4 +35,11 @@ def self.configure
def self.configuration
@_configuration ||= Configuration.new
end

def self.time_like?(value)
# Check for ActiveSupport's #acts_like_time? for their time-like objects
# (like ActiveSupport::TimeWithZone).
(value.respond_to?(:acts_like_time?) && value.acts_like_time?) ||
value.is_a?(Time)
end
end
36 changes: 16 additions & 20 deletions lib/super_diff/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@ module ActiveRecord
:OperationalSequencers,
"super_diff/active_record/operational_sequencers",
)
end
end

if defined?(SuperDiff::RSpec)
SuperDiff::RSpec.configure do |config|
config.add_extra_differ_class(
SuperDiff::ActiveRecord::Differs::ActiveRecordRelation,
)
config.add_extra_operational_sequencer_class(
SuperDiff::ActiveRecord::OperationalSequencers::ActiveRecordModel,
)
config.add_extra_operational_sequencer_class(
SuperDiff::ActiveRecord::OperationalSequencers::ActiveRecordRelation,
)
config.add_extra_diff_formatter_class(
SuperDiff::ActiveRecord::DiffFormatters::ActiveRecordRelation,
)
SuperDiff.configure do |config|
config.add_extra_differ_classes(
Differs::ActiveRecordRelation,
)
config.add_extra_operational_sequencer_classes(
OperationalSequencers::ActiveRecordModel,
OperationalSequencers::ActiveRecordRelation,
)
config.add_extra_diff_formatter_classes(
DiffFormatters::ActiveRecordRelation,
)
config.add_extra_inspector_classes(
ObjectInspection::Inspectors::ActiveRecordModel,
ObjectInspection::Inspectors::ActiveRecordRelation,
)
end
end
end

require "super_diff/active_record/monkey_patches"

SuperDiff::ObjectInspection.map.prepend(
SuperDiff::ActiveRecord::ObjectInspection::MapExtension,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,45 @@ module SuperDiff
module ActiveRecord
module ObjectInspection
module Inspectors
ActiveRecordModel = SuperDiff::ObjectInspection::InspectionTree.new do
add_text do |object|
"#<#{object.class} "
class ActiveRecordModel < SuperDiff::ObjectInspection::Inspectors::Base
def self.applies_to?(value)
value.is_a?(::ActiveRecord::Base)
end

when_multiline do
add_text "{"
end
protected

nested do |object|
add_break
def inspection_tree
SuperDiff::ObjectInspection::InspectionTree.new do
add_text do |object|
"#<#{object.class} "
end

insert_separated_list(
["id"] + (object.attributes.keys.sort - ["id"]),
separator: ",",
) do |name|
add_text name
add_text ": "
add_inspection_of object.read_attribute(name)
end
end
when_multiline do
add_text "{"
end

add_break
nested do |object|
add_break

when_multiline do
add_text "}"
end
insert_separated_list(
["id"] + (object.attributes.keys.sort - ["id"]),
separator: ",",
) do |name|
add_text name
add_text ": "
add_inspection_of object.read_attribute(name)
end
end

add_text ">"
add_break

when_multiline do
add_text "}"
end

add_text ">"
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ module SuperDiff
module ActiveRecord
module ObjectInspection
module Inspectors
ActiveRecordRelation = SuperDiff::ObjectInspection::InspectionTree.new do
add_text "#<ActiveRecord::Relation ["

nested do |array|
insert_array_inspection_of(array)
class ActiveRecordRelation < SuperDiff::ObjectInspection::Inspectors::Base
def self.applies_to?(value)
value.is_a?(::ActiveRecord::Relation)
end

add_break
add_text "]>"
protected

def inspection_tree
SuperDiff::ObjectInspection::InspectionTree.new do
add_text "#<ActiveRecord::Relation ["

nested do |array|
insert_array_inspection_of(array)
end

add_break
add_text "]>"
end
end
end
end
end
Expand Down
Loading

0 comments on commit 8845c20

Please sign in to comment.