sub_diff 1.0.6 → 1.0.7

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: a9bf511596ffa127d50dbb11ca5c23455c22e2e9
4
- data.tar.gz: 1ddf085a4b05b5053d42f7934211ff40af9f7d24
3
+ metadata.gz: 752cac400652db441bd35020203e6ab107dd11a6
4
+ data.tar.gz: 4f2ec9341e8f352dbf3df9f447d6865e655e1ffe
5
5
  SHA512:
6
- metadata.gz: 156e609d5da9583939778c4b1b38b97f044ee168b3f2f668ffcc646f0a7960e5c57d887744f8be7d945c2c0849755a7c456769ebc22232dbeb7aecc7c2a4b266
7
- data.tar.gz: 6468333a0d3e6ec9be8479c2ecbe261b856abf7494073729b7f71202c65cab11c7b9ebd65440c4db5de19a12fb184a007c93281b117d25bcd0f0c947e6a86e6b
6
+ metadata.gz: cd95af17191c1b86ed572c8115b32f673beea23c16a15f4d87adb50b94a9b62bdca391054b2ab9e623792d67b6770932a310e759ee0c931ac46c12b1788f2082
7
+ data.tar.gz: 39aa674adade0b204e99a553531cd736214a629593b0b5c5c053880c038d0113947fb1bc6f21729cb9b02a93291b80cdec74c08f0f9a466c2ec55010e2ba4a32
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sub_diff (1.0.6)
4
+ sub_diff (1.0.7)
5
5
 
6
6
  GEM
7
7
  remote: https://www.rubygems.org/
@@ -0,0 +1,29 @@
1
+ module SubDiff
2
+ class Adapter
3
+ extend Forwardable
4
+
5
+ def_delegators :differ, :builder
6
+ def_delegators :builder, :diff_method
7
+ def_delegators :instance, :diff
8
+
9
+ attr_reader :differ
10
+
11
+ def initialize(differ)
12
+ @differ = differ
13
+ end
14
+
15
+ private
16
+
17
+ def instance
18
+ adapter_class.new(differ)
19
+ end
20
+
21
+ def adapter_class
22
+ Module.nesting.last.const_get(adapter_name)
23
+ end
24
+
25
+ def adapter_name
26
+ diff_method.to_s.capitalize
27
+ end
28
+ end
29
+ end
@@ -1,8 +1,10 @@
1
1
  module SubDiff
2
2
  class Builder
3
- def initialize(string, type)
3
+ attr_reader :string, :diff_method
4
+
5
+ def initialize(string, diff_method)
4
6
  @string = string
5
- @type = type
7
+ @diff_method = diff_method
6
8
  end
7
9
 
8
10
  def diff(*args, &block)
@@ -21,8 +23,6 @@ module SubDiff
21
23
 
22
24
  private
23
25
 
24
- attr_reader :string, :type
25
-
26
26
  def build_diff_collection(&block)
27
27
  collection.reset(&block).dup
28
28
  end
@@ -32,19 +32,11 @@ module SubDiff
32
32
  end
33
33
 
34
34
  def adapter
35
- adapter_class.new(differ)
36
- end
37
-
38
- def adapter_class
39
- Module.nesting.last.const_get(adapter_name)
40
- end
41
-
42
- def adapter_name
43
- type.to_s.capitalize
35
+ @adapter ||= Adapter.new(differ)
44
36
  end
45
37
 
46
38
  def differ
47
- Differ.new(self, type)
39
+ @differ ||= Differ.new(self)
48
40
  end
49
41
  end
50
42
  end
@@ -2,26 +2,23 @@ module SubDiff
2
2
  class Differ
3
3
  extend Forwardable
4
4
 
5
- def_delegators :builder, :string
5
+ def_delegators :builder, :diff_method, :string
6
6
 
7
- def initialize(builder, type)
7
+ attr_reader :builder
8
+
9
+ def initialize(builder)
8
10
  @builder = builder
9
- @type = type
10
11
  end
11
12
 
12
13
  def each_diff(*args)
13
14
  # Ruby 1.8.7 does not support additional args after * (splat)
14
15
  block = args.pop
15
16
 
16
- string.send(type, args.first) do |match|
17
+ string.send(diff_method, args.first) do |match|
17
18
  diff = { :match => match, :prefix => $`, :suffix => $' }
18
19
  diff[:replacement] = match.sub(*args, &block)
19
20
  yield(builder, diff)
20
21
  end
21
22
  end
22
-
23
- private
24
-
25
- attr_reader :builder, :type
26
23
  end
27
24
  end
data/lib/sub_diff/gsub.rb CHANGED
@@ -16,8 +16,10 @@ module SubDiff
16
16
  end
17
17
 
18
18
  def suffix(_diff, search)
19
+ suffix = super
19
20
  matcher = suffix_matcher(search)
20
- super unless super.send(matcher, search)
21
+ skip_suffix = suffix.send(matcher, search)
22
+ suffix unless skip_suffix
21
23
  end
22
24
 
23
25
  def suffix_matcher(search)
data/lib/sub_diff/sub.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module SubDiff
2
2
  class Sub
3
+ attr_reader :differ
4
+
3
5
  def initialize(differ)
4
6
  @differ = differ
5
7
  end
@@ -15,8 +17,6 @@ module SubDiff
15
17
 
16
18
  private
17
19
 
18
- attr_reader :differ
19
-
20
20
  def process(builder, diff, search)
21
21
  builder << prefix(diff)
22
22
  builder.push(diff[:replacement], diff[:match])
@@ -1,3 +1,3 @@
1
1
  module SubDiff
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.7'
3
3
  end
data/lib/sub_diff.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'delegate'
2
2
  require 'forwardable'
3
- require 'sub_diff/core_ext/string'
3
+ require 'sub_diff/adapter'
4
4
  require 'sub_diff/builder'
5
5
  require 'sub_diff/collection'
6
6
  require 'sub_diff/diff'
@@ -8,5 +8,6 @@ require 'sub_diff/differ'
8
8
  require 'sub_diff/sub'
9
9
  require 'sub_diff/gsub'
10
10
  require 'sub_diff/version'
11
+ require 'sub_diff/core_ext/string'
11
12
 
12
13
  String.send(:include, SubDiff::CoreExt::String)
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.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Huber
@@ -39,6 +39,7 @@ files:
39
39
  - LICENSE
40
40
  - README.md
41
41
  - lib/sub_diff.rb
42
+ - lib/sub_diff/adapter.rb
42
43
  - lib/sub_diff/builder.rb
43
44
  - lib/sub_diff/collection.rb
44
45
  - lib/sub_diff/core_ext/string.rb