Skip to content

Commit 646bf9e

Browse files
committed
Rename some concepts
* Rename "operation sequence" to "operation tree" * Rename "operational sequencer" to "operation tree builder" This commit is in preparation for adding elisions to diffs, which will require adding the concept of an "operation list" (basically a flattened version of an operation tree).
1 parent 8845c20 commit 646bf9e

File tree

71 files changed

+283
-270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+283
-270
lines changed

ARCHITECTURE.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,28 @@ but here are some quick hits:
55

66
## Basic concepts
77

8-
* A **differ** figures out which operational sequencer to use.
9-
* An **operational sequencer** makes a comparison between two like data structures.
10-
and generates a set of operations between them
11-
(additions, deletions, or changes).
12-
* An **operation sequence** is a list of those operations
13-
associated with some kind of diff formatter.
14-
* A **diff formatter** takes a list of operations
15-
and spits out a textual representation of that list in the form of a conventional diff.
168
* An **object inspector** generates a multi-line textual representation of an object,
179
similar to PrettyPrinter in Ruby or AwesomePrint,
1810
but more appropriate for showing within a diff.
11+
* An **operation** represents a difference in one value from another
12+
in the context of a data structure.
13+
That difference can either be an *delete*, *insert*, or *change*.
14+
* An **operation tree** is the set of all operations between two data structures,
15+
where each operation represents the difference between an inner element within the structure
16+
(value for an array or a key/value pair for a hash).
17+
Since change operations represent elements that have child elements,
18+
they also have child operations to represent those child elements.
19+
Those child operations can themselves have children, etc.
20+
This descendancy is what forms the tree.
21+
* An **operation tree builder** makes a comparison between two like data structures
22+
and generates an operation tree to represent the differences.
23+
* A **diff formatter** takes an operation tree
24+
and spits out a textual representation of that tree in the form of a conventional diff.
25+
Each operation may in fact generate more than one line in the final diff
26+
because the object that is specific to the operation is run through an object inspector.
27+
* Finally, a **differ** ties everything together
28+
and figures out which operation tree builder and diff formatter to use for a particular pair of values
29+
(where one value is the "expected" and the other is the "actual").
1930

2031
## Code flow diagram
2132

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,16 @@ you would add something like this to your test helper file
167167
``` ruby
168168
SuperDiff.configure do |config|
169169
config.add_extra_differ_class(YourDiffer)
170-
config.add_extra_operational_sequencer_class(YourOperationalSequencer)
171-
config.add_extra_operation_sequence_class(YourOperationSequence)
170+
config.add_extra_operation_tree_builder_class(YourOperationTreeBuilder)
171+
config.add_extra_operation_tree_class(YourOperationTree)
172172
config.add_extra_diff_formatter_class(YourDiffFormatter)
173173
end
174174
```
175175

176-
*(More info here in the future on adding a custom differ, operational sequencer, operation sequence, and diff formatter.
176+
*(More info here in the future on adding a custom differ,
177+
operation tree builder,
178+
operation tree,
179+
and diff formatter.
177180
Also explanations on what these are.)*
178181

179182
## Support

lib/super_diff.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module SuperDiff
1616
autoload :Helpers, "super_diff/helpers"
1717
autoload :ImplementationChecks, "super_diff/implementation_checks"
1818
autoload :ObjectInspection, "super_diff/object_inspection"
19-
autoload :OperationSequences, "super_diff/operation_sequences"
20-
autoload :OperationalSequencers, "super_diff/operational_sequencers"
19+
autoload :OperationTrees, "super_diff/operation_trees"
20+
autoload :OperationTreeBuilders, "super_diff/operation_tree_builders"
2121
autoload :Operations, "super_diff/operations"
2222
autoload :RecursionGuard, "super_diff/recursion_guard"
2323

lib/super_diff/active_record.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ module ActiveRecord
99
"super_diff/active_record/object_inspection",
1010
)
1111
autoload(
12-
:OperationSequences,
13-
"super_diff/active_record/operation_sequences",
12+
:OperationTrees,
13+
"super_diff/active_record/operation_trees",
1414
)
1515
autoload(
16-
:OperationalSequencers,
17-
"super_diff/active_record/operational_sequencers",
16+
:OperationTreeBuilders,
17+
"super_diff/active_record/operation_tree_builders",
1818
)
1919

