worque 0.1.5 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 509912a33940b740eb50a0c98aa55f256e90cd48
4
- data.tar.gz: d7dc7cd45b482af9b5c6001289c2ea7dac11b258
3
+ metadata.gz: fcaba8f8f67002bfdd2c6b8eb49961deda41186f
4
+ data.tar.gz: bcc471deff6aa73ab3481819b6396a0e13e214d8
5
5
  SHA512:
6
- metadata.gz: 23dfc71b98a0d455469892dd4f917885bf7f40173db4bd30c4363f7c680d2da22c455eeb13a067da700409a74fdbd99cd28b09c1070fe06ef54c2c9406acc4d6
7
- data.tar.gz: 9c16073df9e1e2d069739c4c7b535254892f765d8604d72e90b9abec64f539d529ca17e1888529665df2c46eca44969dfe50939e8842a613d2816ceae0e747af
6
+ metadata.gz: 4e7143b95c2d5a40c92290189ae9c62c45442c265ceb8807dd54519216a2d5184544df2c9e9f96b422280b3b8df0340fe8165fc3f373fae50cc8e9257a8c7124
7
+ data.tar.gz: 2a3b41249ac41cec06aeea39a10f58b7d4234c5c773083d04dca0a85d757d354aeafac7106ac9fbc8e7962e9dc3238e26271f0e707cd02cfa4c11e99b50c94ef
data/README.md CHANGED
@@ -37,19 +37,30 @@ Or, if you're using RVM and want the command available system-wide while keeping
37
37
 
38
38
  #### `worque todo`
39
39
 
40
- Add this to your `.bash_profile`
40
+ Explicitly declare your path
41
41
 
42
42
  ```sh
43
- export WORQUE_PATH='/path/to/your/notes'
43
+ worque todo --path /path/to/your/notes
44
44
  ```
45
45
 
46
- I often map it to my Dropbox like this
46
+ Or you might want to put it in the global configuration file `~/.worquerc`
47
+
48
+ ```json
49
+ {
50
+ "path": "/path/to/your/notes"
51
+ }
52
+ ```
53
+
54
+
55
+ I often prefer mapping notes to my Dropbox like this:
47
56
 
48
57
  ```sh
49
- export WORQUE_PATH='~/Dropbox/Notes/Todos'
58
+ {
59
+ "path": "~/Dropbox/Notes/Todos"
60
+ }
50
61
  ```
51
62
 
52
- Then executing the command below will create a today's note for you
63
+ Then executing the command below will create a today's note.
53
64
 
54
65
  ```sh
55
66
  worque todo --for today
@@ -59,21 +70,22 @@ worque todo --for today
59
70
  Or look back what's done yesterday.
60
71
 
61
72
  ```sh
62
- workque todo --for=yesterday
73
+ worque todo --for=yesterday
63
74
  # ~/notes/checklist-2016-07-18.md
64
75
  # This will jump back to Friday's note if it's Monday today!
65
76
  ```
66
77
 
67
- If you're kind of nerd and you have no life. You would rather work over the weekend than hanging out with folks, so you should enable the **hardcore** mode which will stop skipping weekend for you.
78
+ Lastly, jump ahead and start to plan for tomorrow.
68
79
 
69
80
  ```sh
70
- worque todo --for yesterday --no-skip-weekend
81
+ worque todo --for=tomorrow
82
+ # ~/notes/checklist-2016-07-20.md
71
83
  ```
72
84
 
73
- You can also explicitly specify the file path
85
+ If you're kind of nerd and you have no life. You would rather work over the weekend than hanging out with folks, so you should enable the **hardcore** mode which will stop skipping weekend for you.
74
86
 
75
87
  ```sh
76
- worque todo --for today --path ~/path/to/your/notes
88
+ worque todo --for yesterday --no-skip-weekend
77
89
  ```
78
90
 
79
91
  Moreover, you can add a task into your notes quickly without open that file.
@@ -93,8 +105,8 @@ Personally I alias it like `today` like this, so vim will automatically open the
93
105
  file when I type `today`
94
106
 
95
107
  ```sh
