sub_diff 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sub_diff/{diff_builder.rb → builder.rb} +3 -3
- data/lib/sub_diff/{diff_collection.rb → collection.rb} +1 -1
- data/lib/sub_diff/core_ext/string.rb +3 -3
- data/lib/sub_diff/differ.rb +10 -10
- data/lib/sub_diff/version.rb +1 -1
- data/spec/sub_diff/{diff_collection_spec.rb → collection_spec.rb} +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db20a712d5a1c4827ecdb355b8bf7908014acf55
|
4
|
+
data.tar.gz: 2e0fada841e581713251b66ead8df9dad486d3cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 210f157fb1dd0ec4da7384d888ed07399507372a8afd0f11bfdc5583935012dc736c947c1f528aabe86386030570e29f5976fc1057f0c95e2c3064a0e79b0520
|
7
|
+
data.tar.gz: 3f4c90c216981bb97c04edb43785e5a1cabc5376858e8b82f0c5b36f853ed02da542addfab1f491eab301622505601962d2f07eff137877ffc46af6ae70bee45
|
data/Gemfile.lock
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'forwardable'
|
2
|
-
require 'sub_diff/
|
2
|
+
require 'sub_diff/collection'
|
3
3
|
require 'sub_diff/differ'
|
4
4
|
require 'sub_diff/gsub'
|
5
5
|
|
6
6
|
module SubDiff
|
7
|
-
class
|
7
|
+
class Builder < Struct.new(:string, :type)
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :instance, :diff
|
@@ -28,7 +28,7 @@ module SubDiff
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def collection
|
31
|
-
|
31
|
+
Collection.new(string)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'sub_diff/
|
1
|
+
require 'sub_diff/builder'
|
2
2
|
|
3
3
|
module SubDiff
|
4
4
|
module CoreExt
|
5
5
|
module String
|
6
6
|
def sub_diff(*args, &block)
|
7
|
-
|
7
|
+
Builder.new(self, :sub).diff(*args, &block)
|
8
8
|
end
|
9
9
|
|
10
10
|
def gsub_diff(*args, &block)
|
11
|
-
|
11
|
+
Builder.new(self, :gsub).diff(*args, &block)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/sub_diff/differ.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module SubDiff
|
2
|
-
class Differ < Struct.new(:
|
4
|
+
class Differ < Struct.new(:collection, :type)
|
5
|
+
extend Forwardable
|
6
|
+
|
7
|
+
def_delegators :collection, :string
|
8
|
+
|
3
9
|
def diff(*args)
|
4
10
|
# Ruby 1.8.7 does not support additional args after * (splat)
|
5
11
|
block = args.pop
|
6
12
|
|
7
|
-
|
13
|
+
string.send(type, args.first) do |match|
|
8
14
|
diff = { :match => match, :prefix => $`, :suffix => $' }
|
9
15
|
diff[:replacement] = match.sub(*args, &block)
|
10
|
-
yield(
|
16
|
+
yield(collection, diff)
|
11
17
|
end
|
12
18
|
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def differ
|
19
|
-
diff_collection.string.method(diff_method)
|
19
|
+
collection
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
data/lib/sub_diff/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require File.expand_path('../../../lib/sub_diff/
|
1
|
+
require File.expand_path('../../../lib/sub_diff/collection', __FILE__)
|
2
2
|
|
3
|
-
RSpec.describe SubDiff::
|
3
|
+
RSpec.describe SubDiff::Collection do
|
4
4
|
subject { described_class.new(diffable) }
|
5
5
|
|
6
6
|
let(:diffable) { 'this is a simple test' }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
@@ -39,16 +39,16 @@ files:
|
|
39
39
|
- LICENSE
|
40
40
|
- README.md
|
41
41
|
- lib/sub_diff.rb
|
42
|
+
- lib/sub_diff/builder.rb
|
43
|
+
- lib/sub_diff/collection.rb
|
42
44
|
- lib/sub_diff/core_ext/string.rb
|
43
45
|
- lib/sub_diff/diff.rb
|
44
|
-
- lib/sub_diff/diff_builder.rb
|
45
|
-
- lib/sub_diff/diff_collection.rb
|
46
46
|
- lib/sub_diff/differ.rb
|
47
47
|
- lib/sub_diff/gsub.rb
|
48
48
|
- lib/sub_diff/sub.rb
|
49
49
|
- lib/sub_diff/version.rb
|
50
50
|
- spec/spec_helper.rb
|
51
|
-
- spec/sub_diff/
|
51
|
+
- spec/sub_diff/collection_spec.rb
|
52
52
|
- spec/sub_diff/diff_spec.rb
|
53
53
|
- spec/sub_diff_spec.rb
|
54
54
|
- sub_diff.gemspec
|
@@ -83,6 +83,6 @@ specification_version: 4
|
|
83
83
|
summary: Inspect the changes of your `String#sub` and `String#gsub` replacements
|
84
84
|
test_files:
|
85
85
|
- spec/spec_helper.rb
|
86
|
-
- spec/sub_diff/
|
86
|
+
- spec/sub_diff/collection_spec.rb
|
87
87
|
- spec/sub_diff/diff_spec.rb
|
88
88
|
- spec/sub_diff_spec.rb
|