Class: VersionBoss::Gem::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/version_boss/gem/version_file.rb

Overview

Represents a file that contains the gem's version and can update the version

Use VersionFileFactory.find create a VersionFile instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, content_before, version, content_after) ⇒ VersionFile

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.

Create an VersionFile instance

Use VersionFileFactory.find create a VersionFile instance.

Examples:

version_file = VersionFile.new('VERSION', 'VERSION = "', '1.2.3', '"')

Parameters:

  • path (String)

    the path to the file relative to the current directory

  • content_before (String)

    the content before the version

  • version (String)

    the version

  • content_after (String)

    the content after the version

Raises:



28
29
30
31
32
33
34
35
36
37
# File 'lib/version_boss/gem/version_file.rb', line 28

def initialize(path, content_before, version, content_after)
  unless version.is_a?(VersionBoss::Gem::IncrementableVersion)
    raise VersionBoss::Error, 'version must be an IncrementableVersion'
  end

  @path = path
  @content_before = content_before
  @version = version
  @content_after = content_after
end

Instance Attribute Details

#content_afterString (readonly)

The content in the version file before the version

Examples:

version_file = VersionFile.new('lib/version_boss/version.rb', 'VERSION = "', '1.2.3', '"')
version_file.content_after # => '"'

Returns:

  • (String)


83
84
85
# File 'lib/version_boss/gem/version_file.rb', line 83

def content_after
  @content_after
end

#content_beforeString (readonly)

The content in the version file before the version

Examples:

version_file = VersionFile.new('lib/version_boss/version.rb', 'VERSION = "', '1.2.3', '"')
version_file.content_before # => 'VERSION = "'

Returns:

  • (String)


59
60
61
# File 'lib/version_boss/gem/version_file.rb', line 59

def content_before
  @content_before
end

#pathString (readonly)

The path to the file relative to the current directory

Examples:

version_file = VersionFile.new('lib/version_boss/version.rb', 'VERSION = "', '1.2.3', '"')
version_file.path # => 'lib/version_boss/version.rb'

Returns:

  • (String)


48
49
50
# File 'lib/version_boss/gem/version_file.rb', line 48

def path
  @path
end

#versionVersionBoss::IncrementableVersion

The version from the version file

Examples:

version = VersionBoss::IncrementableVersion.new('1.2.3')
version_file = VersionFile.new('lib/version_boss/version.rb', 'VERSION = "', version, '"')
version_file.version.to_s # => '1.2.3'

Returns:

  • (VersionBoss::IncrementableVersion)

Raises:



72
73
74
# File 'lib/version_boss/gem/version_file.rb', line 72

def version
  @version
end