Class: Bump::FileUpdateRule
- Inherits:
-
Object
- Object
- Bump::FileUpdateRule
- Defined in:
- lib/bump/domain/file_update_rule.rb
Overview
The file update rule model
is able to perform actual file update
Constant Summary collapse
- PLACEHOLDER_PATTERN =
The placeholder pattern
'%.%.%'
Instance Method Summary collapse
-
#afterPattern ⇒ String
Gets the version string after bumping.
-
#beforePattern ⇒ String
Gets the version string before bumping.
-
#file ⇒ String
Gets the file name.
-
#fileGetContents ⇒ String
Gets the contents of the file.
-
#initialize(file, pattern, before_version, after_version) ⇒ FileUpdateRule
constructor
A new instance of FileUpdateRule.
-
#patternExists ⇒ Boolean
Checks if the pattern found in the file.
-
#perform ⇒ void
Performs file update.
Constructor Details
#initialize(file, pattern, before_version, after_version) ⇒ FileUpdateRule
Returns a new instance of FileUpdateRule.
17 18 19 20 21 22 23 24 |
# File 'lib/bump/domain/file_update_rule.rb', line 17 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 |
Instance Method Details
#afterPattern ⇒ String
Gets the version string after bumping
43 44 45 |
# File 'lib/bump/domain/file_update_rule.rb', line 43 def afterPattern @after_pattern end |
#beforePattern ⇒ String
Gets the version string before bumping
36 37 38 |
# File 'lib/bump/domain/file_update_rule.rb', line 36 def beforePattern @before_pattern end |
#file ⇒ String
Gets the file name
29 30 31 |
# File 'lib/bump/domain/file_update_rule.rb', line 29 def file @file end |
#fileGetContents ⇒ String
Gets the contents of the file
50 51 52 |
# File 'lib/bump/domain/file_update_rule.rb', line 50 def fileGetContents File.read @file, :encoding => Encoding::UTF_8 end |
#patternExists ⇒ Boolean
Checks if the pattern found in the file
57 58 59 |
# File 'lib/bump/domain/file_update_rule.rb', line 57 def patternExists fileGetContents.index @before_pattern end |
#perform ⇒ void
This method returns an undefined value.
Performs file update
64 65 66 |
# File 'lib/bump/domain/file_update_rule.rb', line 64 def perform File.write @file, fileGetContents.sub(@before_pattern, @after_pattern) end |