Class: Bump::BumpInfoRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/bump/domain/bump_info_repository.rb

Overview

The repository class for the bump info persistence in file as yaml string

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ BumpInfoRepository

Returns a new instance of BumpInfoRepository.

Parameters:

  • file (String)


8
9
10
# File 'lib/bump/domain/bump_info_repository.rb', line 8

def initialize(file)
  @file = file
end

Instance Method Details

#from_fileBump::BumpInfo

Gets the bump info from the given file

Parameters:

  • file (String)

Returns:



16
17
18
19
20
21
# File 'lib/bump/domain/bump_info_repository.rb', line 16

def from_file
  config = YAML.load_file @file
  version = VersionNumberFactory.from_string config['version']

  BumpInfo.new version, config['files'], config['commit']
end

#save(bump_info) ⇒ void

This method returns an undefined value.

Saves the bump info

Parameters:



27
28
29
# File 'lib/bump/domain/bump_info_repository.rb', line 27

def save(bump_info)
  File.write @file, to_yaml(bump_info)
end

#to_yaml(bump_info) ⇒ Hash

Parameters:

Returns:

  • (Hash)


34
35
36
37
38
39
40
41
42
# File 'lib/bump/domain/bump_info_repository.rb', line 34

def to_yaml(bump_info)
  hash = { 'version' => bump_info.version.to_s }

  hash['commit'] = bump_info.commit if bump_info.commit

  hash['files'] = bump_info.files

  hash.to_yaml
end