Class: Bump::BumpInfo

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

Overview

The bump information model

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, files, commit) ⇒ BumpInfo

Returns a new instance of BumpInfo.

Parameters:

  • version (Bump::VersionNumber)

    The version

  • files (Array)

    The replace patterns

  • commit (String)

    The commit message



11
12
13
14
15
16
17
18
19
20
# File 'lib/bump/domain/bump_info.rb', line 11

def initialize(version, files, commit)
  @version = version
  @files = files
  @commit = commit

  @commit = 'Bump to version v%.%.%' unless @commit

  @before_version = @version.to_s
  @after_version = @version.to_s
end

Instance Attribute Details

#after_versionObject (readonly)

Returns the value of attribute after_version.



6
7
8
# File 'lib/bump/domain/bump_info.rb', line 6

def after_version
  @after_version
end

#before_versionObject (readonly)

Returns the value of attribute before_version.



6
7
8
# File 'lib/bump/domain/bump_info.rb', line 6

def before_version
  @before_version
end

#commitObject (readonly)

Returns the value of attribute commit.



6
7
8
# File 'lib/bump/domain/bump_info.rb', line 6

def commit
  @commit
end

#filesObject (readonly)

Returns the value of attribute files.



6
7
8
# File 'lib/bump/domain/bump_info.rb', line 6

def files
  @files
end

#versionObject (readonly)

Returns the value of attribute version.



6
7
8
# File 'lib/bump/domain/bump_info.rb', line 6

def version
  @version
end

Instance Method Details

#bump(level) ⇒ Object

Performs bumping version.

Parameters:

  • level (Symbol)


30
31
32
33
# File 'lib/bump/domain/bump_info.rb', line 30

def bump(level)
  @version.bump level
  @after_version = @version.to_s
end

#commit_messageString

Gets the commit message with the current version number

Returns:

  • (String)


24
25
26
# File 'lib/bump/domain/bump_info.rb', line 24

def commit_message
  @commit.sub '%.%.%', @after_version
end

#create_update_rulesArray<Bump::FileUpdateRule>

Creates file update rules according to the current settings.

Returns:



51
52
53
54
55
# File 'lib/bump/domain/bump_info.rb', line 51

def create_update_rules
  @files.map do |file, pattern|
    FileUpdateRuleFactory.create(file, pattern, @before_version, @after_version)
  end.flatten
end

#perform_updatevoid

This method returns an undefined value.

Performs all updates.



60
61
62
# File 'lib/bump/domain/bump_info.rb', line 60

def perform_update
  create_update_rules.each(&:perform)
end

#preid=(preid) ⇒ Object

Sets the preid.

Parameters:

  • preid (String)

    The pre id



37
38
39
40
# File 'lib/bump/domain/bump_info.rb', line 37

def preid=(preid)
  @version.preid = preid
  @after_version = @version.to_s
end

#update_rulesArray<Bump::FileUpdateRules>

Gets the file update rules.

Returns:

  • (Array<Bump::FileUpdateRules>)


44
45
46
# File 'lib/bump/domain/bump_info.rb', line 44

def update_rules
  create_update_rules
end

#valid?Boolean

Checks the all the version patterns are available

Returns:

  • (Boolean)


66
67
68
69
70
71
72
# File 'lib/bump/domain/bump_info.rb', line 66

def valid?
  create_update_rules.each do |rule|
    return false if !rule.file_exists || !rule.pattern_exists
  end

  true
end