class Bump::FileUpdateRule
The file update rule model
is able to perform actual file update
Constants
- PLACEHOLDER_PATTERN
The placeholder pattern
Attributes
after_pattern[R]
before_pattern[R]
file[R]
Public Class Methods
new(file, pattern, before_version, after_version)
click to toggle source
@param [String] file @param [String] pattern @param [Bump::VersionNumber] before_version @param [Bump::VersionNumber] after_version
# File lib/bump/domain/file_update_rule.rb, line 15 def initialize(file, pattern, before_version, after_version) @file = file @pattern = pattern || PLACEHOLDER_PATTERN # default pattern is '%.%.%' @before_version = before_version @after_version = after_version @before_pattern = @pattern.sub PLACEHOLDER_PATTERN, @before_version @after_pattern = @pattern.sub PLACEHOLDER_PATTERN, @after_version end
Public Instance Methods
file_exists()
click to toggle source
Returns true if the file exists @return [Boolean]
# File lib/bump/domain/file_update_rule.rb, line 33 def file_exists File.exist? @file end
file_get_contents()
click to toggle source
Gets the contents of the file
@return [String]
# File lib/bump/domain/file_update_rule.rb, line 27 def file_get_contents File.read @file, encoding: Encoding::UTF_8 end
pattern_exists()
click to toggle source
Checks if the pattern found in the file @return [Boolean]
# File lib/bump/domain/file_update_rule.rb, line 39 def pattern_exists !file_get_contents.index(@before_pattern).nil? end
perform()
click to toggle source
Performs file update @return [void]
# File lib/bump/domain/file_update_rule.rb, line 45 def perform File.write @file, file_get_contents.sub(@before_pattern, @after_pattern) end