fastlane-plugin-patch 0.4.0 → 0.4.1

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: ca22332d6aadf5ba6d6ef8caae93aa206e1cceb0
4
- data.tar.gz: 0e7329cfd451552872dc685fef793709c837a246
3
+ metadata.gz: 168fcc13fa33b2037f80ebe36b8eb19b2a065d66
4
+ data.tar.gz: 2a57c7080d0197ceeef5ce90be08f76ba2e79237
5
5
  SHA512:
6
- metadata.gz: 52cbcad0a3515ce3b37c484a1bbc6999bbf97639832d06f0f1e41add939bd40a15831e554b12319b5a76487c26860a2929b322c427fe2caed258d1bf72112cfd
7
- data.tar.gz: 9d5170068631d7d53cccfcc3f9f3a800d1eaeb01c7b59d2bf22f2d4ae471573600087611fb2f159e0f7fa28df6ad623263cb6c46c70f355d9f994581d9b839b0
6
+ metadata.gz: 1132ec65c4b40ae558d0cb5e312113e6ab7cf31910ee72a034b360923e221b4bb5d51e634864db44c565a5dc07fe609c27d777bcd951ddf1f83af0be13b5fdd4
7
+ data.tar.gz: 104cbfa158a62f046569f3c0eee24ee5a885fe5345d571033e12f1c59594402d99b4fa4aef7bc583491c50a27de1e94d80321777e9b5ba6ff97fe624920ef761
@@ -34,12 +34,12 @@ module Fastlane
34
34
 
35
35
  files.each do |file|
36
36
  modified_contents = File.open(file, "r") do |f|
37
- helper.apply_patch f.read,
38
- params[:regexp],
39
- params[:text],
40
- params[:global],
41
- params[:mode],
42
- params[:offset]
37
+ PatternPatch::Utilities.apply_patch f.read,
38
+ params[:regexp],
39
+ params[:text],
40
+ params[:global],
41
+ params[:mode],
42
+ params[:offset]
43
43
  end
44
44
 
45
45
  File.open(file, "w") { |f| f.write modified_contents }
@@ -1,3 +1,4 @@
1
+ require 'pattern_patch'
1
2
  require 'yaml'
2
3
 
3
4
  module Fastlane
@@ -35,19 +36,19 @@ module Fastlane
35
36
  files.each do |file|
36
37
  modified_contents = File.open(file, "r") do |f|
37
38
  if params[:revert]
38
- helper.revert_patch f.read,
39
- params[:regexp],
40
- params[:text],
41
- params[:global],
42
- params[:mode],
43
- params[:offset]
39
+ PatternPatch::Utilities.revert_patch f.read,
40
+ params[:regexp],
41
+ params[:text],
42
+ params[:global],
43
+ params[:mode],
44
+ params[:offset]
44
45
  else
45
- helper.apply_patch f.read,
46
- params[:regexp],
47
- params[:text],
48
- params[:global],
49
- params[:mode],
50
- params[:offset]
46
+ PatternPatch::Utilities.apply_patch f.read,
47
+ params[:regexp],
48
+ params[:text],
49
+ params[:global],
50
+ params[:mode],
51
+ params[:offset]
51
52
  end
52
53
  end
53
54
 
@@ -1,3 +1,4 @@
1
+ require 'pattern_patch'
1
2
  require 'yaml'
2
3
 
3
4
  module Fastlane
@@ -34,12 +35,12 @@ module Fastlane
34
35
 
35
36
  files.each do |file|
36
37
  modified_contents = File.open(file, "r") do |f|
37
- helper.revert_patch f.read,
38
- params[:regexp],
39
- params[:text],
40
- params[:global],
41
- params[:mode],
42
- params[:offset]
38
+ PatternPatch::Utilities.revert_patch f.read,
39
+ params[:regexp],
40
+ params[:text],
41
+ params[:global],
42
+ params[:mode],
43
+ params[:offset]
43
44
  end
44
45
 
45
46
  File.open(file, "w") { |f| f.write modified_contents }
@@ -1,108 +1,7 @@
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
-
30
1
  module Fastlane
31
2
  module Helper
32
3
  class PatchHelper
33
4
  class << self
34
- # Add the specified text after the specified pattern.
35
- # Returns a modified copy of the string.
36
- #
37
- # :contents: A string to modify, e.g. the contents of a file
38
- # :regexp: A regular expression specifying a pattern to be matched
39
- # :text: Text to be appended to the specified pattern
40
- # :global: Boolean flag. If true, patch all occurrences of the regex.
41
- # :mode: :append, :prepend or :replace to specify how to apply the patch
42
- # :offset: Starting position for matching
43
- def apply_patch(contents, regexp, text, global, mode, offset)
44
- search_position = offset
45
- while (matches = regexp.match(contents, search_position))
46
- patched_pattern =
47
- case mode
48
- when :append
49
- "#{matches[0]}#{text.apply_matches matches}"
50
- when :prepend
51
- "#{text.apply_matches matches}#{matches[0]}"
52
- when :replace
53
- matches[0].sub regexp, text
54
- else
55
- raise ArgumentError, "Invalid mode argument. Specify :append, :prepend or :replace."
56
- end
57
-
58
- contents = "#{matches.pre_match}#{patched_pattern}#{matches.post_match}"
59
- break unless global
60
- search_position = matches.pre_match.length + patched_pattern.length
61
- end
62
- contents
63
- end
64
-
65
- # Reverts a patch. Use the same arguments that were supplied to apply_patch.
66
- # The mode argument can only be :append or :prepend. Patches using :replace
67
- # cannot be reverted.
68
- # Returns a modified copy of the string.
69
- #
70
- # :contents: A string to modify, e.g. the contents of a file
71
- # :regexp: A regular expression specifying a pattern to be matched
72
- # :text: Text to be appended to the specified pattern
73
- # :global: Boolean flag. If true, patch all occurrences of the regex.
74
- # :mode: :append or :prepend. :replace patches cannot be reverted automatically.
75
- # :offset: Starting position for matching
76
- def revert_patch(contents, regexp, text, global, mode, offset)
77
- search_position = offset
78
- regexp_string = regexp.to_s
79
-
80
- patched_regexp =
81
- case mode
82
- when :append
83
- /#{regexp_string}#{text}/m
84
- when :prepend
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
92
- else
93
- raise ArgumentError, "Invalid mode argument. Specify :append or :prepend."
94
- end
95
-
96
- while (matches = patched_regexp.match(contents, search_position))
97
- reverted_text = matches[0].sub(text.apply_matches(matches), '')
98
- contents = "#{matches.pre_match}#{reverted_text}#{matches.post_match}"
99
- break unless global
100
- search_position = matches.pre_match.length + reverted_text.length
101
- end
102
-
103
- contents
104
- end
105
-
106
5
  def files_from_params(params)
107
6
  case params[:files]
108
7
  when Array
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Patch
3
- VERSION = "0.4.0"
3
+ VERSION = "0.4.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-10-07 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pattern_patch
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: pry
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
170
  version: '0'
157
171
  requirements: []
158
172
  rubyforge_project:
159
- rubygems_version: 2.6.13
173
+ rubygems_version: 2.6.14
160
174
  signing_key:
161
175
  specification_version: 4
162
176
  summary: Apply and revert pattern-based patches to any text file.