Class: Incr::Command::Mix

Inherits:
Object
  • Object
show all
Defined in:
lib/incr/command/mix.rb

Constant Summary collapse

VERSION_REGEX =
/@?version:?\W*\"(\d*.\d*.\d*)"/
VERSION_REPLACEMENT_PATTERNS =
[
  "version: \"%s\"",
  "@version \"%s\""
]

Instance Method Summary collapse

Constructor Details

#initialize(args, global_options) ⇒ Mix

Returns a new instance of Mix.



10
11
12
13
14
15
16
17
# File 'lib/incr/command/mix.rb', line 10

def initialize(args, global_options)
  @segment = args[0]
  @mix_file_filename = File.join('.', global_options[:version_file_dir], 'mix.exs')
  @tag_pattern = global_options[:tag_name_pattern]
  @commit = global_options[:commit]
  @tag = global_options[:tag]
  @noop = global_options[:noop]
end

Instance Method Details

#executeObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/incr/command/mix.rb', line 19

def execute
  if !File.exist?(@mix_file_filename)
    warn("'#{@mix_file_filename}': file not found.")
    return
  end

  file_content = IO.read(@mix_file_filename)
  if file_content == nil
    return
  end

  file_version = file_content.match(VERSION_REGEX)[1]
  old_version = SemVersion.new(file_version)
  new_version = Incr::Service::Version.increment_segment(old_version, @segment)
  replace_file_version(old_version, new_version)

  new_tag = @tag_pattern % new_version.to_s

  puts new_tag

  if not @noop
    repository = Incr::Service::Repository.new('.')
    repository.add(@mix_file_filename)
    repository.commit(new_tag) if @commit
    repository.tag(new_tag) if @tag
  end
end