Class: CaptiveRelease::VersionFile

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

Constant Summary collapse

TYPES =
%w[package_json plain app_config_js ruby_version android_gradle ios_plist].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, type) ⇒ VersionFile

Returns a new instance of VersionFile.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/captive_release/version_file.rb', line 11

def initialize(path, type)
  raise ArgumentError, "Unknown type #{type}. Must be one of: #{TYPES.join(", ")}" unless TYPES.include?(type)

  @path = path
  @type = type
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/captive_release/version_file.rb', line 9

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.



9
10
11
# File 'lib/captive_release/version_file.rb', line 9

def type
  @type
end

Instance Method Details

#read_versionObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/captive_release/version_file.rb', line 18

def read_version
  raise "File not found: #{path}" unless File.exist?(path)

  case type
  when "package_json"    then JSON.parse(File.read(path))["version"]
  when "plain"           then File.read(path).strip
  when "app_config_js"   then read_app_config_js
  when "ruby_version"    then read_ruby_version
  when "android_gradle"  then read_android_gradle
  when "ios_plist"       then read_ios_plist
  end
end

#to_hObject



44
45
46
# File 'lib/captive_release/version_file.rb', line 44

def to_h
  { "path" => path, "type" => type }
end

#write_version(new_version) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/captive_release/version_file.rb', line 31

def write_version(new_version)
  raise "File not found: #{path}" unless File.exist?(path)

  case type
  when "package_json"    then write_package_json(new_version)
  when "plain"           then File.write(path, "#{new_version}\n")
  when "app_config_js"   then write_app_config_js(new_version)
  when "ruby_version"    then write_ruby_version(new_version)
  when "android_gradle"  then write_android_gradle(new_version)
  when "ios_plist"       then write_ios_plist(new_version)
  end
end