class Ufo::Current
Public Class Methods
env_extra()
click to toggle source
# File lib/ufo/current.rb, line 62 def self.env_extra Current.new.env_extra end
new(options={})
click to toggle source
# File lib/ufo/current.rb, line 6 def initialize(options={}) Ufo.check_ufo_project! @options = options @file = ".ufo/current" @path = "#{Ufo.root}/#{@file}" end
service()
click to toggle source
reads service, returns nil if not set
# File lib/ufo/current.rb, line 81 def self.service Current.new.service end
service!(service=:current)
click to toggle source
reads service, will exit if current service not set
# File lib/ufo/current.rb, line 86 def self.service!(service=:current) return service if service != :current service = Current.service return service if service puts "ERROR: service must be specified.".color(:red) puts <<-EOL Example: ufo #{ARGV.first} SERVICE You can also set a current service to be remembered with: ufo current --service SERVICE EOL exit 1 # if want to display full help menu: # Ufo::CLI.start(ARGV + ["-h"]) end
services()
click to toggle source
reads services, returns [] if not set
# File lib/ufo/current.rb, line 71 def self.services Current.new.services end
Public Instance Methods
data()
click to toggle source
# File lib/ufo/current.rb, line 53 def data YAML.load(IO.read(@path)) rescue {} end
env_extra()
click to toggle source
# File lib/ufo/current.rb, line 57 def env_extra current = data["env_extra"] return current unless current&.empty? end
rm()
click to toggle source
# File lib/ufo/current.rb, line 17 def rm FileUtils.rm_f(@path) puts "Current settings have been removed. Removed #{@file}" end
run()
click to toggle source
# File lib/ufo/current.rb, line 13 def run @options[:rm] ? rm : set end
service()
click to toggle source
# File lib/ufo/current.rb, line 75 def service current = data["service"] return current unless current&.empty? end
services()
click to toggle source
# File lib/ufo/current.rb, line 66 def services return data["services"] || [] end
set()
click to toggle source
# File lib/ufo/current.rb, line 22 def set if @options.empty? show else d = data # assign data to d to create local variable for merge to work d = d.merge(@options).delete_if do |_,v| v&.empty? || v == [''] end text = YAML.dump(d) IO.write(@path, text) puts "Current settings saved in .ufo/current" show end end
show()
click to toggle source
# File lib/ufo/current.rb, line 37 def show if data.empty? puts <<-EOL There are no current settings. To set a current service run: ufo current --service my-service ufo current -h # for more examples EOL return end data.each do |key, value| puts "Current #{key}: #{value}" end end