1hdoc 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -20
- data/bin/1hdoc +2 -3
- data/lib/1hdoc/actions/commit.rb +42 -0
- data/lib/1hdoc/actions/init.rb +28 -0
- data/lib/1hdoc/actions/push.rb +10 -0
- data/lib/1hdoc/actions/version.rb +7 -0
- data/lib/1hdoc/actions.rb +32 -0
- data/lib/1hdoc/cli.rb +50 -0
- data/lib/1hdoc/core/configuration.rb +26 -10
- data/lib/1hdoc/core/log.rb +21 -0
- data/lib/1hdoc/core/progress.rb +42 -0
- data/lib/1hdoc/core/repository.rb +32 -0
- data/lib/1hdoc/version.rb +8 -1
- data/lib/1hdoc.rb +9 -9
- metadata +11 -8
- data/lib/1hdoc/application.rb +0 -94
- data/lib/1hdoc/core/committer.rb +0 -27
- data/lib/1hdoc/core/log_builder.rb +0 -46
- data/lib/1hdoc/core/log_viewer.rb +0 -49
- data/lib/1hdoc/core/utilities.rb +0 -27
- data/lib/1hdoc/integration.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a84109594225740fa2b2a7696c0745d72f68b324
|
4
|
+
data.tar.gz: 546dddc52b368d64b4221c2407c4a0b394b5c3e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ed83b089e997708a403be343b83b0281ec8be37d2e0fc54524688c9459b527bcd09b8295f75e41317cf26490100796861914ed29835652d9b39b48be31cbc78
|
7
|
+
data.tar.gz: 6e739f455a58e9e010fa532e902ced6a435c7bb0a1a536d2e389057721eb2dcba6613c59abdf0f9bd493bdca43dedbbb91b13f59800e2f25bb98f443f3992f39
|
data/README.md
CHANGED
@@ -1,11 +1,6 @@
|
|
1
1
|
# 1hdoc
|
2
|
-
[](https://codeclimate.com/github/domcorvasce/1hdoc)
|
3
|
-
[](https://codeclimate.com/github/domcorvasce/1hdoc/coverage)
|
4
|
-
[](https://travis-ci.org/domcorvasce/1hdoc)
|
5
2
|
|
6
3
|
Keep track of your progress during #100DaysOfCode event.
|
7
|
-
## Warning
|
8
|
-
It's still in development so you could meet some bugs.
|
9
4
|
|
10
5
|
## Installation
|
11
6
|
|
@@ -43,7 +38,7 @@ Here we are! Now you've to initialize all necessary files which are:
|
|
43
38
|
Open your Terminal and type:
|
44
39
|
|
45
40
|
```shell
|
46
|
-
1hdoc
|
41
|
+
1hdoc
|
47
42
|
```
|
48
43
|
|
49
44
|
### Change repo's remote origin
|
@@ -72,15 +67,14 @@ Great! Let's 1hdoc track your progress. Type:
|
|
72
67
|
1hdoc --commit
|
73
68
|
```
|
74
69
|
|
75
|
-
By default, 1hdoc
|
70
|
+
By default, 1hdoc don't push to the repo automatically after you
|
76
71
|
register your progress.
|
77
72
|
|
78
|
-
You can change this behavior by assigning `
|
73
|
+
You can change this behavior by assigning `true` to `auto_push` option in
|
79
74
|
`~/.1hdoc.yml`:
|
80
75
|
|
81
76
|
```yaml
|
82
|
-
|
83
|
-
auto_push: false
|
77
|
+
:auto_push: true
|
84
78
|
```
|
85
79
|
|
86
80
|
### Manually push to the repo
|
@@ -88,16 +82,7 @@ auto_push: false
|
|
88
82
|
If you turn off `auto_push` you can push to the repo typing:
|
89
83
|
|
90
84
|
```shell
|
91
|
-
1hdoc --
|
92
|
-
```
|
93
|
-
|
94
|
-
### See progress
|
95
|
-
|
96
|
-
Obviously you can see your progress:
|
97
|
-
|
98
|
-
```shell
|
99
|
-
1hdoc --log
|
100
|
-
1hdoc --log=2 # only day 2
|
85
|
+
1hdoc --push
|
101
86
|
```
|
102
87
|
|
103
88
|
## Contribute
|
data/bin/1hdoc
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module HDOC
|
2
|
+
module Actions
|
3
|
+
##
|
4
|
+
# Register the daily progress.
|
5
|
+
def commit
|
6
|
+
open_configuration_file
|
7
|
+
return $stderr.puts 'You are done for today :)' if record_already_exist?
|
8
|
+
|
9
|
+
register_daily_progress
|
10
|
+
commit_daily_progress
|
11
|
+
update_last_record_day
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def record_already_exist?
|
17
|
+
@options[:last_commit_on] == Time.now.strftime('%Y-%m-%d')
|
18
|
+
end
|
19
|
+
|
20
|
+
def register_daily_progress
|
21
|
+
open_log
|
22
|
+
progress = Progress.new(@options[:day] + 1)
|
23
|
+
|
24
|
+
progress.register
|
25
|
+
@log.append(progress.format)
|
26
|
+
end
|
27
|
+
|
28
|
+
def commit_daily_progress
|
29
|
+
open_repository
|
30
|
+
@repository.commit("Add Day #{@options[:day] + 1}")
|
31
|
+
|
32
|
+
push if @options[:auto_push]
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_last_record_day
|
36
|
+
@configuration.set :day, @configuration.options[:day] + 1
|
37
|
+
@configuration.set :last_commit_on, Time.now.strftime('%Y-%m-%d')
|
38
|
+
|
39
|
+
@configuration.update
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module HDOC
|
2
|
+
module Actions
|
3
|
+
##
|
4
|
+
# Initialize the necessary files cloning the #100DaysOfCode's repo
|
5
|
+
# and create the configuration file in the user's $HOME path.
|
6
|
+
def init
|
7
|
+
puts 'Where I should locate the #100DaysOfCode repo (ex. ~/my_repo): '
|
8
|
+
@workspace = File.expand_path $stdin.gets.chomp
|
9
|
+
|
10
|
+
initialize_workspace
|
11
|
+
initialize_configuration_file
|
12
|
+
|
13
|
+
$stderr.puts 'Here we are! You are ready to go.'
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def initialize_workspace
|
19
|
+
Repository.clone(ENVIRONMENT[:repository_url], @workspace)
|
20
|
+
Log.reset(File.join(@workspace, ENVIRONMENT[:log_file]))
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize_configuration_file
|
24
|
+
defaults = { auto_push: false, day: 0, workspace: @workspace }
|
25
|
+
Configuration.init(ENVIRONMENT[:configuration_file], defaults)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Implements actions which can be executed by the program.
|
4
|
+
module Actions
|
5
|
+
ENVIRONMENT = {
|
6
|
+
configuration_file: File.expand_path('~/.1hdoc.yml'),
|
7
|
+
repository_url: 'https://github.com/Kallaway/100-days-of-code',
|
8
|
+
log_file: 'log.md'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def open_configuration_file
|
14
|
+
@configuration = Configuration.new(ENVIRONMENT[:configuration_file])
|
15
|
+
@options = @configuration.options
|
16
|
+
end
|
17
|
+
|
18
|
+
def open_repository
|
19
|
+
open_configuration_file unless @configuration
|
20
|
+
@repository = Repository.new(@options[:workspace])
|
21
|
+
end
|
22
|
+
|
23
|
+
def open_log
|
24
|
+
@log = Log.new(File.join(@options[:workspace], ENVIRONMENT[:log_file]))
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
require_relative 'actions/push'
|
30
|
+
require_relative 'actions/commit'
|
31
|
+
require_relative 'actions/init'
|
32
|
+
require_relative 'actions/version'
|
data/lib/1hdoc/cli.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides the CLI interface for interact with the program.
|
4
|
+
class CLI
|
5
|
+
include Actions
|
6
|
+
|
7
|
+
AVAILABLE_COMMANDS = [
|
8
|
+
['-i', '--init', 'Initialize necessary files.'],
|
9
|
+
['-c', '--commit', 'Register your progress and sync it.'],
|
10
|
+
['-p', '--push', 'Manually synchronize your online repository.'],
|
11
|
+
['-v', '--version', 'Show program version.']
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
def initialize(option_parser = OptionParser)
|
15
|
+
@option_parser = option_parser
|
16
|
+
check_for_configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
@option_parser.new do |opts|
|
21
|
+
opts.banner = 'Usage: 1hdoc [options]'
|
22
|
+
|
23
|
+
@options = opts
|
24
|
+
initialize_options
|
25
|
+
end.parse!
|
26
|
+
|
27
|
+
rescue @option_parser::ParseError
|
28
|
+
$stderr.puts @options
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def check_for_configuration
|
34
|
+
unless File.exist? ENVIRONMENT[:configuration_file]
|
35
|
+
$stderr.puts 'Unable to find configuration file..'
|
36
|
+
init
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize_options
|
41
|
+
AVAILABLE_COMMANDS.each do |command|
|
42
|
+
@options.on(*command) { send(remove_dashes(command[1])) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove_dashes(command)
|
47
|
+
command.sub('--', '')
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -1,20 +1,36 @@
|
|
1
1
|
module HDOC
|
2
2
|
##
|
3
|
-
#
|
3
|
+
# Provides methods for read configuration options by a file.
|
4
|
+
# By default, it uses YAML as configuration file's parse
|
4
5
|
class Configuration
|
5
|
-
attr_reader :options
|
6
|
-
include Utilities
|
6
|
+
attr_reader :options, :file_path
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
File.open(
|
12
|
-
configuration_file.puts(options
|
8
|
+
def self.init(file_path, file_parser = YAML, **options)
|
9
|
+
file_path = File.expand_path(file_path)
|
10
|
+
|
11
|
+
File.open(file_path, 'w') do |configuration_file|
|
12
|
+
configuration_file.puts file_parser.dump(options)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(
|
17
|
-
@
|
16
|
+
def initialize(file_path, file_parser = YAML)
|
17
|
+
@file_path = File.expand_path(file_path)
|
18
|
+
@file_parser = file_parser
|
19
|
+
|
20
|
+
raise Errno::ENOENT unless File.exist? @file_path
|
21
|
+
load_options
|
22
|
+
end
|
23
|
+
|
24
|
+
def load_options
|
25
|
+
@options = @file_parser.load(File.read(file_path))
|
26
|
+
end
|
27
|
+
|
28
|
+
def update
|
29
|
+
Configuration.init(@file_path, @file_parser, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def set(option, value)
|
33
|
+
@options[option] = value
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides methods for interact with the log file.
|
4
|
+
class Log
|
5
|
+
attr_reader :log_path
|
6
|
+
|
7
|
+
def self.reset(log_path)
|
8
|
+
log_path = File.expand_path(log_path)
|
9
|
+
File.open(log_path, 'w') { |log| log.print '' }
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(log_path)
|
13
|
+
@log_path = File.expand_path(log_path)
|
14
|
+
raise Errno::ENOENT unless File.exist? log_path
|
15
|
+
end
|
16
|
+
|
17
|
+
def append(content)
|
18
|
+
File.open(log_path, 'a') { |log| log.puts content }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides methods for register and format user's daily progress.
|
4
|
+
class Progress
|
5
|
+
attr_reader :record
|
6
|
+
|
7
|
+
QUESTIONS = {
|
8
|
+
progress: 'Your progress: ',
|
9
|
+
thoughts: 'Your thoughts: ',
|
10
|
+
link: 'Link to work: '
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def initialize(current_day)
|
14
|
+
@current_day = current_day
|
15
|
+
@current_date = Time.now.strftime('%B %d, %Y')
|
16
|
+
|
17
|
+
@record = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def register
|
21
|
+
QUESTIONS.each do |field, question|
|
22
|
+
puts question
|
23
|
+
@record[field] = gets.chomp
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def format
|
28
|
+
result = "### Day #{@current_day}: #{@current_date}\n"
|
29
|
+
record.each { |field, value| result << format_field(field, value) }
|
30
|
+
|
31
|
+
result
|
32
|
+
end
|
33
|
+
|
34
|
+
def format_field(field, value)
|
35
|
+
"**#{field.capitalize}:** #{value}\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
def set_record(record)
|
39
|
+
@record = record
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module HDOC
|
2
|
+
##
|
3
|
+
# Provides an interface for interact with Git repositories.
|
4
|
+
class Repository
|
5
|
+
def self.clone(url, destination, adapter = Git)
|
6
|
+
adapter.clone(url, destination)
|
7
|
+
rescue adapter::GitExecuteError => error
|
8
|
+
$stderr.puts error.message
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(repo_path, adapter = Git)
|
12
|
+
@adapter = adapter
|
13
|
+
@repo = @adapter.open(repo_path)
|
14
|
+
rescue ArgumentError
|
15
|
+
$stderr.puts 'The given repository is not a valid one.'
|
16
|
+
end
|
17
|
+
|
18
|
+
def commit(message)
|
19
|
+
@repo.add(all: true)
|
20
|
+
@repo.commit(message)
|
21
|
+
|
22
|
+
rescue @adapter::GitExecuteError => error
|
23
|
+
$stderr.puts error
|
24
|
+
end
|
25
|
+
|
26
|
+
def push
|
27
|
+
puts @repo.push
|
28
|
+
rescue @adapter::GitExecuteError => error
|
29
|
+
$stderr.puts error
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/1hdoc/version.rb
CHANGED
data/lib/1hdoc.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
# stdlib
|
2
4
|
require 'yaml'
|
3
|
-
require 'optparse'
|
4
5
|
require 'git'
|
6
|
+
require 'optparse'
|
5
7
|
|
6
|
-
# 1hdoc
|
7
|
-
require_relative '1hdoc/core/utilities'
|
8
|
+
# 1hdoc
|
8
9
|
require_relative '1hdoc/core/configuration'
|
9
|
-
require_relative '1hdoc/core/
|
10
|
-
require_relative '1hdoc/core/
|
11
|
-
require_relative '1hdoc/core/
|
10
|
+
require_relative '1hdoc/core/log'
|
11
|
+
require_relative '1hdoc/core/progress'
|
12
|
+
require_relative '1hdoc/core/repository'
|
12
13
|
|
13
|
-
# 1hdoc inteface
|
14
14
|
require_relative '1hdoc/version'
|
15
|
-
require_relative '1hdoc/
|
16
|
-
require_relative '1hdoc/
|
15
|
+
require_relative '1hdoc/actions'
|
16
|
+
require_relative '1hdoc/cli'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 1hdoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dom Corvasce
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -77,13 +77,16 @@ files:
|
|
77
77
|
- README.md
|
78
78
|
- bin/1hdoc
|
79
79
|
- lib/1hdoc.rb
|
80
|
-
- lib/1hdoc/
|
81
|
-
- lib/1hdoc/
|
80
|
+
- lib/1hdoc/actions.rb
|
81
|
+
- lib/1hdoc/actions/commit.rb
|
82
|
+
- lib/1hdoc/actions/init.rb
|
83
|
+
- lib/1hdoc/actions/push.rb
|
84
|
+
- lib/1hdoc/actions/version.rb
|
85
|
+
- lib/1hdoc/cli.rb
|
82
86
|
- lib/1hdoc/core/configuration.rb
|
83
|
-
- lib/1hdoc/core/
|
84
|
-
- lib/1hdoc/core/
|
85
|
-
- lib/1hdoc/core/
|
86
|
-
- lib/1hdoc/integration.rb
|
87
|
+
- lib/1hdoc/core/log.rb
|
88
|
+
- lib/1hdoc/core/progress.rb
|
89
|
+
- lib/1hdoc/core/repository.rb
|
87
90
|
- lib/1hdoc/version.rb
|
88
91
|
homepage: https://github.com/domcorvasce/1hdoc
|
89
92
|
licenses:
|
data/lib/1hdoc/application.rb
DELETED
@@ -1,94 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Provides an interface for interact with the program.
|
4
|
-
class Application
|
5
|
-
include Integration
|
6
|
-
|
7
|
-
AVAILABLE_COMMANDS = [
|
8
|
-
['-i', '--init', 'Initialize necessary files.'],
|
9
|
-
['-c', '--commit', 'Register your progress and sync it.'],
|
10
|
-
['-s', '--sync', 'Manually synchronize your online repository.'],
|
11
|
-
['-v', '--version', 'Show program version.']
|
12
|
-
].freeze
|
13
|
-
|
14
|
-
def initialize(option_parser = OptionParser)
|
15
|
-
@option_parser = option_parser
|
16
|
-
@config_file = File.expand_path('~/.1hdoc.yml')
|
17
|
-
|
18
|
-
return init unless File.exist?(@config_file)
|
19
|
-
|
20
|
-
@config_options = Configuration.new(@config_file).options
|
21
|
-
@log_path = File.join(@config_options['workspace'], 'log.yml')
|
22
|
-
@repo = 'https://github.com/domcorvasce/100-days-of-code'
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Parse defined options.
|
27
|
-
def run
|
28
|
-
options = initialize_options
|
29
|
-
options.parse!
|
30
|
-
rescue @option_parser::InvalidOption
|
31
|
-
puts options
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def initialize_options
|
37
|
-
@option_parser.new do |opts|
|
38
|
-
opts.banner = 'Usage: 1hdoc -h'
|
39
|
-
|
40
|
-
AVAILABLE_COMMANDS.each do |command|
|
41
|
-
opts.on(*command) { send(command[1].sub('--', '')) }
|
42
|
-
end
|
43
|
-
|
44
|
-
opts.on('-l', '--log=[DAY]', 'Show the entire log or per day') do |day|
|
45
|
-
show_log(day)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
##
|
51
|
-
# Initialize necessary files such as the configuration file.
|
52
|
-
def init
|
53
|
-
print 'Type the full path for your new repo (ex. ~/works/my_repo): '
|
54
|
-
workspace = $stdin.gets.chomp
|
55
|
-
|
56
|
-
Configuration.init(@config_file, 'workspace' => File.expand_path(workspace),
|
57
|
-
'auto_push' => true)
|
58
|
-
Committer.init(@repo, workspace)
|
59
|
-
|
60
|
-
puts 'Here we are! You are ready to start.'
|
61
|
-
end
|
62
|
-
|
63
|
-
##
|
64
|
-
# Track user's progress for the current day.
|
65
|
-
def commit
|
66
|
-
log_handler = LogBuilder.new(@log_path)
|
67
|
-
committer = Committer.new(@config_options['workspace'])
|
68
|
-
|
69
|
-
return puts 'You are done for today :)' unless log_handler.record_not_exist?
|
70
|
-
|
71
|
-
latest_day = log_handler.add(register_daily_commit)
|
72
|
-
committer.commit("Add Day #{latest_day}")
|
73
|
-
|
74
|
-
sync if @config_options['auto_push']
|
75
|
-
end
|
76
|
-
|
77
|
-
##
|
78
|
-
# Show the entire log or per day.
|
79
|
-
def show_log(target_day)
|
80
|
-
log_viewer = LogViewer.new(@log_path)
|
81
|
-
puts log_viewer.show(target_day.to_i)
|
82
|
-
end
|
83
|
-
|
84
|
-
##
|
85
|
-
# Manually push the daily commit to user's repository.
|
86
|
-
def sync
|
87
|
-
push_commit(@config_options['workspace'])
|
88
|
-
end
|
89
|
-
|
90
|
-
def version
|
91
|
-
puts '1hdoc ver' + VERSION
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
data/lib/1hdoc/core/committer.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Provides an interface for Git in order to manage user's repo.
|
4
|
-
class Committer
|
5
|
-
##
|
6
|
-
# Initialize the workspace.
|
7
|
-
def self.init(repository, path, git = Git)
|
8
|
-
path = File.expand_path(path)
|
9
|
-
|
10
|
-
$stderr.puts 'Cloning #100DaysOfCode repository..'
|
11
|
-
git.clone(repository, path)
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(path, git = Git)
|
15
|
-
@repo = git.open(path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def commit(message)
|
19
|
-
@repo.add(all: true)
|
20
|
-
@repo.commit(message)
|
21
|
-
end
|
22
|
-
|
23
|
-
def push
|
24
|
-
@repo.push
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Provides methods for manage user's log such as adding records.
|
4
|
-
class LogBuilder
|
5
|
-
attr_reader :log
|
6
|
-
include Utilities
|
7
|
-
|
8
|
-
def initialize(path, file_parser = YAML)
|
9
|
-
@path = expand_path(path)
|
10
|
-
@log = parse_file(@path, file_parser)
|
11
|
-
|
12
|
-
@today_date = Time.now.strftime('%Y-%m-%d')
|
13
|
-
@record = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
##
|
17
|
-
# Check if there is no record for the current day.
|
18
|
-
def record_not_exist?
|
19
|
-
last_day = @log.keys.last
|
20
|
-
last_day.nil? || @log[last_day]['published_on'] != @today_date
|
21
|
-
end
|
22
|
-
|
23
|
-
def add(data)
|
24
|
-
day = fetch_current_day
|
25
|
-
|
26
|
-
@record[day] = stringify_symbols(data)
|
27
|
-
@record[day]['published_on'] = @today_date
|
28
|
-
|
29
|
-
append_to_log
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def append_to_log
|
35
|
-
File.open(@path, 'a') do |log|
|
36
|
-
log.puts @record.to_yaml.sub('---', '')
|
37
|
-
end
|
38
|
-
|
39
|
-
fetch_current_day
|
40
|
-
end
|
41
|
-
|
42
|
-
def fetch_current_day
|
43
|
-
(@log.keys.last || 0) + 1
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Show the user's log in a human-readable way.
|
4
|
-
class LogViewer
|
5
|
-
include Utilities
|
6
|
-
|
7
|
-
def initialize(path, file_parser = YAML)
|
8
|
-
@path = expand_path(path)
|
9
|
-
@log = parse_file(@path, file_parser)
|
10
|
-
end
|
11
|
-
|
12
|
-
def show(target_day = 0)
|
13
|
-
result = ''
|
14
|
-
|
15
|
-
@log.each do |past_day, information|
|
16
|
-
next if target_day != 0 && target_day != past_day
|
17
|
-
result << format_log(past_day, information)
|
18
|
-
end
|
19
|
-
|
20
|
-
result
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
##
|
26
|
-
# Format log's data in order to get something like:
|
27
|
-
# ```
|
28
|
-
# - Day 1 -
|
29
|
-
# ** Progress **
|
30
|
-
# Fixed CSS, worked on canvas functionality for the app.
|
31
|
-
#
|
32
|
-
# ** Thoughts **
|
33
|
-
# I really struggled with CSS.
|
34
|
-
#
|
35
|
-
# -- Link to work: http://www.example.com/
|
36
|
-
# ```
|
37
|
-
def format_log(day, data)
|
38
|
-
%(
|
39
|
-
|- Day #{day} -
|
40
|
-
|
|
41
|
-
| ** Progress ** \n #{data['progress']}
|
42
|
-
|
|
43
|
-
| ** Thoughts ** \n #{data['thoughts']}
|
44
|
-
|
|
45
|
-
| -- Link to work: #{data['link']}
|
46
|
-
).gsub(/ +\|/, '')
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
data/lib/1hdoc/core/utilities.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Implements methods and constants used by many independents classes.
|
4
|
-
module Utilities
|
5
|
-
##
|
6
|
-
# Load log from a YAML file.
|
7
|
-
def parse_file(path, file_parser)
|
8
|
-
raise Errno::ENOENT, "Unable to find #{path}" unless File.exist?(path)
|
9
|
-
file_parser.load_file(path) || {}
|
10
|
-
end
|
11
|
-
|
12
|
-
##
|
13
|
-
# Transform symbol's keys in string ones.
|
14
|
-
def stringify_symbols(hash_object)
|
15
|
-
hash_object.keys.each do |key|
|
16
|
-
next unless key.is_a?(Symbol)
|
17
|
-
hash_object[key.to_s] = hash_object.delete(key)
|
18
|
-
end
|
19
|
-
|
20
|
-
hash_object
|
21
|
-
end
|
22
|
-
|
23
|
-
def expand_path(path)
|
24
|
-
File.expand_path(path, File.dirname($PROGRAM_NAME))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/1hdoc/integration.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module HDOC
|
2
|
-
##
|
3
|
-
# Provides methods used across various commands.
|
4
|
-
module Integration
|
5
|
-
QUESTIONS = {
|
6
|
-
progress: 'Your progress:',
|
7
|
-
thoughts: 'Your thoughts:',
|
8
|
-
link: 'Link to work:'
|
9
|
-
}.freeze
|
10
|
-
|
11
|
-
def push_commit(workspace)
|
12
|
-
committer = Committer.new(workspace)
|
13
|
-
committer.push
|
14
|
-
$stderr.puts 'Daily commit pushed with success!'
|
15
|
-
rescue Exception => exception
|
16
|
-
$stderr.puts exception.message
|
17
|
-
end
|
18
|
-
|
19
|
-
def register_daily_commit
|
20
|
-
record = {}
|
21
|
-
|
22
|
-
QUESTIONS.each do |key, question|
|
23
|
-
record[key] = ask(question)
|
24
|
-
end
|
25
|
-
|
26
|
-
record
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
|
31
|
-
def ask(message)
|
32
|
-
puts message
|
33
|
-
gets.chomp
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|