Class: Lono::Cfn::Current
- Inherits:
-
Object
- Object
- Lono::Cfn::Current
- Defined in:
- lib/lono/cfn/current.rb
Class Method Summary collapse
-
.name ⇒ Object
reads name, returns nil if not set.
-
.name!(name = :current) ⇒ Object
reads name, will exit if current name not set.
-
.suffix ⇒ Object
reads suffix, returns nil if not set.
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(options = {}) ⇒ Current
constructor
A new instance of Current.
- #name ⇒ Object
- #rm ⇒ Object
- #run ⇒ Object
- #set ⇒ Object
- #show ⇒ Object
- #suffix ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Current
Returns a new instance of Current.
5 6 7 8 9 10 |
# File 'lib/lono/cfn/current.rb', line 5 def initialize(={}) Lono::ProjectChecker.check_lono_project @options = @file = ".lono/current" @path = "#{Lono.root}/#{@file}" end |
Class Method Details
.name ⇒ Object
reads name, returns nil if not set
73 74 75 |
# File 'lib/lono/cfn/current.rb', line 73 def self.name Current.new.name end |
.name!(name = :current) ⇒ Object
reads name, will exit if current name not set
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/lono/cfn/current.rb', line 78 def self.name!(name=:current) return name if name != :current name = Current.name return name if name # TODO: don't think it is possible to get here... puts "ERROR: stack name must be specified.".colorize(:red) puts <<-EOL Example: lono cfn #{ARGV[1]} STACK You can also set a current stack name to be remembered with: lono cfn current --name STACK EOL exit 1 end |
Instance Method Details
#data ⇒ Object
53 54 55 |
# File 'lib/lono/cfn/current.rb', line 53 def data YAML.load(IO.read(@path)) rescue {} end |
#name ⇒ Object
67 68 69 70 |
# File 'lib/lono/cfn/current.rb', line 67 def name current = data["name"] return current unless current&.empty? end |
#rm ⇒ Object
16 17 18 19 |
# File 'lib/lono/cfn/current.rb', line 16 def rm FileUtils.rm_f(@path) puts "Current settings have been removed. Removed #{@file}" end |
#run ⇒ Object
12 13 14 |
# File 'lib/lono/cfn/current.rb', line 12 def run @options[:rm] ? rm : set end |
#set ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lono/cfn/current.rb', line 21 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 |k,v| v&.empty? || v == [''] end text = YAML.dump(d) FileUtils.mkdir_p(File.dirname(@path)) IO.write(@path, text) puts "Current settings saved in .lono/current" show end end |
#show ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lono/cfn/current.rb', line 37 def show if data.empty? puts <<-EOL There are no current settings. To set a current stack run: lono cfn current --name mystack lono cfn current -h # for more examples EOL return end data.each do |key, value| puts "Current #{key}: #{value}" end end |
#suffix ⇒ Object
57 58 59 60 |
# File 'lib/lono/cfn/current.rb', line 57 def suffix current = data["suffix"] return current unless current&.empty? end |