Skip to content

Commit e8db65c

Browse files
committed
Use attr_extras in more places
1 parent cde1f81 commit e8db65c

File tree

4 files changed

+23
-54
lines changed

4 files changed

+23
-54
lines changed

lib/super_diff/diff_formatters/collection.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module SuperDiff
22
module DiffFormatters
33
class Collection
4+
extend AttrExtras.mixin
5+
46
ICONS = { delete: "-", insert: "+" }.freeze
57
STYLES = { insert: :inserted, delete: :deleted, noop: :normal }.freeze
68

7-
extend AttrExtras.mixin
8-
99
method_object(
1010
[
1111
:open_token!,

lib/super_diff/object_inspection/inspection_tree.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,10 @@ def build_node(type, *args, &block)
126126
end
127127

128128
class BlockArgument
129-
attr_reader :object
129+
extend AttrExtras.mixin
130130

131-
def initialize(object:, as_single_line:)
132-
@object = object
133-
@as_single_line = as_single_line
134-
end
135-
136-
def as_single_line?
137-
@as_single_line
138-
end
131+
rattr_initialize [:object!, :as_single_line!]
132+
attr_query :as_single_line?
139133
end
140134
end
141135
end

lib/super_diff/operations/binary_operation.rb

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
11
module SuperDiff
22
module Operations
33
class BinaryOperation
4-
attr_reader(
5-
:name,
6-
:left_collection,
7-
:right_collection,
8-
:left_key,
9-
:right_key,
10-
:left_value,
11-
:right_value,
12-
:left_index,
13-
:right_index,
14-
:child_operations,
15-
)
4+
extend AttrExtras.mixin
165

17-
def initialize(
18-
name:,
19-
left_collection:,
20-
right_collection:,
21-
left_index:,
22-
right_index:,
23-
left_key:,
24-
right_key:,
25-
left_value:,
26-
right_value:,
27-
child_operations: []
6+
rattr_initialize(
7+
[
8+
:name!,
9+
:left_collection!,
10+
:right_collection!,
11+
:left_index!,
12+
:right_index!,
13+
:left_key!,
14+
:right_key!,
15+
:left_value!,
16+
:right_value!,
17+
:left_index!,
18+
:right_index!,
19+
child_operations: [],
20+
],
2821
)
29-
@name = name
30-
@left_collection = left_collection
31-
@right_collection = right_collection
32-
@left_index = left_index
33-
@right_index = right_index
34-
@left_key = left_key
35-
@right_key = right_key
36-
@left_value = left_value
37-
@right_value = right_value
38-
@child_operations = child_operations
39-
end
4022

4123
def should_add_comma_after_displaying?
4224
left_index < left_collection.size - 1 ||

lib/super_diff/rspec/differ.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
module SuperDiff
22
module RSpec
33
class Differ
4-
def self.diff(actual, expected)
5-
new(actual, expected).diff
6-
end
4+
extend AttrExtras.mixin
75

8-
def initialize(actual, expected)
9-
@actual = actual
10-
@expected = expected
11-
end
6+
static_facade :diff, :actual, :expected
127

138
def diff
149
if worth_diffing?
@@ -39,8 +34,6 @@ def diff
3934

4035
private
4136

42-
attr_reader :actual, :expected
43-
4437
def worth_diffing?
4538
!comparing_equal_values? &&
4639
comparing_values_of_a_similar_class? &&

0 commit comments

Comments
 (0)