class PodspecBump::Bump

Constants

BUMPS
OPTIONS
VERSION_REGEX

Public Class Methods

bump(current, next_version, options) click to toggle source
# File lib/podspec_bump.rb, line 37
def self.bump(current, next_version, options)
  replace(current, next_version)
  commit(next_version, options) if options[:commit]
  ["Bump version #{current} to #{next_version}", 0]
end
bump_part(part, options) click to toggle source
# File lib/podspec_bump.rb, line 68
def self.bump_part(part, options)
  current = version_from_file
  next_version = next_version(current, part)
  bump(current, next_version, options)
end
commit(version, options) click to toggle source
# File lib/podspec_bump.rb, line 48
def self.commit(version, options)
  return unless File.directory?(".git")
  system_cmd("git add --update #{spec_file()} && git commit -m 'v#{version}'")
  system_cmd("git tag -a -m 'Bump to v#{version}' #{version}")
end
defaults() click to toggle source
# File lib/podspec_bump.rb, line 12
def self.defaults
  {
    :commit => true
  }
end
next_version(current, part) click to toggle source
# File lib/podspec_bump.rb, line 74
def self.next_version(current, part)
  major, minor, patch = current.split('.')

  case part
  when "major"
    major, minor, patch = major.succ, 0, 0, nil
  when "minor"
    minor, patch = minor.succ, 0
  when "patch"
    patch = patch.succ
  else
    raise "unknown part #{part.inspect}"
  end

  [major, minor, patch].compact.join('.')
end
replace(old, new) click to toggle source
# File lib/podspec_bump.rb, line 43
def self.replace(old, new)
  content = File.read(spec_file)
  File.open(spec_file, "w"){|f| f.write(content.sub(old, new)) }
end
run(bump, options={}) click to toggle source
# File lib/podspec_bump.rb, line 18
def self.run(bump, options={})
  options = defaults.merge(options)
  
  case bump
  when *BUMPS
    bump_part(bump, options)
  when "current"
    puts "Current version: #{version_from_file()}"
  else
    raise InvalidOptionError
  end
rescue InvalidOptionError
  puts "Invalid option. Choose between #{OPTIONS.join(',')}."
rescue NotfoundSpecFileError
  puts "Not found your spec file"
rescue Exception => e
  puts "Something wrong happened: #{e.message}\n#{e.backtrace.join("\n")}"
end
spec_file() click to toggle source
# File lib/podspec_bump.rb, line 59
def self.spec_file
  Dir.glob('*.podspec')[0]
end
system_cmd(command) click to toggle source
# File lib/podspec_bump.rb, line 54
def self.system_cmd(command)
  puts command
  system command
end
version_from_file() click to toggle source
# File lib/podspec_bump.rb, line 63
def self.version_from_file
  raise NotfoundSpecFileError if Dir.glob('*.podspec').empty?
  File.read(spec_file)[VERSION_REGEX]
end