crusoe 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +33 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +90 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/exe/crusoe +4 -0
- data/lib/crusoe/cli.rb +93 -0
- data/lib/crusoe/commands/git/add.rb +12 -0
- data/lib/crusoe/commands/git/checkout.rb +17 -0
- data/lib/crusoe/commands/git/commit.rb +22 -0
- data/lib/crusoe/commands/git/git_command.rb +28 -0
- data/lib/crusoe/commands/git/pull.rb +14 -0
- data/lib/crusoe/commands/git/push.rb +12 -0
- data/lib/crusoe/commands/git/remote_git_command.rb +16 -0
- data/lib/crusoe/commands/git.rb +11 -0
- data/lib/crusoe/commands/journal.rb +22 -0
- data/lib/crusoe/commands/read.rb +35 -0
- data/lib/crusoe/commands.rb +4 -0
- data/lib/crusoe/configuration.rb +20 -0
- data/lib/crusoe/entry.rb +13 -0
- data/lib/crusoe/entry_file.rb +29 -0
- data/lib/crusoe/entry_file_name.rb +38 -0
- data/lib/crusoe/entry_template.rb +33 -0
- data/lib/crusoe/interface.rb +21 -0
- data/lib/crusoe/templates/entry_template.md.erb +5 -0
- data/lib/crusoe/version.rb +5 -0
- data/lib/crusoe.rb +4 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b4a32192daf5b633da6ab3d4b914f79c1a76c08e48f22651656c65b4c63321ce
|
4
|
+
data.tar.gz: 83af5b4c5f515d1ca57fb24bddf6d0e49b01c90d68e62cd09a12b2d19344eed7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f721eb5652b8232650348c78a5a1e0285da99c6584bb48b8ff850c72c135b53041fbdf58790bfa4539583410a20f4b6e543dd505629035cf7788b5dfba6463c8
|
7
|
+
data.tar.gz: 43afa28420513bba378085b33313ad997d9203430baaca25c025fd5499861d981447bc7e80a0447f48662aa46b41451ebae62573d011324d8bc80dc92a952f4b
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
inherit_from:
|
2
|
+
- https://raw.githubusercontent.com/Bodacious/style-guides/main/.rubocop.yml
|
3
|
+
|
4
|
+
require:
|
5
|
+
- rubocop-rspec
|
6
|
+
- rubocop-rake
|
7
|
+
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 3.0
|
10
|
+
NewCops: enable
|
11
|
+
|
12
|
+
Style/StringLiterals:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Style/StringLiteralsInInterpolation:
|
17
|
+
Enabled: true
|
18
|
+
EnforcedStyle: double_quotes
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 120
|
22
|
+
|
23
|
+
RSpec/AnyInstance:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
RSpec/ExampleLength:
|
27
|
+
Max: 50
|
28
|
+
|
29
|
+
RSpec/MessageSpies:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
RSpec/VerifiedDoubleReference:
|
33
|
+
EnforcedStyle: string
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.1
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in crusoe.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "bundler"
|
9
|
+
gem "rake", "~> 13.0"
|
10
|
+
gem "rspec", "~> 3.0"
|
11
|
+
gem "rspec-mocks"
|
12
|
+
gem "rubocop", "~> 1.21"
|
13
|
+
gem "rubocop-rake"
|
14
|
+
gem "rubocop-rspec"
|
15
|
+
gem "timecop"
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
crusoe (0.1.0)
|
5
|
+
git
|
6
|
+
thor
|
7
|
+
yaml
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.8.5)
|
13
|
+
public_suffix (>= 2.0.2, < 6.0)
|
14
|
+
ast (2.4.2)
|
15
|
+
diff-lcs (1.5.0)
|
16
|
+
git (1.18.0)
|
17
|
+
addressable (~> 2.8)
|
18
|
+
rchardet (~> 1.8)
|
19
|
+
json (2.6.3)
|
20
|
+
language_server-protocol (3.17.0.3)
|
21
|
+
parallel (1.23.0)
|
22
|
+
parser (3.2.2.3)
|
23
|
+
ast (~> 2.4.1)
|
24
|
+
racc
|
25
|
+
public_suffix (5.0.3)
|
26
|
+
racc (1.7.1)
|
27
|
+
rainbow (3.1.1)
|
28
|
+
rake (13.0.6)
|
29
|
+
rchardet (1.8.0)
|
30
|
+
regexp_parser (2.8.1)
|
31
|
+
rexml (3.2.5)
|
32
|
+
rspec (3.12.0)
|
33
|
+
rspec-core (~> 3.12.0)
|
34
|
+
rspec-expectations (~> 3.12.0)
|
35
|
+
rspec-mocks (~> 3.12.0)
|
36
|
+
rspec-core (3.12.2)
|
37
|
+
rspec-support (~> 3.12.0)
|
38
|
+
rspec-expectations (3.12.3)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.12.0)
|
41
|
+
rspec-mocks (3.12.6)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.12.0)
|
44
|
+
rspec-support (3.12.1)
|
45
|
+
rubocop (1.54.0)
|
46
|
+
json (~> 2.3)
|
47
|
+
language_server-protocol (>= 3.17.0)
|
48
|
+
parallel (~> 1.10)
|
49
|
+
parser (>= 3.2.2.3)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
regexp_parser (>= 1.8, < 3.0)
|
52
|
+
rexml (>= 3.2.5, < 4.0)
|
53
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
54
|
+
ruby-progressbar (~> 1.7)
|
55
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
56
|
+
rubocop-ast (1.29.0)
|
57
|
+
parser (>= 3.2.1.0)
|
58
|
+
rubocop-capybara (2.18.0)
|
59
|
+
rubocop (~> 1.41)
|
60
|
+
rubocop-factory_bot (2.23.1)
|
61
|
+
rubocop (~> 1.33)
|
62
|
+
rubocop-rake (0.6.0)
|
63
|
+
rubocop (~> 1.0)
|
64
|
+
rubocop-rspec (2.24.0)
|
65
|
+
rubocop (~> 1.33)
|
66
|
+
rubocop-capybara (~> 2.17)
|
67
|
+
rubocop-factory_bot (~> 2.22)
|
68
|
+
ruby-progressbar (1.13.0)
|
69
|
+
thor (1.2.2)
|
70
|
+
timecop (0.9.8)
|
71
|
+
unicode-display_width (2.4.2)
|
72
|
+
yaml (0.2.1)
|
73
|
+
|
74
|
+
PLATFORMS
|
75
|
+
arm64-darwin-22
|
76
|
+
x86_64-darwin-22
|
77
|
+
|
78
|
+
DEPENDENCIES
|
79
|
+
bundler
|
80
|
+
crusoe!
|
81
|
+
rake (~> 13.0)
|
82
|
+
rspec (~> 3.0)
|
83
|
+
rspec-mocks
|
84
|
+
rubocop (~> 1.21)
|
85
|
+
rubocop-rake
|
86
|
+
rubocop-rspec
|
87
|
+
timecop
|
88
|
+
|
89
|
+
BUNDLED WITH
|
90
|
+
2.4.12
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Bodacious
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Crusoe
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/crusoe`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/crusoe.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/exe/crusoe
ADDED
data/lib/crusoe/cli.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
require "thor"
|
2
|
+
require_relative "commands/git"
|
3
|
+
require_relative "commands/journal"
|
4
|
+
require_relative "commands/read"
|
5
|
+
require_relative "configuration"
|
6
|
+
require_relative "interface"
|
7
|
+
|
8
|
+
module Crusoe
|
9
|
+
class CLI < Thor
|
10
|
+
attr_reader :configuration
|
11
|
+
attr_reader :interface
|
12
|
+
private :configuration, :interface
|
13
|
+
|
14
|
+
def initialize(...)
|
15
|
+
@configuration = Configuration.new
|
16
|
+
@interface = Interface.new
|
17
|
+
super(...)
|
18
|
+
end
|
19
|
+
|
20
|
+
default_task :journal
|
21
|
+
|
22
|
+
desc "journal", "This is the default task."
|
23
|
+
option :date, type: "string", default: "today"
|
24
|
+
def journal
|
25
|
+
fetch_remote_repo
|
26
|
+
date = parse_date_option(options[:date])
|
27
|
+
write(date)
|
28
|
+
update_remote_repo
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "read", "Read an entry"
|
32
|
+
option :date, type: "string", default: "today"
|
33
|
+
def read
|
34
|
+
update_remote_repo
|
35
|
+
date = parse_date_option(options[:date])
|
36
|
+
read_dates(date)
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "report", "Generate a report for the last week"
|
40
|
+
def report
|
41
|
+
update_remote_repo
|
42
|
+
today = Date.today
|
43
|
+
days_to_last_monday = (today.wday - 1) % 7
|
44
|
+
last_monday = today - days_to_last_monday
|
45
|
+
read_dates(last_monday..today)
|
46
|
+
end
|
47
|
+
|
48
|
+
# TODO: Add command for updating the TOC file on each commit
|
49
|
+
desc "toc", "Update the ToC on the README.md"
|
50
|
+
def update_toc
|
51
|
+
puts "TODO: Add GitCommit"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def parse_date_option(date_option_string)
|
57
|
+
case date_option_string
|
58
|
+
when "today" then Date.today
|
59
|
+
when "yesterday" then Date.today - 1
|
60
|
+
else
|
61
|
+
Date.parse(date_option_string)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def read_dates(date_range)
|
66
|
+
content = Commands::Read.new(
|
67
|
+
directory: configuration.entries_directory_path,
|
68
|
+
date_range: date_range
|
69
|
+
).to_s
|
70
|
+
interface.display(content)
|
71
|
+
end
|
72
|
+
|
73
|
+
def write(date)
|
74
|
+
journal = Commands::Journal.new(
|
75
|
+
directory: configuration.entries_directory_path,
|
76
|
+
date: date
|
77
|
+
)
|
78
|
+
journal.prepare_entry_file!
|
79
|
+
interface.write(journal.entry_file_name)
|
80
|
+
end
|
81
|
+
|
82
|
+
def fetch_remote_repo
|
83
|
+
Commands::Git::Checkout.new(directory: configuration.entries_directory_path).main
|
84
|
+
Commands::Git::Pull.new(directory: configuration.entries_directory_path).main
|
85
|
+
end
|
86
|
+
|
87
|
+
def update_remote_repo
|
88
|
+
Commands::Git::Add.new(directory: configuration.entries_directory_path).all
|
89
|
+
Commands::Git::Commit.new(directory: configuration.entries_directory_path).commit!
|
90
|
+
Commands::Git::Push.new(directory: configuration.entries_directory_path).main
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative "git_command"
|
2
|
+
module Crusoe
|
3
|
+
module Commands
|
4
|
+
module Git
|
5
|
+
##
|
6
|
+
# Stages the current changes in git, commits, and pushes
|
7
|
+
require_relative "git_command"
|
8
|
+
class Checkout < GitCommand
|
9
|
+
MAIN_GIT_BRANCH = "main".freeze
|
10
|
+
|
11
|
+
def main
|
12
|
+
git_client.checkout(MAIN_GIT_BRANCH)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Crusoe
|
2
|
+
module Commands
|
3
|
+
module Git
|
4
|
+
##
|
5
|
+
# Stages the current changes in git, commits, and pushes
|
6
|
+
require_relative "git_command"
|
7
|
+
class Commit < GitCommand
|
8
|
+
attr_reader :directory
|
9
|
+
|
10
|
+
def commit!
|
11
|
+
git_client.commit(commit_message)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def commit_message
|
17
|
+
"Updating entry for #{Date.today}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Crusoe
|
2
|
+
module Commands
|
3
|
+
module Git
|
4
|
+
class GitCommand
|
5
|
+
require "git"
|
6
|
+
|
7
|
+
MAIN_GIT_BRANCH = "main".freeze
|
8
|
+
|
9
|
+
attr_reader :directory
|
10
|
+
|
11
|
+
def initialize(directory:)
|
12
|
+
super()
|
13
|
+
@directory = directory
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def git_client
|
19
|
+
return @git_client if defined?(@git_client)
|
20
|
+
|
21
|
+
(Git.init(directory) unless File.directory?(File.join(directory, ".git")))
|
22
|
+
|
23
|
+
@git_client = ::Git.open(directory)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Crusoe
|
2
|
+
module Commands
|
3
|
+
module Git
|
4
|
+
##
|
5
|
+
# Stages the current changes in git, commits, and pushes
|
6
|
+
require_relative "remote_git_command"
|
7
|
+
class Pull < RemoteGitCommand
|
8
|
+
def main
|
9
|
+
git_client.pull(remote_origin, MAIN_GIT_BRANCH)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Crusoe
|
2
|
+
module Commands
|
3
|
+
module Git
|
4
|
+
require_relative "git_command"
|
5
|
+
class RemoteGitCommand < GitCommand
|
6
|
+
REMOTE_NAME = "origin".freeze
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def remote_origin
|
11
|
+
git_client.remote(REMOTE_NAME)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "../../crusoe/entry"
|
2
|
+
require_relative "../../crusoe/entry_file"
|
3
|
+
require_relative "../../crusoe/entry_file_name"
|
4
|
+
require_relative "../../crusoe/entry_template"
|
5
|
+
module Crusoe
|
6
|
+
module Commands
|
7
|
+
class Journal
|
8
|
+
attr_reader :entry_file_name
|
9
|
+
attr_reader :default_file_content
|
10
|
+
|
11
|
+
def initialize(directory:, date: Date.today)
|
12
|
+
entry = Crusoe::Entry.new(date)
|
13
|
+
@entry_file_name = EntryFileName.new(entry, directory).to_s
|
14
|
+
@default_file_content = EntryTemplate.new(entry).to_s
|
15
|
+
end
|
16
|
+
|
17
|
+
def prepare_entry_file!
|
18
|
+
EntryFile.create_unless_exist(entry_file_name, default_file_content)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative "../../crusoe/entry"
|
2
|
+
require_relative "../../crusoe/entry_file"
|
3
|
+
require_relative "../../crusoe/entry_file_name"
|
4
|
+
require_relative "../../crusoe/entry_template"
|
5
|
+
module Crusoe
|
6
|
+
module Commands
|
7
|
+
class Read
|
8
|
+
attr_reader :date_range
|
9
|
+
attr_reader :directory
|
10
|
+
|
11
|
+
DAY_SEPARATOR = "\n\n".freeze
|
12
|
+
JOURNAL_FILE_DATE_REGEX = %r{/(?<date>\d{4}-\d{2}-\d{2})\.md$}
|
13
|
+
|
14
|
+
def initialize(directory:, date_range:)
|
15
|
+
@directory = directory
|
16
|
+
@date_range = date_range
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
files.map { File.read(_1) }.join(DAY_SEPARATOR)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def files
|
26
|
+
Dir.glob(File.join(directory, "*", "*.md"))
|
27
|
+
.select do |file|
|
28
|
+
match_data = file.match(JOURNAL_FILE_DATE_REGEX)
|
29
|
+
file_date = Date.parse(match_data[:date])
|
30
|
+
date_range.include?(file_date)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Crusoe
|
2
|
+
class Configuration
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
DEFAULT_DIRECTORY = File.join(Dir.home, ".crusoe")
|
6
|
+
ENTRIES_DIRECTORY_NAME = "entries".freeze
|
7
|
+
CONFIGURATION_FILE_NAME = "config.yml".freeze
|
8
|
+
|
9
|
+
attr_reader :git_repo
|
10
|
+
attr_reader :entries_directory_path
|
11
|
+
|
12
|
+
def initialize(base_directory_path = DEFAULT_DIRECTORY)
|
13
|
+
configuration_file_path = File.join(base_directory_path, CONFIGURATION_FILE_NAME)
|
14
|
+
configs = YAML.load_file(configuration_file_path)
|
15
|
+
@directory = configs["directory"] || DEFAULT_DIRECTORY
|
16
|
+
@git_repo = configs["git_repo"]
|
17
|
+
@entries_directory_path = File.join(base_directory_path, ENTRIES_DIRECTORY_NAME)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/crusoe/entry.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
module Crusoe
|
2
|
+
class EntryFile
|
3
|
+
attr_reader :entry_file_name
|
4
|
+
attr_reader :content
|
5
|
+
|
6
|
+
def self.create_unless_exist(entry_file_name, content = "")
|
7
|
+
entry_file = new(entry_file_name)
|
8
|
+
|
9
|
+
return if entry_file.exist?
|
10
|
+
|
11
|
+
entry_file.write(content)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(entry_file_name)
|
15
|
+
@entry_file_name = entry_file_name.to_s
|
16
|
+
@content = content
|
17
|
+
end
|
18
|
+
|
19
|
+
def exist?
|
20
|
+
File.exist?(entry_file_name)
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(content)
|
24
|
+
dir_path = File.dirname(entry_file_name.to_s)
|
25
|
+
FileUtils.mkdir_p(dir_path)
|
26
|
+
File.write(entry_file_name.to_s, content)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Crusoe
|
2
|
+
class EntryFileName
|
3
|
+
attr_reader :entry
|
4
|
+
attr_reader :entries_directory
|
5
|
+
|
6
|
+
DATE_SEPARATOR = "-".freeze
|
7
|
+
|
8
|
+
def initialize(entry, entries_directory)
|
9
|
+
@entry = entry
|
10
|
+
@entries_directory = entries_directory
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_file_path
|
14
|
+
File.join(entries_directory,
|
15
|
+
month_directory_name,
|
16
|
+
file_name) + file_format
|
17
|
+
end
|
18
|
+
|
19
|
+
alias to_s to_file_path
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def month_directory_name
|
24
|
+
entry.date.to_s
|
25
|
+
.split(DATE_SEPARATOR)
|
26
|
+
.take(2)
|
27
|
+
.join(DATE_SEPARATOR)
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_name
|
31
|
+
entry.date.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
def file_format
|
35
|
+
".md"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "erb"
|
3
|
+
|
4
|
+
module Crusoe
|
5
|
+
class EntryTemplate
|
6
|
+
attr_reader :entry
|
7
|
+
|
8
|
+
def initialize(entry)
|
9
|
+
@entry = entry
|
10
|
+
end
|
11
|
+
|
12
|
+
def rendered_template_content
|
13
|
+
markdown = ERB.new(template_content)
|
14
|
+
markdown.result(entry.binding)
|
15
|
+
end
|
16
|
+
|
17
|
+
alias to_s rendered_template_content
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def template_content
|
22
|
+
File.read(template_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
def template_path
|
26
|
+
File.join(
|
27
|
+
Pathname.new(__FILE__).dirname.realpath,
|
28
|
+
"templates",
|
29
|
+
"entry_template.md.erb"
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Crusoe
|
2
|
+
class Interface
|
3
|
+
def display(content)
|
4
|
+
$stdout.puts content
|
5
|
+
end
|
6
|
+
|
7
|
+
def write(file_name)
|
8
|
+
system("#{editor_exe} #{editor_options} #{file_name}")
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def editor_exe
|
14
|
+
"${EDITOR:-vi}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def editor_options
|
18
|
+
"-w"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/crusoe.rb
ADDED
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: crusoe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gavin Morrice
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: yaml
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |
|
56
|
+
Crusoe is a gem that helps you keep track of your daily
|
57
|
+
work and thoughts in Markdown files. It automates the
|
58
|
+
process of creating, updating, and organising these files.
|
59
|
+
email:
|
60
|
+
- gavin@gavinmorrice.com
|
61
|
+
executables:
|
62
|
+
- crusoe
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".rspec"
|
67
|
+
- ".rubocop.yml"
|
68
|
+
- ".ruby-version"
|
69
|
+
- CHANGELOG.md
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- LICENSE.txt
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- exe/crusoe
|
76
|
+
- lib/crusoe.rb
|
77
|
+
- lib/crusoe/cli.rb
|
78
|
+
- lib/crusoe/commands.rb
|
79
|
+
- lib/crusoe/commands/git.rb
|
80
|
+
- lib/crusoe/commands/git/add.rb
|
81
|
+
- lib/crusoe/commands/git/checkout.rb
|
82
|
+
- lib/crusoe/commands/git/commit.rb
|
83
|
+
- lib/crusoe/commands/git/git_command.rb
|
84
|
+
- lib/crusoe/commands/git/pull.rb
|
85
|
+
- lib/crusoe/commands/git/push.rb
|
86
|
+
- lib/crusoe/commands/git/remote_git_command.rb
|
87
|
+
- lib/crusoe/commands/journal.rb
|
88
|
+
- lib/crusoe/commands/read.rb
|
89
|
+
- lib/crusoe/configuration.rb
|
90
|
+
- lib/crusoe/entry.rb
|
91
|
+
- lib/crusoe/entry_file.rb
|
92
|
+
- lib/crusoe/entry_file_name.rb
|
93
|
+
- lib/crusoe/entry_template.rb
|
94
|
+
- lib/crusoe/interface.rb
|
95
|
+
- lib/crusoe/templates/entry_template.md.erb
|
96
|
+
- lib/crusoe/version.rb
|
97
|
+
homepage: https://github.com/bodacious/crusoe
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata:
|
101
|
+
allowed_push_host: https://rubygems.org
|
102
|
+
homepage_uri: https://github.com/bodacious/crusoe
|
103
|
+
source_code_uri: https://github.com/bodacious/crusoe
|
104
|
+
changelog_uri: https://github.com/bodacious/crusoe/CHANGELOG.md
|
105
|
+
rubygems_mfa_required: 'true'
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '3.0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubygems_version: 3.4.8
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: A journaling tool for developers.
|
125
|
+
test_files: []
|