96
- alias today="vim $(worque todo) +':cd $WORQUE_PATH'"
97
- alias ytd="vim $(worque todo) +':cd $WORQUE_PATH'"
108
+ alias today="vim $(worque todo)"
109
+ alias ytd="vim $(worque todo --for=yesterday)"
98
110
  ```
99
111
 
100
112
  #### `worque push`
@@ -138,7 +150,7 @@ bundle install
138
150
  bundle exec rake test
139
151
  ```
140
152
 
141
- ## To be implemented
153
+ ## WORKQUE FOR WORKQUE
142
154
 
143
155
  Something in my plan:
144
156
 
data/lib/worque/cli.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require 'thor'
2
- require 'worque/command/todo'
2
+ require 'worque/command/todo/action'
3
3
  require 'worque/command/todo/options'
4
- require 'worque/command/push'
4
+ require 'worque/command/push/action'
5
5
  require 'worque/command/push/options'
6
+ require 'worque/default_config'
6
7
 
7
8
  module Worque
8
9
  class CLI < ::Thor
@@ -10,16 +11,17 @@ module Worque
10
11
 
11
12
  desc 'todo', 'Make a todo'
12
13
 
13
- method_option :for, force: false, type: :string, enum: ['today', 'yesterday'], default: 'today'
14
- method_option :skip_weekend, force: false, type: :boolean, default: true
15
- method_option :path, force: false, type: :string, default: ENV['WORQUE_PATH']
16
- method_option :append_task, force: false, type: :string
14
+ method_option :for, type: :string, enum: ['today', 'yesterday', 'tomorrow'], default: 'today'
15
+ method_option :skip_weekend, type: :boolean, default: true
16
+ method_option :path, type: :string
17
+ method_option :append_task, type: :string
17
18
 
18
19
  def todo
19
20
  begin
20
- result = Worque::Command::Todo.run(options)
21
+ default_opts = Worque::DefaultConfig.load!.data
22
+ result = Worque::Command::Todo::Action.run(default_opts.merge options)
21
23
  rescue InvalidPath => e
22
- abort e.message
24
+ $stderr.puts e.message
23
25
  end
24
26
 
25
27
  $stdout.puts result
@@ -27,11 +29,13 @@ module Worque
27
29
 
28
30
  desc 'push', 'Push your notes to Slack channel'
29
31
 
30
- method_option :for, force: false, type: :string, enum: ['today', 'yesterday'], default: 'today'
31
- method_option :channel, force: true, required: true, type: :string, desc: 'Can be channel, private group ID or name. E.g. #daily-report'
32
+ method_option :path, type: :string
33
+ method_option :for, type: :string, enum: ['today', 'yesterday', 'tomorrow'], default: 'today'
34
+ method_option :channel, required: true, type: :string, desc: 'Can be channel, private group ID or name. E.g. #daily-report'
32
35
 
33
36
  def push
34
- $stdout.puts Worque::Command::Push.run(options)
37
+ default_opts = Worque::DefaultConfig.load!.data
38
+ $stdout.puts Worque::Command::Push::Action.run(default_opts.merge options)
35
39
  end
36
40
  end
37
41
  end
@@ -0,0 +1,55 @@
1
+ require 'worque/utils/slack'
2
+ require 'worque/utils/business_day'
3
+ require 'json'
4
+
5
+ module Worque
6
+ module Command
7
+ module Push
8
+ class Action
9
+ REPORT_FILE_PATH_FORMAT = "%<worque_path>s/notes-%<date_for>s.md".freeze
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ end
14
+
15
+ def call
16
+ slack = Worque::Utils::Slack.new(options.token)
17
+ JSON.dump(slack.post(options.channel, report_file_content))
18
+ end
19
+
20
+ class << self
21
+ def run(options)
22
+ require 'worque/command/push/options'
23
+
24
+ new(Worque::Command::Push::Options.new(options)).call()
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :options
31
+
32
+ def date_for
33
+ case options.for.to_sym
34
+ when :today
35
+ Date.today
36
+ when :yesterday
37
+ Worque::Utils::BusinessDay.previous(Date.today, true)
38
+ end
39
+ end
40
+
41
+ def report_file_content
42
+ File.open(report_file_path).read
43
+ end
44
+
45
+ def report_file_path
46
+ REPORT_FILE_PATH_FORMAT % Hash[
47
+ worque_path: options.path,
48
+ date_for: date_for
49
+ ]
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -4,11 +4,13 @@ module Worque
4
4
  attr_reader :channel
