class FigNewton::Commands::Init
Public Class Methods
new(stack_name, config_dir)
click to toggle source
# File lib/fig-newton/commands/init.rb, line 6 def initialize(stack_name, config_dir) @stack_name = stack_name @config_dir = config_dir @yaml = nil end
Public Instance Methods
run(forced = false)
click to toggle source
# File lib/fig-newton/commands/init.rb, line 12 def run(forced = false) generate_yaml write_yaml(forced) end
Private Instance Methods
generate_yaml()
click to toggle source
# File lib/fig-newton/commands/init.rb, line 19 def generate_yaml @yaml = unindent(<<-YAML) name: #{@stack_name} apps: tugboat: repo: "behance/tugboat" example-app: repo: "behance/example" dir: "xmp" YAML end
stack_filename()
click to toggle source
# File lib/fig-newton/commands/init.rb, line 40 def stack_filename @filename ||= FigNewton::Config.filepath_from_stack(@config_dir, @stack_name) end
unindent(s)
click to toggle source
# File lib/fig-newton/commands/init.rb, line 44 def unindent(s) s.gsub(/^#{s.scan(/^[ \t]+(?=\S)/).min}/, "") end
write_yaml(forced)
click to toggle source
# File lib/fig-newton/commands/init.rb, line 31 def write_yaml(forced) if File.exist?(stack_filename) && !forced puts "The file \"#{stack_filename}\" already exists. Use --force to overwrite it" return end File.open(stack_filename, "w") { |f| f.write(@yaml) } end