Module: HDOC::Actions

Included in:
CLI
Defined in:
lib/1hdoc/actions.rb,
lib/1hdoc/actions/init.rb,
lib/1hdoc/actions/push.rb,
lib/1hdoc/actions/commit.rb,
lib/1hdoc/actions/version.rb

Overview

Implements actions which can be executed by the program.

Constant Summary collapse

ENVIRONMENT =
{
  configuration_file: File.expand_path('~/.1hdoc.yml'),
  repository_url: 'https://github.com/Kallaway/100-days-of-code',
  log_file: 'log.md'
}.freeze
QUESTIONS =
{
  day: 'Great! On what day you are: ',
  workspace: 'Ok! Where I could find your workspace (ex. ~/work/100doc): '
}.freeze

Instance Method Summary collapse

Instance Method Details

#commitObject

Register the daily progress.



5
6
7
8
9
10
11
12
# File 'lib/1hdoc/actions/commit.rb', line 5

def commit
  open_configuration_file
  return $stderr.puts 'You are done for today :)' if record_already_exist?

  register_daily_progress
  commit_daily_progress
  update_last_record_day
end

#initObject

Initialize the necessary files cloning the #100DaysOfCode’s repo and create the configuration file in the user’s $HOME path.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/1hdoc/actions/init.rb', line 11

def init
  print 'Do you already maintain a log on your PC? [yn] '
  already_active = $stdin.gets.chomp.downcase

  return customize_configuration_file if already_active == 'y'

  puts 'Where I should locate the #100DaysOfCode repo (ex. ~/my_repo): '
  @workspace = File.expand_path $stdin.gets.chomp

  initialize_workspace
  initialize_configuration_file

  $stderr.puts 'Here we are! You are ready to go.'
end

#pushObject

Push the progress to the repository.



5
6
7
8
9
10
11
12
13
# File 'lib/1hdoc/actions/push.rb', line 5

def push
  if user_already_pushed?
    $stderr.puts 'You already pushed for today'
    return
  end

  open_repository
  @repository.push
end

#versionObject



3
4
5
# File 'lib/1hdoc/actions/version.rb', line 3

def version
  $stderr.puts HDOC.version
end