5
5
  attr_reader :token
6
6
  attr_reader :for
7
+ attr_reader :path
7
8
 
8
9
  def initialize(options)
9
10
  @channel = options[:channel]
11
+ @path = options[:path]
10
12
  @for = options[:for]
11
- @token = ENV['SLACK_API_TOKEN']
13
+ @token = options[:token]
12
14
  end
13
15
  end
14
16
  end
@@ -0,0 +1,63 @@
1
+ require 'worque/utils/command'
2
+ require 'worque/utils/business_day'
3
+ require 'date'
4
+
5
+ module Worque
6
+ module Command
7
+ module Todo
8
+ class Action
9
+ FILE_PATH_FORMAT = "%<path>s/notes-%<date>s.md".freeze
10
+
11
+ def initialize(options)
12
+ @options = options
13
+ validate_options!
14
+ end
15
+
16
+ def call
17
+ Worque::Utils::Command.mkdir(options.path)
18
+
19
+ notes_file_path = filename(date_for).tap do |f|
20
+ Worque::Utils::Command.touch f
21
+ end
22
+
23
+ if options.append_task
24
+ Worque::Utils::Command.append_text(notes_file_path, options.append_task)
25
+ end
26
+
27
+ notes_file_path
28
+ end
29
+
30
+ class << self
31
+ def run(options)
32
+ new(Worque::Command::Todo::Options.new(options)).call()
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ attr_reader :options
39
+
40
+ def date_for
41
+ case options.for.to_sym
42
+ when :today
43
+ Date.today
44
+ when :yesterday
45
+ Worque::Utils::BusinessDay.previous(Date.today, options.skip_weekend?)
46
+ when :tomorrow
47
+ Worque::Utils::BusinessDay.next(Date.today, options.skip_weekend?)
48
+ end
49
+ end
50
+
51
+ def filename(date)
52
+ FILE_PATH_FORMAT % { path: options.path, date: date }
53
+ end
54
+
55
+ def validate_options!
56
+ if options.path.to_s.empty?
57
+ raise InvalidPath, 'Neither --path nor WORQUE_PATH is not set'
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,33 @@
1
+ module Worque
2
+ class Hash < ::Thor::CoreExt::HashWithIndifferentAccess; end
3
+
4
+ class DefaultConfig
5
+ attr_reader :data
6
+
7
+ def initialize(data = ::Worque::Hash.new)
8
+ @data = data
9
+ end
10
+
11
+ class << self
12
+ def load!
13
+ new(::Worque::Hash.new(parsed_config))
14
+ end
15
+
16
+ private
17
+
18
+ def parsed_config
19
+ JSON.parse(load_file)
20
+ rescue Errno::ENOENT
21
+ {}
22
+ end
23
+
24
+ def load_file
25
+ File.read(config_file_path)
26
+ end
27
+
28
+ def config_file_path
29
+ "#{Dir.home}/.worquerc"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -3,8 +3,8 @@ module Worque
3
3
  module BusinessDay
4
4
  extend self
5
5
 
6
- def next(date)
7
- shift(date, 1)
6
+ def next(date, skip_weekend = true)
7
+ shift(date, 1, skip_weekend)
8
8
  end
9
9
 
10
10
  def previous(date, skip_weekend = true)
@@ -18,11 +18,9 @@ module Worque
18
18
  private
19
19
 
20
20
  def shift(date, inc, skip_weekend = true)
21
- loop do
22
- date += inc
23
- break if !skip_weekend || !weekend?(date)
24
- end
25
- date
21
+ return date + inc unless skip_weekend && weekend?(date + inc)
22
+
23
+ shift(date + inc, inc, skip_weekend)
26
24
  end
