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
61
62
# 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

  parseSemVer(@vName)

  # 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



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/flutter_version_tool.rb', line 108

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



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/flutter_version_tool.rb', line 120

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/flutter_version_tool.rb', line 96

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

#changeVersionName(p_name) ⇒ Object



90
91
92
93
94
# File 'lib/flutter_version_tool.rb', line 90

def changeVersionName(p_name)
  @vName = p_name.to_s
  parseSemVer(@vName)
  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