tcelfer 1.0.1

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.
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2018 Anthony Gargiulo <anthony@agargiulo.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ require 'date'
18
+ require 'logger'
19
+ require 'sequel'
20
+
21
+ module Tcelfer
22
+ # Middleware between Sequel and everything else
23
+ class Storage
24
+ attr_reader :days
25
+
26
+ def initialize
27
+ db = Sequel.connect("sqlite://#{Tcelfer.config.sqlite_path}")
28
+ db.loggers << Logger.new($stderr) if Tcelfer.config.debug
29
+ validate_db! db
30
+ Dir["#{__dir__}/models/*"].each(&Kernel.method(:require))
31
+ @days = Tcelfer::Models::Day
32
+ @days.plugin :update_or_create
33
+ end
34
+
35
+ # Record a new day or update an existing one
36
+ # @param [String] rating
37
+ # @param [String] notes
38
+ # @param [Date] date
39
+ def rec_day(rating, notes, date)
40
+ if Tcelfer.config.update_existing
41
+ days.update_or_create({ date: date }, rating: rating, notes: notes)
42
+ elsif days.where(date: date).count.zero?
43
+ days.new(date: date, rating: rating, notes: notes).save
44
+ else
45
+ raise Tcelfer::DuplicateDayError, "Date: `#{date}' already has a record. Try again tomorrow."
46
+ end
47
+ end
48
+
49
+ # Returns an array of Tcelfer::Model::Day objects for the given month/year
50
+ # @param [Integer] month
51
+ # @param [Integer] year
52
+ # @return [Array]
53
+ def by_month(month, year)
54
+ raise StorageError, "Invalid Month #{month}, valid: [1-12]" unless (1..12).cover? month
55
+
56
+ @days.where(date: Date.new(year, month, 1)..Date.new(year, month, -1)).to_a
57
+ end
58
+
59
+ private
60
+
61
+ def validate_db!(db)
62
+ raise Tcelfer::StorageError, 'did you forget to run `bin/db_init`?' unless db.tables.include? :days
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2018 Anthony Gargiulo <anthony@agargiulo.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ module Tcelfer
18
+ VERSION = '1.0.1'
19
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2018 Anthony Gargiulo <anthony@agargiulo.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ require 'bundler/setup'
18
+ require 'tcelfer'
19
+
20
+ RSpec.configure do |config|
21
+ # Enable flags like --only-failures and --next-failure
22
+ config.example_status_persistence_file_path = '.rspec_status'
23
+
24
+ # Disable RSpec exposing methods globally on `Module` and `main`
25
+ config.disable_monkey_patching!
26
+
27
+ config.expect_with :rspec do |c|
28
+ c.syntax = :expect
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (C) 2018 Anthony Gargiulo <anthony@agargiulo.com>
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ RSpec.describe Tcelfer do
18
+ context 'base info' do
19
+ before(:all) do
20
+ ENV['TCELFER_SQLITE_PATH'] = ''
21
+ end
22
+ it 'has a version number' do
23
+ expect(Tcelfer::VERSION).not_to be nil
24
+ end
25
+
26
+ it 'defines more than one daily rating' do
27
+ expect(Tcelfer::DAY_RATINGS.length).to be > 1
28
+ end
29
+
30
+ it 'is configurable with any_config' do
31
+ expect(described_class.config).to be_a Anyway::Config
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,247 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tcelfer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Anthony Gargiulo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.50'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.50'
97
+ - !ruby/object:Gem::Dependency
98
+ name: anyway_config
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: paint
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: sequel
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.15'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '5.15'
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.3'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.3'
153
+ - !ruby/object:Gem::Dependency
154
+ name: terminal-table
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.8'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.8'
167
+ - !ruby/object:Gem::Dependency
168
+ name: thor
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.20'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.20'
181
+ - !ruby/object:Gem::Dependency
182
+ name: tty-prompt
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '0.18'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '0.18'
195
+ description: Reflect on your day, prompts with thor or webapp and stores to db
196
+ email:
197
+ - anthony@agargiulo.com
198
+ executables:
199
+ - tcelfer
200
+ extensions: []
201
+ extra_rdoc_files: []
202
+ files:
203
+ - CHANGELOG.md
204
+ - Dockerfile
205
+ - Gemfile
206
+ - Gemfile.lock
207
+ - LICENSE
208
+ - README.md
209
+ - Rakefile
210
+ - exe/tcelfer
211
+ - lib/tcelfer.rb
212
+ - lib/tcelfer/cli.rb
213
+ - lib/tcelfer/cli/report.rb
214
+ - lib/tcelfer/config.rb
215
+ - lib/tcelfer/errors.rb
216
+ - lib/tcelfer/models/day.rb
217
+ - lib/tcelfer/storage.rb
218
+ - lib/tcelfer/version.rb
219
+ - spec/spec_helper.rb
220
+ - spec/tcelfer_spec.rb
221
+ homepage: https://www.github.com/agargiulo/tcelfer
222
+ licenses:
223
+ - GPL-3.0-only
224
+ metadata:
225
+ allowed_push_host: https://rubygems.org
226
+ homepage_uri: https://www.github.com/agargiulo/tcelfer
227
+ source_code_uri: https://www.github.com/agargiulo/tcelfer
228
+ post_install_message:
229
+ rdoc_options: []
230
+ require_paths:
231
+ - lib
232
+ required_ruby_version: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ required_rubygems_version: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ requirements: []
243
+ rubygems_version: 3.0.1
244
+ signing_key:
245
+ specification_version: 4
246
+ summary: Reflect on your day and keep track
247
+ test_files: []