Class: ReleaseMe::BumpVersion

Inherits:
Object
  • Object
show all
Includes:
Adapter
Defined in:
lib/release_me/bump_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Adapter

#adapter_config, #adapter_list, #local_config, #version_file

Constructor Details

#initialize(options) ⇒ BumpVersion

Returns a new instance of BumpVersion.



12
13
14
# File 'lib/release_me/bump_version.rb', line 12

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/release_me/bump_version.rb', line 10

def options
  @options
end

Instance Method Details

#app_configObject



24
25
26
# File 'lib/release_me/bump_version.rb', line 24

def app_config
  @app_config ||= adapter_config(options[:project_path])
end

#app_version_fileObject



16
17
18
# File 'lib/release_me/bump_version.rb', line 16

def app_version_file
  app_config.version_file
end

#new_versionObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/release_me/bump_version.rb', line 28

def new_version
  unless @new_version
    @new_version = case version_type
                   when :commit
                     `git rev-parse HEAD`.chomp[0..8]
                   when :time
                     Time.now.strftime('%Y.%m.%d.%H%M')
                   when :semver
                     app_config.current_version.next
                   else
                     options[:version] || app_config.current_version.next
                   end
  end
  @new_version
end

#runObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/release_me/bump_version.rb', line 44

def run
  app_config_lines = File.read(app_config.version_file)
  app_config_lines.gsub!(app_config.current_version, new_version)
  debug_message = "updated version string from #{app_config.current_version} to #{new_version}"
  if options[:json]
    output = JSON.pretty_generate(message: debug_message,
                                  file_content: app_config_lines,
                                  new_version: new_version,
                                  old_version: app_config.current_version)
  else
    STDERR.puts debug_message
    File.write(app_config.version_file, app_config_lines) unless options[:dry_run]
    output = app_config_lines
  end
  output
end

#version_typeObject



20
21
22
# File 'lib/release_me/bump_version.rb', line 20

def version_type
  options[:version]
end