Class: CaptiveRelease::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_files, expo = nil, capacitor = nil) ⇒ Config

Returns a new instance of Config.

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
# File 'lib/captive_release/config.rb', line 53

def initialize(version_files, expo = nil, capacitor = nil)
  raise ArgumentError, "version_files cannot be empty" if version_files.empty?

  @version_files = version_files
  @expo          = expo
  @capacitor     = capacitor
end

Instance Attribute Details

#capacitorObject (readonly)

Returns the value of attribute capacitor.



33
34
35
# File 'lib/captive_release/config.rb', line 33

def capacitor
  @capacitor
end

#expoObject (readonly)

Returns the value of attribute expo.



33
34
35
# File 'lib/captive_release/config.rb', line 33

def expo
  @expo
end

#version_filesObject (readonly)

Returns the value of attribute version_files.



33
34
35
# File 'lib/captive_release/config.rb', line 33

def version_files
  @version_files
end

Class Method Details

.load(path = CONFIG_FILE) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/captive_release/config.rb', line 35

def self.load(path = CONFIG_FILE)
  raise "#{CONFIG_FILE} not found. Run `captive-release init` first." unless File.exist?(path)

  data = JSON.parse(File.read(path))
  new(
    data["version_files"].map { |f| VersionFile.new(f["path"], f["type"]) },
    ExpoConfig.from_hash(data["expo"]),
    CapacitorConfig.from_hash(data["capacitor"])
  )
end

.write(version_files, path = CONFIG_FILE, expo: nil, capacitor: nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/captive_release/config.rb', line 46

def self.write(version_files, path = CONFIG_FILE, expo: nil, capacitor: nil)
  data = { "version_files" => version_files.map(&:to_h) }
  data["expo"]      = expo.to_h      if expo
  data["capacitor"] = capacitor.to_h if capacitor
  File.write(path, "#{JSON.pretty_generate(data)}\n")
end

Instance Method Details

#capacitor?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/captive_release/config.rb', line 65

def capacitor?
  !capacitor.nil?
end

#current_versionObject



69
70
71
# File 'lib/captive_release/config.rb', line 69

def current_version
  version_files.first.read_version
end

#expo?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/captive_release/config.rb', line 61

def expo?
  !expo.nil?
end