tempo-cli 0.2.6 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.lock +64 -39
- data/README.md +16 -7
- data/Rakefile +3 -3
- data/bin/tempo +28 -0
- data/features/step_definitions/tempo_steps.rb +14 -14
- data/features/support/env.rb +1 -1
- data/lib/file_record/directory.rb +104 -1
- data/lib/file_record/file_utility.rb +50 -8
- data/lib/file_record/record.rb +11 -10
- data/lib/tempo/controllers/end_controller.rb +1 -1
- data/lib/tempo/controllers/projects_controller.rb +1 -1
- data/lib/tempo/controllers/records_controller.rb +56 -4
- data/lib/tempo/controllers/report_controller.rb +1 -1
- data/lib/tempo/controllers/start_controller.rb +2 -2
- data/lib/tempo/exceptions.rb +11 -0
- data/lib/tempo/models/log.rb +20 -3
- data/lib/tempo/models/time_record.rb +7 -1
- data/lib/tempo/version.rb +1 -1
- data/lib/tempo/views/base.rb +3 -3
- data/lib/tempo/views/formatters/interactive.rb +44 -0
- data/lib/tempo/views/formatters/screen.rb +9 -10
- data/lib/tempo/views/interactive.rb +32 -0
- data/lib/tempo/views/reporter.rb +15 -0
- data/lib/tempo/views/view_records/base.rb +24 -0
- data/lib/tempo/views/view_records/time_record.rb +1 -1
- data/tempo-cli.gemspec +6 -8
- data/test/lib/file_record/directory_test.rb +17 -14
- data/test/lib/file_record/record_test.rb +11 -8
- data/test/lib/tempo/models/base_test.rb +3 -3
- data/test/lib/tempo/models/composite_test.rb +2 -2
- data/test/lib/tempo/models/log_test.rb +17 -7
- data/test/lib/tempo/models/project_test.rb +1 -1
- data/test/lib/tempo/models/time_record_test.rb +4 -4
- data/test/lib/tempo/views/formatters/console_test.rb +32 -0
- data/test/lib/tempo/views/reporter_test.rb +7 -1
- data/test/support/factories.rb +9 -17
- metadata +25 -31
@@ -7,17 +7,69 @@ module Tempo
|
|
7
7
|
|
8
8
|
def initialize_from_records(options, args)
|
9
9
|
|
10
|
-
dir =
|
11
|
-
|
12
|
-
if File.exists?(File.join(dir, 'tempo'))
|
10
|
+
dir = options.fetch( :directory, ENV['HOME'])
|
13
11
|
|
12
|
+
if File.exist?(File.join(dir, 'tempo'))
|
14
13
|
Tempo::Controllers::Projects.load directory: dir
|
15
|
-
|
16
14
|
else
|
17
15
|
FileRecord::Directory.create_new directory: dir
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
19
|
+
def backup_records(options, args)
|
20
|
+
dir = options.fetch( :directory, ENV['HOME'])
|
21
|
+
Views::interactive_progress "\nBacking up #{dir}/tempo"
|
22
|
+
|
23
|
+
if File.exist?(File.join(dir, 'tempo'))
|
24
|
+
dest = FileRecord::Directory.backup directory: dir
|
25
|
+
Views::interactive_progress "Sucessfully created #{dest}"
|
26
|
+
else
|
27
|
+
Views::no_items("directory #{dir}/tempo", :error)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def old_records_present?(options)
|
32
|
+
file_utility = FileRecord::FileUtility.new(Tempo::Model::TimeRecord, options)
|
33
|
+
file_utility.old_style_log_records_exists?
|
34
|
+
end
|
35
|
+
|
36
|
+
def move_old_records(options)
|
37
|
+
file_utility = FileRecord::FileUtility.new(Tempo::Model::TimeRecord, options)
|
38
|
+
file_utility.move_old_records
|
39
|
+
end
|
40
|
+
|
41
|
+
def clean_records(options, args)
|
42
|
+
dir = File.join( options.fetch( :directory, ENV['HOME']), "tempo", "tempo_time_records")
|
43
|
+
|
44
|
+
if old_records_present? options
|
45
|
+
|
46
|
+
confirm = Tempo::Views::interactive_confirm_move_old_records
|
47
|
+
|
48
|
+
if confirm.positive_response?
|
49
|
+
move_old_records options
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
Views::interactive_progress "Loading records from #{dir}"
|
54
|
+
|
55
|
+
days = Model::TimeRecord.record_d_ids(options)
|
56
|
+
|
57
|
+
days.each do |d_id|
|
58
|
+
begin
|
59
|
+
date = "#{d_id[4..5].to_i}/#{d_id[6..7]}/#{d_id[0..3]}"
|
60
|
+
Views::interactive_progress_partial date
|
61
|
+
Model::TimeRecord.load_day_record(d_id, options)
|
62
|
+
Model::TimeRecord.save_to_file(options)
|
63
|
+
Model::TimeRecord.clear_all
|
64
|
+
rescue TimeConflictError => e
|
65
|
+
Views::message " exiting on error..."
|
66
|
+
Views::message "\nAn error occurred which prevented cleaning all the records on #{date}"
|
67
|
+
Views::message "Please repair the records in file #{dir}/#{Model::TimeRecord.file(d_id)}"
|
68
|
+
return Views::error e
|
69
|
+
end
|
70
|
+
end
|
71
|
+
Views::message "\nSuccess -- all files are clean!"
|
72
|
+
end
|
21
73
|
end #class << self
|
22
74
|
end
|
23
75
|
end
|
@@ -11,7 +11,7 @@ module Tempo
|
|
11
11
|
return Tempo::Views.project_assistance if Tempo::Model::Project.index.empty?
|
12
12
|
|
13
13
|
# A from flag has been supplied by the user
|
14
|
-
# and
|
14
|
+
# and possibly a to flag,
|
15
15
|
# so we return a period of day records
|
16
16
|
#
|
17
17
|
if options[:from] != "last record"
|
@@ -13,14 +13,14 @@ module Tempo
|
|
13
13
|
return Views.project_assistance if Model::Project.index.empty?
|
14
14
|
|
15
15
|
if not options[:at]
|
16
|
-
start_time = Time.new()
|
16
|
+
start_time = Time.new().round()
|
17
17
|
else
|
18
18
|
start_time = Time.parse options[:at]
|
19
19
|
end
|
20
20
|
|
21
21
|
return Views.no_match_error( "valid timeframe", options[:at], false ) if start_time.nil?
|
22
22
|
|
23
|
-
if start_time > Time.new()
|
23
|
+
if start_time > Time.new().round()
|
24
24
|
Views.warning("WARNING: logging time in the future may cause trouble maintaining running records")
|
25
25
|
end
|
26
26
|
|
data/lib/tempo/exceptions.rb
CHANGED
data/lib/tempo/models/log.rb
CHANGED
@@ -46,9 +46,13 @@ module Tempo
|
|
46
46
|
FileRecord::FileUtility.new(self, {time: time}).filename
|
47
47
|
end
|
48
48
|
|
49
|
+
def d_id_from_file(file)
|
50
|
+
/(\d+)\.yaml/.match(file)[1]
|
51
|
+
end
|
52
|
+
|
49
53
|
# Returns the immediate directory for the log
|
50
54
|
# Tempo::Model::MessageLog => tempo_message_logs
|
51
|
-
def dir
|
55
|
+
def dir(time)
|
52
56
|
FileRecord::FileUtility.new(self).log_directory
|
53
57
|
end
|
54
58
|
|
@@ -58,6 +62,10 @@ module Tempo
|
|
58
62
|
FileRecord::FileUtility.new(self, options).log_records
|
59
63
|
end
|
60
64
|
|
65
|
+
def record_d_ids(options={})
|
66
|
+
records(options).each_with_object(Array.new) {|file,d_ids| d_ids << d_id_from_file(file)}
|
67
|
+
end
|
68
|
+
|
61
69
|
# returns the loaded record with the latest start time
|
62
70
|
# Only loads records if options[:load] is true,
|
63
71
|
# otherwise assumes records are already loaded
|
@@ -102,10 +110,9 @@ module Tempo
|
|
102
110
|
|
103
111
|
# Return a Time object for the last record's date
|
104
112
|
def last_day(options={})
|
105
|
-
reg = /(\d+)\.yaml/
|
106
113
|
recs = records options
|
107
114
|
if recs.last
|
108
|
-
d_id =
|
115
|
+
d_id = d_id_from_file(recs.last)
|
109
116
|
time = day_id_to_time d_id if d_id
|
110
117
|
return time
|
111
118
|
end
|
@@ -131,6 +138,16 @@ module Tempo
|
|
131
138
|
FileRecord::FileUtility.new(self, options).file_path
|
132
139
|
end
|
133
140
|
|
141
|
+
# Normally not necessary to perform, only
|
142
|
+
# used when cleaning (and testing) records
|
143
|
+
def clear_all
|
144
|
+
@ids = {}
|
145
|
+
@index = []
|
146
|
+
@days_index = {}
|
147
|
+
@id_counter = {}
|
148
|
+
@current = nil
|
149
|
+
end
|
150
|
+
|
134
151
|
# takes and integer, and time or day_id
|
135
152
|
# and returns the instance that matches both
|
136
153
|
# the id and d_id
|
@@ -41,6 +41,12 @@ module Tempo
|
|
41
41
|
# super handles start_time, not end time
|
42
42
|
options[:start_time] ||= Time.now
|
43
43
|
@end_time = options.fetch :end_time, :running
|
44
|
+
|
45
|
+
if ! options[:exact_time]
|
46
|
+
options[:start_time] = options[:start_time].round unless options[:start_time] == :running
|
47
|
+
@end_time = @end_time.round unless @end_time == :running
|
48
|
+
end
|
49
|
+
|
44
50
|
verify_times options[:start_time], @end_time
|
45
51
|
|
46
52
|
super options
|
@@ -146,7 +152,7 @@ module Tempo
|
|
146
152
|
if @end_time.kind_of? Time
|
147
153
|
end_time = @end_time
|
148
154
|
else
|
149
|
-
end_time = Time.now()
|
155
|
+
end_time = Time.now().round
|
150
156
|
end
|
151
157
|
end_time.to_i - @start_time.to_i
|
152
158
|
end
|
data/lib/tempo/version.rb
CHANGED
data/lib/tempo/views/base.rb
CHANGED
@@ -48,13 +48,13 @@ module Tempo
|
|
48
48
|
def no_items(items, category=:info)
|
49
49
|
ViewRecords::Message.new "no #{items} exist", category: category
|
50
50
|
if items == "projects"
|
51
|
-
ViewRecords::Message.new "You must at least one project before you can begin tracking time"
|
51
|
+
ViewRecords::Message.new "You must create at least one project before you can begin tracking time"
|
52
52
|
ViewRecords::Message.new "run `tempo project --help` for more information"
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
def message(message)
|
57
|
-
ViewRecords::Message.new message, category:
|
56
|
+
def message(message, category=:info)
|
57
|
+
ViewRecords::Message.new message, category: category
|
58
58
|
end
|
59
59
|
|
60
60
|
def warning(message)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# The Console block handles interactive queries and progress reports.
|
2
|
+
# It is required when reporting must be done in 'real time' rather than compiled
|
3
|
+
# during runtime and then presented at the end (see Views::Screen). It is the only
|
4
|
+
# formatter that receives blocks as soon as they are handed to the Reporter
|
5
|
+
|
6
|
+
module Tempo
|
7
|
+
module Views
|
8
|
+
module Formatters
|
9
|
+
|
10
|
+
class Interactive < Tempo::Views::Formatters::Base
|
11
|
+
|
12
|
+
|
13
|
+
def message_block(record)
|
14
|
+
record.format do |m|
|
15
|
+
case m.category
|
16
|
+
when :immediate
|
17
|
+
puts "#{m.message}"
|
18
|
+
when :progress
|
19
|
+
puts "#{m.message}..."
|
20
|
+
when :progress_partial
|
21
|
+
$stdout.sync = true
|
22
|
+
print "#{m.message}..."
|
23
|
+
end
|
24
|
+
m.message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def query_block(query)
|
29
|
+
query.format do |q|
|
30
|
+
puts q.query
|
31
|
+
response = Readline.readline('> ', true)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def format_records_container(container)
|
36
|
+
# Pass through over-ride
|
37
|
+
# We don't allow interactive containers at this time because they
|
38
|
+
# would need to be able to detect when the container is complete.
|
39
|
+
# (report containers raised errors on nil durations).
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
# Tempo View Formatters are triggered by the View Reporter
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# see <TODO> for an example of proc blocks.
|
1
|
+
# Tempo View Formatters are triggered by the View Reporter, and all inherit from
|
2
|
+
# Views::Base
|
3
|
+
#
|
4
|
+
# The screen formatter is the primary formatter for reporting results back to the
|
5
|
+
# screen. All formatting is handled after the main processes, when the Reporter is
|
6
|
+
# invoked during the post block. (If immediate feedback is needed,
|
7
|
+
# see Formatters::Console)
|
9
8
|
|
10
9
|
module Tempo
|
11
10
|
module Views
|
@@ -31,7 +30,7 @@ module Tempo
|
|
31
30
|
end
|
32
31
|
end
|
33
32
|
|
34
|
-
# PARTIALS
|
33
|
+
# PARTIALS vv-----------------------------------------------------------------vv
|
35
34
|
|
36
35
|
# spacer for project titles, active project marked with *
|
37
36
|
def active_indicator(project)
|
@@ -56,7 +55,7 @@ module Tempo
|
|
56
55
|
@options[:id] ? "[#{id}] ".rjust(6, ' ') : ""
|
57
56
|
end
|
58
57
|
|
59
|
-
# PARTIALS
|
58
|
+
# PARTIALS ^^-----------------------------------------------------------------^^
|
60
59
|
|
61
60
|
|
62
61
|
def project_block(record)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Tempo
|
2
|
+
module Views
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Must be allowed to return results
|
6
|
+
def interactive_query(query)
|
7
|
+
ViewRecords::Query.new query
|
8
|
+
end
|
9
|
+
|
10
|
+
def interactive_progress(message)
|
11
|
+
ViewRecords::Message.new message, category: :progress
|
12
|
+
end
|
13
|
+
|
14
|
+
def interactive_progress_partial(message)
|
15
|
+
ViewRecords::Message.new message, category: :progress_partial
|
16
|
+
end
|
17
|
+
|
18
|
+
def interactive_confirm_clean
|
19
|
+
query = "\nCleaning Tempo records resaves all records, looking for errors.\n" +
|
20
|
+
"In the event that a record cannot be corrected, you wil be prompted to repair the record manually.\n" +
|
21
|
+
"A backup of the records will also be created before any changes are made.\n\n" +
|
22
|
+
"Do you wish to continue? [YyNn]"
|
23
|
+
interactive_query(query)
|
24
|
+
end
|
25
|
+
|
26
|
+
def interactive_confirm_move_old_records
|
27
|
+
query = "\nYou have files which match an older file structure, do you want to move them so they will be included in your records? [YyNn]"
|
28
|
+
interactive_query(query)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/tempo/views/reporter.rb
CHANGED
@@ -6,6 +6,11 @@
|
|
6
6
|
#
|
7
7
|
# class instance variables:
|
8
8
|
#
|
9
|
+
# @@console
|
10
|
+
# A shell formtter which receives view records as they are created and can
|
11
|
+
# intercept messages that should be displayed in real time, as well as interactive
|
12
|
+
# prompts
|
13
|
+
#
|
9
14
|
# @@formats
|
10
15
|
# an array of formatters, which will be passed the view records on exit
|
11
16
|
# Reporter will always run the error formater first, to check for errors in
|
@@ -20,6 +25,7 @@ module Tempo
|
|
20
25
|
module Views
|
21
26
|
|
22
27
|
class Reporter
|
28
|
+
@@console
|
23
29
|
@@formats
|
24
30
|
@@view_records
|
25
31
|
@@options
|
@@ -40,6 +46,12 @@ module Tempo
|
|
40
46
|
@@options ||= {}
|
41
47
|
end
|
42
48
|
|
49
|
+
# All records are sent directly to the console, so it can decide if
|
50
|
+
# action is required immediately based on the type of record
|
51
|
+
def console
|
52
|
+
@@console ||= Formatters::Interactive.new(options)
|
53
|
+
end
|
54
|
+
|
43
55
|
def add_options(options)
|
44
56
|
@@options ||= {}
|
45
57
|
@@options.merge! options
|
@@ -50,6 +62,9 @@ module Tempo
|
|
50
62
|
|
51
63
|
if /Views::ViewRecords/.match record.class.name
|
52
64
|
@@view_records << record
|
65
|
+
|
66
|
+
# console must be able to return a value
|
67
|
+
return console.report record
|
53
68
|
else
|
54
69
|
raise InvalidViewRecordError
|
55
70
|
end
|
@@ -46,6 +46,30 @@ module Tempo
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
# Query records are handled by the console formatter,
|
50
|
+
# returning results from a call to Readline
|
51
|
+
class Query
|
52
|
+
attr_accessor :type, :query, :match, :response
|
53
|
+
|
54
|
+
def initialize(query, options={})
|
55
|
+
@query = query
|
56
|
+
@type = "query"
|
57
|
+
@match = options.fetch(:match, /(y|Y)(es)?/)
|
58
|
+
@response = Reporter.add_view_record self
|
59
|
+
end
|
60
|
+
|
61
|
+
def positive_response?
|
62
|
+
true if @response.match(@match)
|
63
|
+
end
|
64
|
+
|
65
|
+
def format(&block)
|
66
|
+
# TODO: should we create an interactive default? using:
|
67
|
+
# confirm = Readline.readline('> ', true).match(/(y|Y)(es)?/)
|
68
|
+
block ||= lambda { |q| puts "#{q.query}"; Readline.readline('> ', true) }
|
69
|
+
response = block.call self
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
49
73
|
# Specifically for managing a time duration, nested in other
|
50
74
|
# view records. This can be used with a start and end time,
|
51
75
|
# or used to manage a sum of times.
|
@@ -27,7 +27,7 @@ module Tempo
|
|
27
27
|
@description = model.description
|
28
28
|
@description ||= ""
|
29
29
|
@duration = Duration.new model.duration
|
30
|
-
@end_time = model.end_time == :running ? Time.now() : model.end_time
|
30
|
+
@end_time = model.end_time == :running ? Time.now().round : model.end_time
|
31
31
|
@project = model.project_title
|
32
32
|
@running = model.running?
|
33
33
|
self.class.max_description_length @description.length
|
data/tempo-cli.gemspec
CHANGED
@@ -12,14 +12,12 @@ spec = Gem::Specification.new do |s|
|
|
12
12
|
s.description = 'tempo-cli is a command line time tracking application. Record time spent on projects in YAML files, and manage them from the command line.'
|
13
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.require_paths << 'lib'
|
15
|
-
s.has_rdoc = true
|
16
15
|
s.bindir = 'bin'
|
17
16
|
s.executables << 'tempo'
|
18
|
-
s.add_development_dependency
|
19
|
-
s.add_development_dependency
|
20
|
-
s.add_development_dependency
|
21
|
-
s.add_development_dependency
|
22
|
-
s.
|
23
|
-
s.add_runtime_dependency
|
24
|
-
s.add_runtime_dependency "chronic", "~> 0.10"
|
17
|
+
s.add_development_dependency 'rake', '~> 10.3'
|
18
|
+
s.add_development_dependency 'aruba', '~> 2.2'
|
19
|
+
s.add_development_dependency 'turn', '~> 0.9.7'
|
20
|
+
s.add_development_dependency 'pry','~> 0.14.2'
|
21
|
+
s.add_runtime_dependency 'gli', '~> 2.21', '>= 2.21.1'
|
22
|
+
s.add_runtime_dependency 'chronic', '~> 0.10.2'
|
25
23
|
end
|
@@ -2,41 +2,44 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
describe FileRecord do
|
4
4
|
|
5
|
-
|
5
|
+
def setup
|
6
6
|
@dir = File.join(Dir.home,"tempo")
|
7
7
|
@alt_dir = File.join(Dir.home, "testdir", "tempo")
|
8
|
-
FileUtils.rm_r @dir if File.
|
8
|
+
FileUtils.rm_r @dir if File.exist?(@dir)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
FileUtils.rm_r @dir if File.
|
13
|
-
FileUtils.rm_r @alt_dir if File.
|
11
|
+
def teardown
|
12
|
+
FileUtils.rm_r @dir if File.exist?(@dir)
|
13
|
+
FileUtils.rm_r @alt_dir if File.exist?(@alt_dir)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
16
|
describe "Directory" do
|
18
17
|
|
19
18
|
describe "initialize" do
|
20
19
|
|
21
|
-
it "
|
20
|
+
it "initializes a new directory structure" do
|
22
21
|
project_file = File.join(@dir, "tempo_projects.yaml")
|
23
22
|
readme = File.join(@dir, "README.txt")
|
24
23
|
|
25
24
|
FileRecord::Directory.create_new
|
26
|
-
File.
|
27
|
-
File.
|
28
|
-
File.
|
25
|
+
File.exist?( @dir ).must_equal true
|
26
|
+
File.exist?( project_file ).must_equal true
|
27
|
+
File.exist?( readme ).must_equal true
|
29
28
|
end
|
30
29
|
|
31
|
-
it "
|
30
|
+
it "takes an optional directory parameter" do
|
32
31
|
project_file = File.join(@alt_dir, "tempo_projects.yaml")
|
33
32
|
readme = File.join(@alt_dir, "README.txt")
|
34
33
|
dir = File.join(Dir.home, "testdir")
|
35
34
|
|
36
35
|
FileRecord::Directory.create_new directory: dir
|
37
|
-
File.
|
38
|
-
File.
|
39
|
-
File.
|
36
|
+
File.exist?( @alt_dir ).must_equal true
|
37
|
+
File.exist?( project_file ).must_equal true
|
38
|
+
File.exist?( readme ).must_equal true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "creates a zipped backup directory" do
|
42
|
+
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -5,9 +5,9 @@ describe FileRecord do
|
|
5
5
|
before do
|
6
6
|
# See Rakefile for directory prep and cleanup
|
7
7
|
dir = File.join(Dir.home,"tempo")
|
8
|
-
Dir.mkdir(dir, 0700) unless File.
|
8
|
+
Dir.mkdir(dir, 0700) unless File.exist?(dir)
|
9
9
|
@dir = File.join(Dir.home,"tempo", "tempo_unit_tests")
|
10
|
-
Dir.mkdir(@dir, 0700) unless File.
|
10
|
+
Dir.mkdir(@dir, 0700) unless File.exist?(@dir)
|
11
11
|
end
|
12
12
|
|
13
13
|
describe "Record" do
|
@@ -16,7 +16,7 @@ describe FileRecord do
|
|
16
16
|
|
17
17
|
it "should create a record of all instances" do
|
18
18
|
test_file = File.join(ENV['HOME'],'tempo','tempo_animals.yaml')
|
19
|
-
File.delete( test_file ) if File.
|
19
|
+
File.delete( test_file ) if File.exist?( test_file )
|
20
20
|
pantherinae_factory
|
21
21
|
FileRecord::Record.save_model( Tempo::Model::Animal )
|
22
22
|
contents = eval_file_as_array( test_file )
|
@@ -28,13 +28,13 @@ describe FileRecord do
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
describe "
|
31
|
+
describe "recording a Tempo Log" do
|
32
32
|
|
33
33
|
it "should create daily records containing each instance" do
|
34
|
-
test_file_1 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '20140101.yaml')
|
35
|
-
File.delete(
|
36
|
-
test_file_2 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '20140102.yaml')
|
37
|
-
File.delete(
|
34
|
+
test_file_1 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '2014', '20140101.yaml')
|
35
|
+
File.delete( test_file_1 ) if File.exist?( test_file_1 )
|
36
|
+
test_file_2 = File.join(ENV['HOME'],'tempo','tempo_message_logs', '2014', '20140102.yaml')
|
37
|
+
File.delete( test_file_2 ) if File.exist?( test_file_2 )
|
38
38
|
|
39
39
|
log_factory
|
40
40
|
FileRecord::Record.save_log(Tempo::Model::MessageLog)
|
@@ -67,5 +67,8 @@ describe FileRecord do
|
|
67
67
|
":message: day 2 water the bonsai"]
|
68
68
|
end
|
69
69
|
end
|
70
|
+
|
71
|
+
describe "reading a Tempo Log" do
|
72
|
+
end
|
70
73
|
end
|
71
74
|
end
|
@@ -19,7 +19,7 @@ describe Tempo do
|
|
19
19
|
before do
|
20
20
|
# See Rakefile for directory prep and cleanup
|
21
21
|
@dir = File.join( Dir.home,"tempo" )
|
22
|
-
Dir.mkdir(@dir, 0700) unless File.
|
22
|
+
Dir.mkdir(@dir, 0700) unless File.exist?(@dir)
|
23
23
|
end
|
24
24
|
|
25
25
|
def after_teardown
|
@@ -57,7 +57,7 @@ describe Tempo do
|
|
57
57
|
it "grants children the ability to write to a file" do
|
58
58
|
frog_factory
|
59
59
|
test_file = File.join(ENV['HOME'],'tempo','tempo_animals.yaml')
|
60
|
-
File.delete(test_file) if File.
|
60
|
+
File.delete(test_file) if File.exist?( test_file )
|
61
61
|
contents = Tempo::Model::Animal.save_to_file
|
62
62
|
contents = eval_file_as_array( test_file )
|
63
63
|
contents.must_equal ["---", ":id: 1", ":genious: hyla", ":species: h. versicolor",
|
@@ -69,7 +69,7 @@ describe Tempo do
|
|
69
69
|
|
70
70
|
it "grants children ability to read from a file" do
|
71
71
|
test_file = File.join(ENV['HOME'],'tempo','tempo_animals.yaml')
|
72
|
-
File.delete(test_file) if File.
|
72
|
+
File.delete(test_file) if File.exist?( test_file )
|
73
73
|
file_lines = [ "---", ":id: 11", ":genious: hyla", ":species: h. versicolor",
|
74
74
|
"---", ":id: 12", ":genious: hyla", ":species: h. chrysoscelis",
|
75
75
|
"---", ":id: 14", ":genious: hyla", ":species: h. andersonii",
|
@@ -5,7 +5,7 @@ describe Tempo do
|
|
5
5
|
before do
|
6
6
|
# See Rakefile for directory prep and cleanup
|
7
7
|
@dir = File.join( Dir.home,"tempo" )
|
8
|
-
Dir.mkdir(@dir, 0700) unless File.
|
8
|
+
Dir.mkdir(@dir, 0700) unless File.exist?(@dir)
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "Model::Composite" do
|
@@ -44,7 +44,7 @@ describe Tempo do
|
|
44
44
|
it "should revive a tree structure from a file" do
|
45
45
|
tree_factory
|
46
46
|
test_file = File.join(ENV['HOME'],'tempo','tempo_trees.yaml')
|
47
|
-
File.delete(test_file) if File.
|
47
|
+
File.delete(test_file) if File.exist?( test_file )
|
48
48
|
contents = Tempo::Model::Tree.save_to_file
|
49
49
|
Tempo::Model::Tree.clear_all
|
50
50
|
Tempo::Model::Tree.read_from_file
|
@@ -5,11 +5,11 @@ describe Tempo do
|
|
5
5
|
before do
|
6
6
|
# See Rakefile for directory prep and cleanup
|
7
7
|
@dir = File.join( Dir.home,"tempo" )
|
8
|
-
Dir.mkdir(@dir, 0700) unless File.
|
8
|
+
Dir.mkdir(@dir, 0700) unless File.exist?(@dir)
|
9
9
|
end
|
10
10
|
|
11
11
|
after do
|
12
|
-
FileUtils.rm_r(@dir) if File.
|
12
|
+
FileUtils.rm_r(@dir) if File.exist?(@dir)
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "Model::Log" do
|
@@ -34,8 +34,8 @@ describe Tempo do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
it "knows which directory to save to" do
|
37
|
-
|
38
|
-
Tempo::Model::MessageLog.dir.must_equal "tempo_message_logs"
|
37
|
+
date = Time.new(2021,1,1)
|
38
|
+
Tempo::Model::MessageLog.dir(date).must_equal "tempo_message_logs"
|
39
39
|
end
|
40
40
|
|
41
41
|
it "knows which file name to save to" do
|
@@ -44,13 +44,14 @@ describe Tempo do
|
|
44
44
|
Tempo::Model::MessageLog.file(date).must_equal "20140101.yaml"
|
45
45
|
end
|
46
46
|
|
47
|
+
#TODO-NEW-LOG-DIR
|
47
48
|
it "grants children the ability to write to a file" do
|
48
49
|
log_factory
|
49
50
|
test_dir = File.join(ENV['HOME'],'tempo','tempo_message_logs')
|
50
|
-
FileUtils.rm_r test_dir if File.
|
51
|
+
FileUtils.rm_r test_dir if File.exist?(test_dir)
|
51
52
|
Tempo::Model::MessageLog.save_to_file
|
52
|
-
test_file_1 = File.join(test_dir, "20140101.yaml")
|
53
|
-
test_file_2 = File.join(test_dir, "20140102.yaml")
|
53
|
+
test_file_1 = File.join(test_dir, "2014/20140101.yaml")
|
54
|
+
test_file_2 = File.join(test_dir, "2014/20140102.yaml")
|
54
55
|
contents = eval_file_as_array( test_file_1 )
|
55
56
|
# testing with regex because time zone will be different on different computers,
|
56
57
|
# ex: ":start_time: 2014-01-02 07:15:00.000000000 -05:00"
|
@@ -92,6 +93,15 @@ describe Tempo do
|
|
92
93
|
Tempo::Model::MessageLog.index[0].message.must_equal "day 1 pet the sheep"
|
93
94
|
end
|
94
95
|
|
96
|
+
it "can clear records out after load" do
|
97
|
+
log_record_factory
|
98
|
+
time = Time.new(2014, 1, 1)
|
99
|
+
Tempo::Model::MessageLog.load_day_record time
|
100
|
+
Tempo::Model::MessageLog.ids( time ).must_equal [1,2,3]
|
101
|
+
Tempo::Model::MessageLog.clear_all
|
102
|
+
Tempo::Model::MessageLog.ids( time ).must_equal []
|
103
|
+
end
|
104
|
+
|
95
105
|
it "knows the date of the last record" do
|
96
106
|
log_record_factory
|
97
107
|
last_day = Tempo::Model::MessageLog.last_day
|