Class: Arb::Cli::WorkingDirectory

Inherits:
Object
  • Object
show all
Defined in:
lib/arb/cli/shared/working_directory.rb

Constant Summary collapse

FILES =
{
  ".gitignore" => "    input/**/*\n    instructions/**/*\n    others/**/*\n    .env\n  END\n  \".ruby-version\" => \"3.3.0\\n\",\n  \"Gemfile\" => <<~END,\n    source \"https://rubygems.org\"\n    ruby file: \".ruby-version\"\n  END\n  File.join(\"spec\", \"spec_helper.rb\") => <<~END\n    require \"debug\"\n\n    Dir[File.join(__dir__, \"..\", \"src\", \"**\", \"*.rb\")].each do |file|\n      require file\n    end\n\n\n  END\n}\n",
ENV_KEYS =
["EDITOR_COMMAND", "AOC_COOKIE"]
DEFAULT_EDITOR_COMMAND =
"code"

Class Method Summary collapse

Class Method Details

.prepare!Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/arb/cli/shared/working_directory.rb', line 30

def self.prepare!
  files_created = []

  existing_dotenv = Dotenv.parse(".env")
  unless ENV_KEYS.all? { existing_dotenv.has_key?(it) }
    create_dotenv!(existing_dotenv)
    files_created << :dotenv
  end
  Dotenv.load
  Dotenv.require_keys(*ENV_KEYS)

  files_created += create_other_files!

  if files_created.any?
    puts "✅ Initial files created and committed to a new Git repository."
    puts
  end
end

.refresh_aoc_cookie!Object



49
50
51
52
53
54
55
56
# File 'lib/arb/cli/shared/working_directory.rb', line 49

def self.refresh_aoc_cookie!
  print "Uh oh, your Advent of Code session cookie has expired or was " \
    "incorrectly entered. "
  ENV["AOC_COOKIE"] = input_aoc_cookie
  new_dotenv = Dotenv.parse(".env").dup
  new_dotenv["AOC_COOKIE"] = ENV["AOC_COOKIE"]
  File.write(".env", generate_dotenv(new_dotenv))
end