sub_diff 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/sub_diff/builder.rb +12 -4
- data/lib/sub_diff/collection.rb +15 -2
- data/lib/sub_diff/version.rb +1 -1
- data/spec/sub_diff/collection_spec.rb +43 -0
- data/spec/sub_diff_spec.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0a1c384ad9a38a3da768751496368956897495
|
4
|
+
data.tar.gz: bbf19547c4e3ffa7e418466b655f5f4f393133e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3335512ec9a6d1da59b76932415a0a5558332e871f28df968bbd4f319bc4e11aa77ed6843029c2d16efb9600c4d1ed8c0722a48581de94eb6bd8361c7ab4a7fb
|
7
|
+
data.tar.gz: 08afe03cecebf41f2ec96c65e7c02841bee5e80a34edda84d9b00a4625e5650c776bcd06aed4ab1dbd74ec86c2ff711a693bf8cb7decb5689f00f793c25861b3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -94,8 +94,10 @@ end
|
|
94
94
|
* `SubDiff::Diff#value`
|
95
95
|
* `SubDiff::Diff#value_was`
|
96
96
|
* `SubDiff::Collection#changed?`
|
97
|
+
* `SubDiff::Collection#clear`
|
97
98
|
* `SubDiff::Collection#diffs`
|
98
99
|
* `SubDiff::Collection#each`
|
100
|
+
* `SubDiff::Collection#reset`
|
99
101
|
* `SubDiff::Collection#size`
|
100
102
|
|
101
103
|
## Testing
|
data/lib/sub_diff/builder.rb
CHANGED
@@ -6,9 +6,9 @@ module SubDiff
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def diff(*args, &block)
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
build_diff_collection do
|
10
|
+
adapter.diff(*args, &block)
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def push(*args)
|
@@ -21,7 +21,15 @@ module SubDiff
|
|
21
21
|
|
22
22
|
private
|
23
23
|
|
24
|
-
attr_reader :
|
24
|
+
attr_reader :string, :type
|
25
|
+
|
26
|
+
def build_diff_collection(&block)
|
27
|
+
collection.reset(&block).dup
|
28
|
+
end
|
29
|
+
|
30
|
+
def collection
|
31
|
+
@collection ||= Collection.new(string)
|
32
|
+
end
|
25
33
|
|
26
34
|
def adapter
|
27
35
|
adapter_class.new(differ)
|
data/lib/sub_diff/collection.rb
CHANGED
@@ -3,9 +3,10 @@ module SubDiff
|
|
3
3
|
extend Forwardable
|
4
4
|
include Enumerable
|
5
5
|
|
6
|
-
attr_reader :string, :diffs
|
7
|
-
|
8
6
|
def_delegators :diffs, :each, :size
|
7
|
+
def_delegators :__getobj__, :to_s
|
8
|
+
|
9
|
+
attr_reader :string, :diffs
|
9
10
|
|
10
11
|
def initialize(string)
|
11
12
|
@string = string
|
@@ -17,11 +18,23 @@ module SubDiff
|
|
17
18
|
diffs.any?(&:changed?)
|
18
19
|
end
|
19
20
|
|
21
|
+
def clear
|
22
|
+
diffs.clear
|
23
|
+
__setobj__('')
|
24
|
+
end
|
25
|
+
|
20
26
|
def push(diff)
|
21
27
|
unless diff.empty?
|
22
28
|
diffs << diff
|
23
29
|
__setobj__(diffs.join)
|
24
30
|
end
|
25
31
|
end
|
32
|
+
|
33
|
+
def reset
|
34
|
+
clear
|
35
|
+
__setobj__(string)
|
36
|
+
yield if block_given?
|
37
|
+
self
|
38
|
+
end
|
26
39
|
end
|
27
40
|
end
|
data/lib/sub_diff/version.rb
CHANGED
@@ -21,6 +21,22 @@ RSpec.describe SubDiff::Collection do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe '#clear' do
|
25
|
+
before { subject.push('example') }
|
26
|
+
|
27
|
+
let(:block) { proc { subject.clear } }
|
28
|
+
|
29
|
+
it 'should clear diffs' do
|
30
|
+
expect(block).to change(subject, :size)
|
31
|
+
expect(subject.diffs).to be_empty
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should clear string' do
|
35
|
+
expect(block).to change(subject, :to_s)
|
36
|
+
expect(subject.to_s).to eq('')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
24
40
|
describe '#each' do
|
25
41
|
it { is_expected.to be_an(Enumerable) }
|
26
42
|
it { is_expected.to delegate(:each).to(:diffs) }
|
@@ -40,6 +56,33 @@ RSpec.describe SubDiff::Collection do
|
|
40
56
|
end
|
41
57
|
end
|
42
58
|
|
59
|
+
describe '#reset' do
|
60
|
+
before { subject.push('example') }
|
61
|
+
|
62
|
+
let(:block) { proc { subject.reset } }
|
63
|
+
|
64
|
+
it 'should empty diffs' do
|
65
|
+
expect(block).to change(subject, :size)
|
66
|
+
expect(subject.diffs).to be_empty
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should reset string' do
|
70
|
+
expect(block).to change(subject, :to_s)
|
71
|
+
expect(subject.to_s).to eq(diffable)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should yield if a block is given' do
|
75
|
+
local = 'test'
|
76
|
+
block = proc { local = 'changed' }
|
77
|
+
subject.reset(&block)
|
78
|
+
expect(local).to eq('changed')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should return the instance itself' do
|
82
|
+
expect(block.call).to eq(subject)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
43
86
|
describe '#size' do
|
44
87
|
it { is_expected.to delegate(:size).to(:diffs) }
|
45
88
|
|
data/spec/sub_diff_spec.rb
CHANGED
@@ -2,6 +2,14 @@ RSpec.describe SubDiff do
|
|
2
2
|
subject { 'this is a simple test' }
|
3
3
|
|
4
4
|
describe '#sub_diff' do
|
5
|
+
context 'when called multiple times with the same arguments' do
|
6
|
+
it 'should return a new object' do
|
7
|
+
first = subject.sub_diff('simple', 'very simple')
|
8
|
+
second = subject.sub_diff('simple', 'very simple')
|
9
|
+
expect(second.object_id).not_to eq(first.object_id)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
5
13
|
context 'with a string' do
|
6
14
|
it 'should process arguments correctly' do
|
7
15
|
result = subject.sub_diff('simple', 'very simple')
|
@@ -50,6 +58,14 @@ RSpec.describe SubDiff do
|
|
50
58
|
end
|
51
59
|
|
52
60
|
describe '#gsub_diff' do
|
61
|
+
context 'when called multiple times with the same arguments' do
|
62
|
+
it 'should return a new object' do
|
63
|
+
first = subject.gsub_diff('i', 'x')
|
64
|
+
second = subject.gsub_diff('x', 'x')
|
65
|
+
expect(second.object_id).not_to eq(first.object_id)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
53
69
|
context 'with a string' do
|
54
70
|
it 'should process arguments correctly' do
|
55
71
|
result = subject.gsub_diff('i', 'x')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sub_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|