sub_diff 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a5b6f0499741992f3bc4208ecfea84003a86371f
4
- data.tar.gz: 50d86038a21c0a18a7fc65381a0a99158d3e2f48
3
+ metadata.gz: 0e0a1c384ad9a38a3da768751496368956897495
4
+ data.tar.gz: bbf19547c4e3ffa7e418466b655f5f4f393133e4
5
5
  SHA512:
6
- metadata.gz: 62a7a493cb66b51337b30df012cc7aeb19ae8f2502838c1f2401da4e32ba00a6a04ba00775b3d40c3e8f50ff4f0c66d5695855b5644f68c23e0c6b7183e19a8e
7
- data.tar.gz: 83bbb97a007740f8ec3a9c9e06dcb43e85aabb6a69901126a4496fb8dbc4efc44a51a0d9a395124a5b88487e8da668623f60dc950bd015e4a9f6bed080c082c7
6
+ metadata.gz: 3335512ec9a6d1da59b76932415a0a5558332e871f28df968bbd4f319bc4e11aa77ed6843029c2d16efb9600c4d1ed8c0722a48581de94eb6bd8361c7ab4a7fb
7
+ data.tar.gz: 08afe03cecebf41f2ec96c65e7c02841bee5e80a34edda84d9b00a4625e5650c776bcd06aed4ab1dbd74ec86c2ff711a693bf8cb7decb5689f00f793c25861b3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sub_diff (1.0.4)
4
+ sub_diff (1.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://www.rubygems.org/
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
@@ -6,9 +6,9 @@ module SubDiff
6
6
  end
7
7
 
8
8
  def diff(*args, &block)
9
- @collection = Collection.new(string)
10
- adapter.diff(*args, &block)
11
- collection
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 :collection, :string, :type
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SubDiff
2
- VERSION = '1.0.4'
2
+ VERSION = '1.0.5'
3
3
  end
@@ -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
 
@@ -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
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-05-29 00:00:00.000000000 Z
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec