lib/vedeu/cli/generator/helpers.rb in vedeu-0.5.8 vs lib/vedeu/cli/generator/helpers.rb in vedeu-0.5.9

- old
+ new

@@ -13,10 +13,45 @@ # @return [String] def app_name @app_name ||= File.read('./config/app_name') end + # @return [String] + def app_bin_path + name + '/bin/' + end + + # @return [String] + def app_config_path + name + '/config/' + end + + # @return [String] + def app_controllers_path + name + '/app/controllers/' + end + + # @return [String] + def app_helpers_path + name + '/app/helpers/' + end + + # @return [String] + def app_models_path + name + '/app/models/' + end + + # @return [String] + def app_keymaps_path + name + '/app/models/keymaps/' + end + + # @return [String] + def app_views_path + name + '/app/views/' + end + # @param destination [String] # @return [void] def make_directory(destination) Vedeu.log_stdout(type: :create, message: "#{destination}") @@ -25,35 +60,54 @@ # @param source [String] # @param destination [String] # @return [void] def copy_file(source, destination) - Vedeu.log_stdout(type: :create, message: "#{destination}") + if File.exist?(destination) + skipped_file(destination) - FileUtils.cp(source, destination) + else + Vedeu.log_stdout(type: :create, message: "#{destination}") + + FileUtils.cp(source, destination) + end end # @param source [String] # @param destination [String] # @return [void] def make_file(source, destination) - Vedeu.log_stdout(type: :create, message: "#{destination}") + if File.exist?(destination) + skipped_file(destination) - File.write(destination, parse(source)) + else + Vedeu.log_stdout(type: :create, message: "#{destination}") + + File.write(destination, parse(source)) + end end # @param destination [String] # @return [void] + def skipped_file(destination) + Vedeu.log_stdout(type: :create, + message: "#{destination} " + + Esc.red { 'already exists, skipped.' }) + end + + # @param destination [String] + # @return [void] def touch_file(destination) Vedeu.log_stdout(type: :create, message: "#{destination}") FileUtils.touch(destination) end # @return [String] def name @_name ||= @name.downcase end + alias_method :app_root_path, :name # @return [String] def name_as_class name.downcase.split(/_|-/).map(&:capitalize).join end