class Okapi::PersistentVariables
Public Class Methods
new(config)
click to toggle source
# File lib/okapi/cli/config.rb, line 50 def initialize(config) @config = config @variables = {} end
Public Instance Methods
delete_all!(list)
click to toggle source
# File lib/okapi/cli/config.rb, line 82 def delete_all!(list) original = @variables @variables = @variables.reject { |k| list.include? k } original.length - @variables.length end
filename()
click to toggle source
# File lib/okapi/cli/config.rb, line 55 def filename @config.filename end
load!()
click to toggle source
# File lib/okapi/cli/config.rb, line 71 def load! read! @variables.each_pair do |k,v| ENV[k] = v end end
merge(lines)
click to toggle source
# File lib/okapi/cli/config.rb, line 78 def merge(lines) @variables = @variables.merge lines.map { |l| l.split("=") }.to_h end
read!(force: false)
click to toggle source
# File lib/okapi/cli/config.rb, line 59 def read!(force: false) lines = @config.read!(force: force).split(/\n+/).map(&:strip).reject(&:empty?) @variables = lines.map { |l| l.split("=") }.to_h end
write!()
click to toggle source
# File lib/okapi/cli/config.rb, line 64 def write! @config.write! do |file| file.write(@variables.entries.map { |entry| "#{entry.first}=#{entry.last}"}.join("\n")) file.write("\n") end end