Module: Alfred::Actions
- Defined in:
- lib/alfred/main.rb
Overview
Constant Summary collapse
- CYAN =
Definição das cores para o visual "hacker"
"\e[36m"- RESET =
"\e[0m"
Class Method Summary collapse
-
.criar_arquivo ⇒ void
Verifica a existência ou cria o arquivo Gemfile na pasta de execução atual.
-
.criar_gem ⇒ void
Gerencia a adição interativa de novas gems ao Gemfile e executa o bundle install.
-
.menu ⇒ void
Exibe o menu principal de interação no terminal e gerencia o fluxo de navegação.
Class Method Details
.criar_arquivo ⇒ void
This method returns an undefined value.
Verifica a existência ou cria o arquivo Gemfile na pasta de execução atual.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/alfred/main.rb', line 77 def self.criar_arquivo path = File.join(Dir.pwd, 'Gemfile') puts "Você está na: #{Dir.pwd}" print "Digite 1 para criar o Gemfile aqui: " opcao = STDIN.gets.chomp if opcao == "1" if File.exist?(path) puts "⚠️ Arquivo Gemfile já existe." else File.open(path, 'a') do |file| file.puts "source \"https://rubygems.org\"" end puts "✅ Gemfile criado com sucesso!" end self.criar_gem else self. end end |
.criar_gem ⇒ void
This method returns an undefined value.
Gerencia a adição interativa de novas gems ao Gemfile e executa o bundle install.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/alfred/main.rb', line 46 def self.criar_gem path = File.join(Dir.pwd, 'Gemfile') gems_adicionadas = 0 File.open(path, 'a') do |file| loop do print "Digite o nome da gem (ou '0' para sair): " gem_name = opcao = STDIN.gets.chomp break if gem_name == "0" next if gem_name.empty? file.puts "gem \"#{gem_name}\"" gems_adicionadas += 1 puts "✅ Gem \"#{gem_name}\" adicionada!" end end if gems_adicionadas > 0 puts "Instalando dependências..." if system("bundle install") puts "🎉 Dependências instaladas com sucesso!" else puts "❌ Ocorreu um erro ao rodar o bundle install." end end puts "Processo encerrado. Seu Gemfile foi atualizado!" end |
.menu ⇒ void
This method returns an undefined value.
Exibe o menu principal de interação no terminal e gerencia o fluxo de navegação.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/alfred/main.rb', line 17 def self. puts "\n#{CYAN}==============================" puts " BEM-VINDO AO ALFRED " puts "==============================#{RESET}" puts "Escolha uma opção:" puts "1. Criar arquivo" puts "2. Sair" print "Opção: " opcao = STDIN.gets.chomp case opcao when "1" self.criar_arquivo when "2" puts "Saindo..." exit else puts "Opção inválida!" self. end end |