lib/sub_diff/builder.rb in sub_diff-1.0.4 vs lib/sub_diff/builder.rb in sub_diff-1.0.5
- old
+ new
@@ -4,13 +4,13 @@
@string = string
@type = type
end
def diff(*args, &block)
- @collection = Collection.new(string)
- adapter.diff(*args, &block)
- collection
+ build_diff_collection do
+ adapter.diff(*args, &block)
+ end
end
def push(*args)
if args.compact.any?
diff = Diff.new(*args)
@@ -19,10 +19,18 @@
end
alias_method :<<, :push
private
- attr_reader :collection, :string, :type
+ attr_reader :string, :type
+
+ def build_diff_collection(&block)
+ collection.reset(&block).dup
+ end
+
+ def collection
+ @collection ||= Collection.new(string)
+ end
def adapter
adapter_class.new(differ)
end