Skip to content

Do some reorganizing #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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