module HDOC::Actions
Implements actions which can be executed by the program.
Constants
- ENVIRONMENT
- QUESTIONS
Public Instance Methods
commit()
click to toggle source
Register the daily progress.
# 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
init()
click to toggle source
Initialize the necessary files cloning the #100DaysOfCode’s repo and create the configuration file in the user’s $HOME path.
# 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
push()
click to toggle source
Push the progress to the repository.
# 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
version()
click to toggle source
# File lib/1hdoc/actions/version.rb, line 3 def version $stderr.puts HDOC.version end
Private Instance Methods
commit_daily_progress()
click to toggle source
# File lib/1hdoc/actions/commit.rb, line 28 def commit_daily_progress open_repository @repository.commit("Add Day #{@options[:day].to_i + 1}") push if @options[:auto_push] end
customize_configuration_file()
click to toggle source
# File lib/1hdoc/actions/init.rb, line 28 def customize_configuration_file configuration_options = {} QUESTIONS.each do |option, question| configuration_options[option] = Readline.readline(question, false) end initialize_configuration_file(configuration_options) $stderr.puts 'Here we are! You are ready to go.' end
initialize_configuration_file(options = {})
click to toggle source
# File lib/1hdoc/actions/init.rb, line 44 def initialize_configuration_file(options = {}) defaults = { auto_push: false, day: 0, workspace: @workspace }.merge(options) defaults[:workspace] = File.expand_path defaults[:workspace] Configuration.init(ENVIRONMENT[:configuration_file], defaults) end
initialize_workspace()
click to toggle source
# File lib/1hdoc/actions/init.rb, line 39 def initialize_workspace Repository.clone(ENVIRONMENT[:repository_url], @workspace) Log.reset(File.join(@workspace, ENVIRONMENT[:log_file])) end
open_configuration_file()
click to toggle source
# File lib/1hdoc/actions.rb, line 13 def open_configuration_file @configuration = Configuration.new(ENVIRONMENT[:configuration_file]) @options = @configuration.options end
open_log()
click to toggle source
# File lib/1hdoc/actions.rb, line 23 def open_log @log = Log.new(File.join(@options[:workspace], ENVIRONMENT[:log_file])) end
open_repository()
click to toggle source
# File lib/1hdoc/actions.rb, line 18 def open_repository open_configuration_file unless @configuration @repository = Repository.new(@options[:workspace]) end
record_already_exist?()
click to toggle source
# File lib/1hdoc/actions/commit.rb, line 16 def record_already_exist? @options[:last_commit_on] == Time.now.strftime('%Y-%m-%d') end
register_daily_progress()
click to toggle source
# File lib/1hdoc/actions/commit.rb, line 20 def register_daily_progress open_log progress = Progress.new(@options[:day].to_i + 1) progress.register @log.append(progress.format) end
update_last_record_day()
click to toggle source
# File lib/1hdoc/actions/commit.rb, line 35 def update_last_record_day @configuration.set :day, @configuration.options[:day].to_i + 1 @configuration.set :last_commit_on, Time.now.strftime('%Y-%m-%d') @configuration.update end
user_already_pushed?()
click to toggle source
# File lib/1hdoc/actions/push.rb, line 17 def user_already_pushed? config = Configuration.new(ENVIRONMENT[:configuration_file]) config.options[:last_commit_on] == Time.now.strftime('%Y-%m-%d') end