27
25
 
28
26
  def weekend?(date)
@@ -1,3 +1,3 @@
1
1
  module Worque
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: worque
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cam Huynh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-27 00:00:00.000000000 Z
11
+ date: 2016-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -108,10 +108,11 @@ files:
108
108
  - bin/worque
109
109
  - lib/worque.rb
110
110
  - lib/worque/cli.rb
111
- - lib/worque/command/push.rb
111
+ - lib/worque/command/push/action.rb
112
112
  - lib/worque/command/push/options.rb
113
- - lib/worque/command/todo.rb
113
+ - lib/worque/command/todo/action.rb
114
114
  - lib/worque/command/todo/options.rb
115
+ - lib/worque/default_config.rb
115
116
  - lib/worque/utils/business_day.rb
116
117
  - lib/worque/utils/command.rb
117
118
  - lib/worque/utils/slack.rb
@@ -137,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
138
  version: '0'
138
139
  requirements: []
139
140
  rubyforge_project:
140
- rubygems_version: 2.4.5.1
141
+ rubygems_version: 2.6.6
141
142
  signing_key:
142
143
  specification_version: 4
143
144
  summary: Manage your daily working list
@@ -1,48 +0,0 @@
1
- require 'worque/utils/slack'
2
- require 'worque/utils/business_day'
3
- require 'json'
4
-
5
- module Worque
6
- module Command
7
- class Push
8
- def initialize(options)
9
- @options = options
10
- end
11
-
12
- def call
13
- slack = Worque::Utils::Slack.new(options.token)
14
- JSON.dump(slack.post(options.channel, report_file_content))
15
- end
16
-
17
- def self.run(options)
18
- require 'worque/command/push/options'
19
-
20
- Worque::Command::Push.new(
21
- Worque::Command::Push::Options.new(options)
22
- ).call()
23
- end
24
-
25
- private
26
-
27
- attr_reader :options
28
-
29
- def date_for
30
- case options.for.to_sym
31
- when :today
32
- Date.today
33
- when :yesterday
34
- Worque::Utils::BusinessDay.previous(Date.today, true)
35
- end
36
- end
37
-
38
- def report_file_content
39
- File.open(report_file_path).read
40
- end
41
-
42
- def report_file_path
43
- "#{ ENV['WORQUE_PATH'] }/notes-#{date_for}.md"
44
- end
45
- end
46
- end
47
- end
48
-
@@ -1,58 +0,0 @@
1
- require 'worque/utils/command'
2
- require 'worque/utils/business_day'
3
- require 'date'
4
-
5
- module Worque
6
- module Command
7
- class Todo
8
- def initialize(options)
9
- @options = options
10
- validate_options!
11
- end
12
-
13
- def call
14
- Worque::Utils::Command.mkdir(options.path)
15
-
16
- notes_file_path = filename(date_for)
17
- notes_file_path.tap do |f|
18
- Worque::Utils::Command.touch f
19
- end
20
-
21
- if options.append_task
22
- Worque::Utils::Command.append_text(notes_file_path, options.append_task)
23
- end
24
-
25
- notes_file_path
26
- end
27
-
28
- def self.run(options)
29
- Worque::Command::Todo.new(
30
- Worque::Command::Todo::Options.new(options)
31
- ).call()
32
- end
33
-
34
- private
35
-
36
- attr_reader :options
37
-
38
- def date_for
39
- case options.for.to_sym
40
- when :today
41
- Date.today
42
- when :yesterday
43
- Worque::Utils::BusinessDay.previous(Date.today, options.skip_weekend?)
44
- end
45
- end
46
-
47
- def filename(date)
48
- "#{options.path}/notes-#{date}.md"
49
- end
50
-
51
- def validate_options!
52
- if options.path.to_s.empty?
53
- raise InvalidPath, 'Neither --path nor WORQUE_PATH is not set'
54
- end
55
- end
56
- end
57
- end
58
- end