2020
SuperDiff.configure do |config|
2121
config.add_extra_differ_classes(
2222
Differs::ActiveRecordRelation,
2323
)
24-
config.add_extra_operational_sequencer_classes(
25-
OperationalSequencers::ActiveRecordModel,
26-
OperationalSequencers::ActiveRecordRelation,
24+
config.add_extra_operation_tree_builder_classes(
25+
OperationTreeBuilders::ActiveRecordModel,
26+
OperationTreeBuilders::ActiveRecordRelation,
2727
)
2828
config.add_extra_diff_formatter_classes(
2929
DiffFormatters::ActiveRecordRelation,

lib/super_diff/active_record/diff_formatters/active_record_relation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ module SuperDiff
22
module ActiveRecord
33
module DiffFormatters
44
class ActiveRecordRelation < SuperDiff::DiffFormatters::Base
5-
def self.applies_to?(operations)
6-
operations.is_a?(OperationSequences::ActiveRecordRelation)
5+
def self.applies_to?(operation_tree)
6+
operation_tree.is_a?(OperationTrees::ActiveRecordRelation)
77
end
88

99
def call
@@ -12,7 +12,7 @@ def call
1212
close_token: "]>",
1313
collection_prefix: collection_prefix,
1414
build_item_prefix: proc { "" },
15-
operations: operations,
15+
operation_tree: operation_tree,
1616
indent_level: indent_level,
1717
add_comma: add_comma?,
1818
)

lib/super_diff/active_record/differs/active_record_relation.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ def self.applies_to?(expected, actual)
99

1010
def call
1111
DiffFormatters::ActiveRecordRelation.call(
12-
operations,
12+
operation_tree,
1313
indent_level: indent_level,
1414
)
1515
end
1616

1717
private
1818

19-
def operations
20-
OperationalSequencers::ActiveRecordRelation.call(
19+
def operation_tree
20+
OperationTreeBuilders::ActiveRecordRelation.call(
2121
expected: expected,
2222
actual: actual,
2323
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module SuperDiff
2+
module ActiveRecord
3+
module OperationTreeBuilders
4+
autoload(
5+
:ActiveRecordModel,
6+
"super_diff/active_record/operation_tree_builders/active_record_model",
7+
)
8+
autoload(
9+
:ActiveRecordRelation,
10+
"super_diff/active_record/operation_tree_builders/active_record_relation",
11+
)
12+
end
13+
end
14+
end

lib/super_diff/active_record/operational_sequencers/active_record_model.rb renamed to lib/super_diff/active_record/operation_tree_builders/active_record_model.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SuperDiff
22
module ActiveRecord
3-
module OperationalSequencers
4-
class ActiveRecordModel < SuperDiff::OperationalSequencers::CustomObject
3+
module OperationTreeBuilders
4+
class ActiveRecordModel < SuperDiff::OperationTreeBuilders::CustomObject
55
def self.applies_to?(expected, actual)
66
expected.is_a?(::ActiveRecord::Base) &&
77
actual.is_a?(::ActiveRecord::Base) &&

lib/super_diff/active_record/operational_sequencers/active_record_relation.rb renamed to lib/super_diff/active_record/operation_tree_builders/active_record_relation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module SuperDiff
22
module ActiveRecord
3-
module OperationalSequencers
4-
class ActiveRecordRelation < SuperDiff::OperationalSequencers::Array
3+
module OperationTreeBuilders
4+
class ActiveRecordRelation < SuperDiff::OperationTreeBuilders::Array
55
def self.applies_to?(expected, actual)
66
expected.is_a?(::Array) &&
77
actual.is_a?(::ActiveRecord::Relation)
@@ -15,8 +15,8 @@ def initialize(actual:, **rest)
1515

1616
private
1717

18-
def operations
19-
@_operations ||= OperationSequences::ActiveRecordRelation.new([])
18+
def operation_tree
19+
@_operation_tree ||= OperationTrees::ActiveRecordRelation.new([])
2020
end
2121
end
2222
end

lib/super_diff/active_record/operation_sequences.rb renamed to lib/super_diff/active_record/operation_trees.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module SuperDiff
22
module ActiveRecord
3-
module OperationSequences
3+
module OperationTrees
44
autoload(
55
:ActiveRecordRelation,
6-
"super_diff/active_record/operation_sequences/active_record_relation",
6+
"super_diff/active_record/operation_trees/active_record_relation",
77
)
88
end
99
end

0 commit comments

Comments
 (0)