Class: FlutterVersionTool

Inherits:
Object
  • Object
show all
Defined in:
lib/flutter_version_tool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = "pubspec.yaml") ⇒ FlutterVersionTool

Returns a new instance of FlutterVersionTool.



10
11
12
13
14
15
16
17
18
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/flutter_version_tool.rb', line 10

def initialize(path = "pubspec.yaml")
# Load version from pubspec file

#

# Example:

#   >> fvt = FlutterVersionTool.new("some_project/path/pubspec.yaml")

#

# Arguments:

#   pubspecPath: (String)


  @pubspecPath = path
  
  begin
    pubspec = YAML::load_file(@pubspecPath)
  rescue
    raise 'Read pubspec.yaml failed'
  end
  
  version = pubspec["version"]
  
  begin 
      if not version.include? "+"
          raise
      end
      v_sections = version.split("+")
      @vName = v_sections[0].to_s
      @vCode = v_sections[1].to_i
  rescue
      @noCode = true
      @vName = version
      @vCode = 0
  end
  
  begin
      if not vName.include? "."
          raise
      end
      vName_sections = @vName.split(".")
      @vMajor = vName_sections[0].to_i
      @vMinor = vName_sections[1].to_i
      if (vName_sections.length() > 2)
      @vPatch = vName_sections[2].to_i
      else
      @vPatch = 0
      end
  rescue
      @vMajor = @vName.to_i
      @vMinor = 0
      @vPatch = 0
  end
  
end

Instance Attribute Details

#pubspecPathObject (readonly)

Returns the value of attribute pubspecPath.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def pubspecPath
  @pubspecPath
end

#vCodeObject (readonly)

Returns the value of attribute vCode.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def vCode
  @vCode
end

#vMajorObject (readonly)

Returns the value of attribute vMajor.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def vMajor
  @vMajor
end

#vMinorObject (readonly)

Returns the value of attribute vMinor.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def vMinor
  @vMinor
end

#vNameObject (readonly)

Returns the value of attribute vName.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def vName
  @vName
end

#vPatchObject (readonly)

Returns the value of attribute vPatch.



4
5
6
# File 'lib/flutter_version_tool.rb', line 4

def vPatch
  @vPatch
end

Instance Method Details

#bumpVersionCode(increment = 1) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/flutter_version_tool.rb', line 80

def bumpVersionCode(increment = 1)
  # Increment version build number (default by +1)

  #

  # Example:

  #   >> fvt.bumpVersionCode(1)

  # Arguments:

  #   increment: (Integer)  


  @vCode= @vCode+increment
  commitChanges
end

#bumpVersionName(level = "major", increment = 1) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/flutter_version_tool.rb', line 92

def bumpVersionName(level = "major", increment = 1)
  # Increment version name semantically (default major version by +1)

  #

  # Example:

  #   >> fvt.bumpVersionName("patch")

  # Arguments:

  #   level: ("major","minor","patch")

  #   increment: (Integer)     


  case level
      when "major"
          @vMajor=@vMajor+increment
          @vMinor=0
          @vPatch=0
          puts "Bumping major"
      when "minor"
          @vMinor=@vMinor+increment
          @vPatch=0
          puts "Bumping minor"
      when "patch"
          @vPatch=@vPatch+increment
          puts "Bumping patch"
      else puts "Nope"
  end
  commitChanges
end

#changeVersionCode(p_code) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/flutter_version_tool.rb', line 68

def changeVersionCode(p_code)
  # Change version build number directly to any number

  #

  # Example:

  #   >> fvt.changeVersionCode(140)

  # Arguments:

  #   p_code: (Integer)


  @vCode=p_code.to_i
  commitChanges
end

#vFullObject



6
7
8
# File 'lib/flutter_version_tool.rb', line 6

def vFull
  return "#{@vMajor.to_s}.#{@vMinor.to_s}.#{@vPatch.to_s}+#{@vCode.to_s}"
end