fastlane-plugin-patch 0.3.0 → 0.4.0

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: d6f15eb1e0e061b321516b1b0e2d10078fdc9862
4
- data.tar.gz: 937b14b6afd6fa88b64bfe0cdf8a8d34399eea51
3
+ metadata.gz: ca22332d6aadf5ba6d6ef8caae93aa206e1cceb0
4
+ data.tar.gz: 0e7329cfd451552872dc685fef793709c837a246
5
5
  SHA512:
6
- metadata.gz: df39ffa6eb89432594b8ca3f1cc711aa50a8f1b5b51ea017d66be7d7578097ae4de76118b32b4a2b431038e046a03a44d0e686465d254c9599c1a2fe1b64b4ac
7
- data.tar.gz: 407a273c955a255c4073a49e29b3aeadf47a62e665c5c7bfee6f53a07813159f8ff3f5e1610c79362f410e66034aa530b9a1bffdbd9d0c4e4123d144e131000f
6
+ metadata.gz: 52cbcad0a3515ce3b37c484a1bbc6999bbf97639832d06f0f1e41add939bd40a15831e554b12319b5a76487c26860a2929b322c427fe2caed258d1bf72112cfd
7
+ data.tar.gz: 9d5170068631d7d53cccfcc3f9f3a800d1eaeb01c7b59d2bf22f2d4ae471573600087611fb2f159e0f7fa28df6ad623263cb6c46c70f355d9f994581d9b839b0
data/README.md CHANGED
@@ -62,17 +62,22 @@ patch(
62
62
 
63
63
  #### Capture groups
64
64
 
65
- Capture groups may be used in `:replace` mode.
65
+ Capture groups may be used within the text argument in any mode. Note that
66
+ this works best without interpolation (single quotes or %q). If you use double
67
+ quotes, the backslash must be escaped, e.g. `text: "\\1\"MyOtherpod\""`.
66
68
 
67
69
  ```Ruby
68
70
  patch(
69
71
  files: "MyPod.podspec",
70
- regexp: /(s.name\s*=\s*)"MyPod"/,
72
+ regexp: /(s\.name\s*=\s*)"MyPod"/,
71
73
  text: '\1"MyOtherPod"',
72
74
  mode: :replace
73
75
  )
74
76
  ```
75
77
 
78
+ Patches in `:append` mode using capture groups in the text argument may be
79
+ reverted. This is not currently supported in `:prepend` mode.
80
+
76
81
  #### Revert patches
77
82
 
78
83
  Revert patches by passing the optional `:revert` parameter:
@@ -1,3 +1,32 @@
1
+ class String
2
+ # Replace capture group references in self with appropriate
3
+ # data from matches. Modifies the receiver. The receiver
4
+ # need not match the matches.regexp.
5
+ #
6
+ # :matches: A MatchData object returned by Regexp#match
7
+ def apply_matches!(matches)
8
+ search_position = 0
9
+ while (m = /\\(\d+)/.match(self, search_position))
10
+ capture_group = m[1].to_i
11
+ search_position = index m[0]
12
+ gsub! m[0], matches[capture_group]
13
+ search_position += matches[capture_group].length
14
+ end
15
+ nil
16
+ end
17
+
18
+ # Return a copy of the receiver with capture group references
19
+ # in self replaced by appropriate data from matches. The receiver
20
+ # need not match the matches.regexp.
21
+ #
22
+ # :matches: A MatchData object returned by Regexp#match
23
+ def apply_matches(matches)
24
+ string = clone
25
+ string.apply_matches! matches
26
+ string
27
+ end
28
+ end
29
+
1
30
  module Fastlane
2
31
  module Helper
3
32
  class PatchHelper
@@ -17,9 +46,9 @@ module Fastlane
17
46
  patched_pattern =
18
47
  case mode
19
48
  when :append
20
- "#{matches[0]}#{text}"
49
+ "#{matches[0]}#{text.apply_matches matches}"
21
50
  when :prepend
22
- "#{text}#{matches[0]}"
51
+ "#{text.apply_matches matches}#{matches[0]}"
23
52
  when :replace
24
53
  matches[0].sub regexp, text
25
54
  else
@@ -27,8 +56,8 @@ module Fastlane
27
56
  end
28
57
 
29
58
  contents = "#{matches.pre_match}#{patched_pattern}#{matches.post_match}"
30
- search_position = matches.pre_match.length + patched_pattern.length
31
59
  break unless global
60
+ search_position = matches.pre_match.length + patched_pattern.length
32
61
  end
33
62
  contents
34
63
  end
@@ -51,18 +80,24 @@ module Fastlane
51
80
  patched_regexp =
52
81
  case mode
53
82
  when :append
54
- /#{regexp_string}#{Regexp.quote(text)}/m
83
+ /#{regexp_string}#{text}/m
55
84
  when :prepend
56
- /#{Regexp.quote(text)}#{regexp_string}/m
85
+ # TODO: Capture groups aren't currently revertible in :prepend mode.
86
+ # This patched regexp can turn into something like /\1.*(\d+)/.
87
+ # The capture group reference cannot occur in the regexp before definition
88
+ # of the group. This would have to be transformed to something like
89
+ # /(\d+).*\1/. Patch reversion is probably not a major use case right
90
+ # now, so ignore for the moment.
91
+ /#{text}#{regexp_string}/m
57
92
  else
58
93
  raise ArgumentError, "Invalid mode argument. Specify :append or :prepend."
59
94
  end
60
95
 
61
96
  while (matches = patched_regexp.match(contents, search_position))
62
- reverted_text = matches[0].sub(text, '')
97
+ reverted_text = matches[0].sub(text.apply_matches(matches), '')
63
98
  contents = "#{matches.pre_match}#{reverted_text}#{matches.post_match}"
64
- search_position = matches.pre_match.length + reverted_text.length
65
99
  break unless global
100
+ search_position = matches.pre_match.length + reverted_text.length
66
101
  end
67
102
 
68
103
  contents
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Patch
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-01 00:00:00.000000000 Z
11
+ date: 2017-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -161,4 +161,3 @@ signing_key:
161
161
  specification_version: 4
162
162
  summary: Apply and revert pattern-based patches to any text file.
163
163
  test_files: []
164
- has_rdoc: