Class: Bump::FileUpdateRule

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(file, pattern, before_version, after_version) ⇒ FileUpdateRule

Returns a new instance of FileUpdateRule.

Parameters:



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

#afterPatternString

Gets the version string after bumping

Returns:

  • (String)


43
44
45
# File 'lib/bump/domain/file_update_rule.rb', line 43

def afterPattern
    @after_pattern
end

#beforePatternString

Gets the version string before bumping

Returns:

  • (String)


36
37
38
# File 'lib/bump/domain/file_update_rule.rb', line 36

def beforePattern
    @before_pattern
end

#fileString

Gets the file name

Returns:

  • (String)


29
30
31
# File 'lib/bump/domain/file_update_rule.rb', line 29

def file
    @file
end

#fileGetContentsString

Gets the contents of the file

Returns:

  • (String)


50
51
52
# File 'lib/bump/domain/file_update_rule.rb', line 50

def fileGetContents
    File.read @file, :encoding => Encoding::UTF_8
end

#patternExistsBoolean

Checks if the pattern found in the file

Returns:

  • (Boolean)


57
58
59
# File 'lib/bump/domain/file_update_rule.rb', line 57

def patternExists
    fileGetContents.index @before_pattern
end

#performvoid

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