class RubyLambda::Init
Constants
- TEMPLATE_DIR
Public Class Methods
new(current_directory)
click to toggle source
# File lib/ruby_lambda/init.rb, line 6 def initialize(current_directory) @current_directory = current_directory @shell = Thor::Base.shell.new end
Public Instance Methods
run(mute: false)
click to toggle source
# File lib/ruby_lambda/init.rb, line 11 def run(mute: false) @mute = mute unless File.writable?(@current_directory) @shell.say "Can not create files as the current directory is not writable: #{@current_directory}", :red return end move_template_files rename_env_file update_function_name end
Private Instance Methods
move_template_files()
click to toggle source
# File lib/ruby_lambda/init.rb, line 26 def move_template_files Dir.foreach(TEMPLATE_DIR) do |template_file_name| next if template_file_name == '.' or template_file_name == '..' init_file = File.join(@current_directory, template_file_name) template_file_path = File.join(TEMPLATE_DIR, template_file_name) if File.exist?(init_file) @shell.say_status("Skipped:", "#{template_file_name} file already exists at #{File.expand_path(init_file)}", :yellow) unless @mute else FileUtils.cp(template_file_path, init_file) @shell.say_status("Created:", "#{template_file_name}", :green) unless @mute end end end
rename_env_file()
click to toggle source
# File lib/ruby_lambda/init.rb, line 44 def rename_env_file File.rename("#{@current_directory}/env", "#{@current_directory}/.env") end
update_function_name()
click to toggle source
# File lib/ruby_lambda/init.rb, line 48 def update_function_name config_file = "#{@current_directory}/config.yml" config_data = YAML.load_file config_file config_data['function_name'] = @current_directory.split('/').last File.open(config_file, 'w') { |f| YAML.dump(config_data, f) } end