Sha256: 004c06a66495633299585ae141b11ec8d550b531104af5b4960dc05e938cb469

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

module Andrake::Manifest::Version
  def version
    [version_major, version_minor, version_patch].join(".")
  end

  def bump_major
    self.version_major += 1
    self.version_minor = 0
    self.version_patch = 0
    self.version_code += 1
    self
  end

  def bump_minor
    self.version_minor += 1
    self.version_patch = 0
    self.version_code += 1
    self
  end

  def bump_patch
    self.version_patch += 1
    self.version_code += 1
    self
  end

  def update_version
    manifest["android:versionName"] = version.to_s
    manifest["android:versionCode"] = version_code.to_s
    self
  end

  [:major, :minor, :patch].each do |element|
    define_method("bump_#{element}!".to_sym) do
      send("bump_#{element}".to_sym).update_version.save
      self
    end
  end

  [:major, :minor, :patch, :code].each do |element|
    val_name = "@version_#{element}".to_sym

    define_method("version_#{element}".to_sym) do
      load_version unless instance_variable_get(val_name)
      instance_variable_get(val_name)
    end

    define_method("version_#{element}=".to_sym) do |val|
      instance_variable_set(val_name, val)
      val
    end

    protected "version_#{element}=".to_sym
  end

  private
  def manifest
    @manifest ||= @document.xpath('/manifest').first
  end

  def load_version
    @version_major, @version_minor, @version_patch = manifest["versionName"].split(/\./).map(&:to_i) + [0, 0, 0]
    @version_code = manifest["versionCode"].to_i
    true
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
andrake-1.1.1 lib/andrake/manifest/version.rb
andrake-1.1.0 lib/andrake/manifest/version.rb
andrake-1.0.0 lib/andrake/manifest/version.rb