class Victor::CLI::Commands::Init
Public Instance Methods
run()
click to toggle source
# File lib/victor/cli/commands/init.rb, line 20 def run raise "File already exists #{filename}" if File.exist? filename basename = File.basename filename, '.rb' vars = { filename: filename, basename: basename } content = template_content(template) % vars File.write filename, content say "Saved #{filename}" if template == 'cli' say %Q[Run !txtblu!victor render "#{filename}"!txtrst! to render] else say %Q[Run !txtblu!ruby "#{filename}"!txtrst! to render] end end
Private Instance Methods
available_templates()
click to toggle source
# File lib/victor/cli/commands/init.rb, line 65 def available_templates ['cli', 'dsl', 'standalone'] end
filename()
click to toggle source
# File lib/victor/cli/commands/init.rb, line 39 def filename @filename ||= if args["RUBY_FILE"].end_with? '.rb' args["RUBY_FILE"] else args['RUBY_FILE'] + ".rb" end end
template()
click to toggle source
# File lib/victor/cli/commands/init.rb, line 47 def template @template ||= args['--template'] || 'cli' end
template_content(name)
click to toggle source
# File lib/victor/cli/commands/init.rb, line 51 def template_content(name) filename = File.join templates_path, "#{name}.rb" unless available_templates.include? name raise "Invalid template #{name}\nAvailable templates: #{available_templates.join ', '}" end File.read filename end
templates_path()
click to toggle source
# File lib/victor/cli/commands/init.rb, line 61 def templates_path @templates_path ||= File.expand_path "../templates/init", __dir__ end