Class: Afterlife::Release::ChangeVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/afterlife/release/change_version.rb

Constant Summary collapse

RUBY_REGEXP =
/VERSION\s*=\s*['"]#{Bump::Semver::VERSION_REGEX}['"]/.freeze
REGEXPS =
{
  ruby: RUBY_REGEXP,
  gem: RUBY_REGEXP,
  node: /"version":\s*"#{Bump::Semver::VERSION_REGEX}"/,
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(new_version, options) ⇒ ChangeVersion

Returns a new instance of ChangeVersion.



23
24
25
26
27
# File 'lib/afterlife/release/change_version.rb', line 23

def initialize(new_version, options)
  @file_path = options[:real_path]
  @regexp = REGEXPS[options[:type].to_sym]
  @new_version = new_version
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



21
22
23
# File 'lib/afterlife/release/change_version.rb', line 21

def file_path
  @file_path
end

#new_versionObject (readonly)

Returns the value of attribute new_version.



21
22
23
# File 'lib/afterlife/release/change_version.rb', line 21

def new_version
  @new_version
end

#regexpObject (readonly)

Returns the value of attribute regexp.



21
22
23
# File 'lib/afterlife/release/change_version.rb', line 21

def regexp
  @regexp
end

Class Method Details

.call(new_version) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/afterlife/release/change_version.rb', line 13

def self.call(new_version)
  Afterlife.current_repo.version_files.map do |file_def|
    instance = new(new_version, file_def)
    instance.call
    instance.file_path
  end
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
36
# File 'lib/afterlife/release/change_version.rb', line 29

def call
  fail "could not find a version for #{file_path}" unless current_version

  File.write(
    file_path,
    content.sub(current_version, new_version),
  )
end

#contentObject



43
44
45
# File 'lib/afterlife/release/change_version.rb', line 43

def content
  @content ||= File.read(file_path)
end

#current_versionObject



38
39
40
41
# File 'lib/afterlife/release/change_version.rb', line 38

def current_version
  content[regexp]
  Regexp.last_match(1)
end