Class: Semverify::VersionFile

Inherits:
Object
  • Object
show all
Defined in:
lib/semverify/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 = Semverify::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:



27
28
29
30
31
32
33
34
35
# File 'lib/semverify/version_file.rb', line 27

def initialize(path, content_before, version, content_after)
  raise Semverify::Error, 'version must be an IncrementableSemver' unless
    version.is_a?(Semverify::IncrementableSemver)

  @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 = Semverify::VersionFile.new('lib/semverify/version.rb', 'VERSION = "', '1.2.3', '"')
version_file.content_after # => '"'

Returns:

  • (String)


81
82
83
# File 'lib/semverify/version_file.rb', line 81

def content_after
  @content_after
end

#content_beforeString (readonly)

The content in the version file before the version

Examples:

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

Returns:

  • (String)


57
58
59
# File 'lib/semverify/version_file.rb', line 57

def content_before
  @content_before
end

#pathString (readonly)

The path to the file relative to the current directory

Examples:

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

Returns:

  • (String)


46
47
48
# File 'lib/semverify/version_file.rb', line 46

def path
  @path
end

#versionSemverify::IncrementableSemver

The version from the version file

Examples:

version = Semverify::IncrementableSemver.new('1.2.3')
version_file = Semverify::VersionFile.new('lib/semverify/version.rb', 'VERSION = "', version, '"')
version_file.version.to_s # => '1.2.3'

Returns:

Raises:



70
71
72
# File 'lib/semverify/version_file.rb', line 70

def version
  @version
end