Class: CaptiveRelease::Config
- Inherits:
-
Object
- Object
- CaptiveRelease::Config
- Defined in:
- lib/captive_release/config.rb
Instance Attribute Summary collapse
-
#capacitor ⇒ Object
readonly
Returns the value of attribute capacitor.
-
#expo ⇒ Object
readonly
Returns the value of attribute expo.
-
#version_files ⇒ Object
readonly
Returns the value of attribute version_files.
Class Method Summary collapse
- .load(path = CONFIG_FILE) ⇒ Object
- .write(version_files, path = CONFIG_FILE, expo: nil, capacitor: nil) ⇒ Object
Instance Method Summary collapse
- #capacitor? ⇒ Boolean
- #current_version ⇒ Object
- #expo? ⇒ Boolean
-
#initialize(version_files, expo = nil, capacitor = nil) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(version_files, expo = nil, capacitor = nil) ⇒ Config
Returns a new instance of Config.
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
#capacitor ⇒ Object (readonly)
Returns the value of attribute capacitor.
33 34 35 |
# File 'lib/captive_release/config.rb', line 33 def capacitor @capacitor end |
#expo ⇒ Object (readonly)
Returns the value of attribute expo.
33 34 35 |
# File 'lib/captive_release/config.rb', line 33 def expo @expo end |
#version_files ⇒ Object (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
65 66 67 |
# File 'lib/captive_release/config.rb', line 65 def capacitor? !capacitor.nil? end |
#current_version ⇒ Object
69 70 71 |
# File 'lib/captive_release/config.rb', line 69 def current_version version_files.first.read_version end |
#expo? ⇒ Boolean
61 62 63 |
# File 'lib/captive_release/config.rb', line 61 def expo? !expo.nil? end |