Class: StringInreplaceExtension Private
- Inherits:
-
Object
- Object
- StringInreplaceExtension
- Extended by:
- T::Sig
- Defined in:
- Library/Homebrew/utils/string_inreplace_extension.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Used by the inreplace
function (in utils.rb
).
Instance Attribute Summary collapse
- #errors ⇒ Object private
- #inreplace_string ⇒ Object private
Instance Method Summary collapse
- #change_make_var!(flag, new_value) ⇒ Object private
- #get_make_var(flag) ⇒ Object private
-
#gsub!(before, after, audit_result = true) ⇒ Object
private
rubocop:disable Style/OptionalBooleanParameter.
-
#initialize(string) ⇒ StringInreplaceExtension
constructor
private
A new instance of StringInreplaceExtension.
- #remove_make_var!(flags) ⇒ Object private
- #sub!(before, after) ⇒ Object private
Constructor Details
#initialize(string) ⇒ StringInreplaceExtension
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of StringInreplaceExtension.
13 14 15 16 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 13 def initialize(string) @inreplace_string = string @errors = [] end |
Instance Attribute Details
#errors ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 10 def errors @errors end |
#inreplace_string ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
10 11 12 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 10 def inreplace_string @inreplace_string end |
Instance Method Details
#change_make_var!(flag, new_value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 49 50 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 46 def change_make_var!(flag, new_value) return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, "#{flag}=#{new_value}", false) errors << "expected to change #{flag.inspect} to #{new_value.inspect}" end |
#get_make_var(flag) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 69 def get_make_var(flag) inreplace_string[/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=[ \t]*((?:.*\\\n)*.*)$/, 1] end |
#gsub!(before, after, audit_result = true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
rubocop:disable Style/OptionalBooleanParameter
35 36 37 38 39 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 35 def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter result = inreplace_string.gsub!(before, after) errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil? result end |
#remove_make_var!(flags) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
56 57 58 59 60 61 62 63 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 56 def remove_make_var!(flags) Array(flags).each do |flag| # Also remove trailing \n, if present. unless gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?+:!]?=(?:.*\\\n)*.*$\n?/, "", false) errors << "expected to remove #{flag.inspect}" end end end |
#sub!(before, after) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
22 23 24 25 26 |
# File 'Library/Homebrew/utils/string_inreplace_extension.rb', line 22 def sub!(before, after) result = inreplace_string.sub!(before, after) errors << "expected replacement of #{before.inspect} with #{after.inspect}" unless result result end |