timetrap 1.1.3 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CONTRIBUTORS ADDED
@@ -0,0 +1,3 @@
1
+ * Sam Goldstein
2
+ * Ian Smith-Heisters
3
+ * Ammar Ali
data/README.md CHANGED
@@ -102,6 +102,13 @@ Commands
102
102
 
103
103
  usage: ``t backend``
104
104
 
105
+ **configure**
106
+ Creates a config file at ~/.timetrap.yml or ENV['TIMETRAP_CONFIG_FILE'] if
107
+ one doesn't exist. Prints path to config file. Currently allows configuration
108
+ of path to database file.
109
+
110
+ usage: ``t configure``
111
+
105
112
  **display**
106
113
  Display a given timesheet. If no timesheet is specified, show the current
107
114
  timesheet. If ``all`` is passed as SHEET display all timesheets. Accepts
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 1
4
- :patch: 3
3
+ :minor: 2
4
+ :patch: 0
data/lib/timetrap.rb CHANGED
@@ -3,15 +3,17 @@ require 'chronic'
3
3
  require 'sequel'
4
4
  require 'sequel/extensions/inflector'
5
5
  require 'Getopt/Declare'
6
+ require File.join(File.dirname(__FILE__), 'timetrap', 'config')
6
7
  require File.join(File.dirname(__FILE__), 'timetrap', 'helpers')
7
8
  require File.join(File.dirname(__FILE__), 'timetrap', 'cli')
8
- DB_NAME = defined?(TEST_MODE) ? nil : "#{ENV['HOME']}/.timetrap.db"
9
+ DB_NAME = defined?(TEST_MODE) ? nil : Timetrap::Config['database_file']
9
10
  # connect to database. This will create one if it doesn't exist
10
11
  DB = Sequel.sqlite DB_NAME
11
12
  require File.join(File.dirname(__FILE__), 'timetrap', 'models')
12
13
  Dir["#{File.dirname(__FILE__)}/timetrap/formatters/*.rb"].each do |path|
13
14
  require path
14
15
  end
16
+
15
17
  module Timetrap
16
18
  extend self
17
19
 
data/lib/timetrap/cli.rb CHANGED
@@ -18,6 +18,7 @@ where COMMAND is one of:
18
18
  -e, --end <date:qs> Include entries that start on this date or earlier
19
19
  * backend - open an sqlite shell to the database
20
20
  usage: t backend
21
+ * configure - write out a config file. print path to config file.
21
22
  * display - display the current timesheet or a specific. Pass `all' as
22
23
  SHEET to display all sheets.
23
24
  usage: t display [--ids] [--start DATE] [--end DATE] [--format FMT] [SHEET | all]
@@ -106,6 +107,11 @@ where COMMAND is one of:
106
107
  end
107
108
  end
108
109
 
110
+ def configure
111
+ Config.configure!
112
+ say "Config file is at #{Config::PATH.inspect}"
113
+ end
114
+
109
115
  def edit
110
116
  entry = args['-i'] ? Entry[args['-i']] : Timetrap.active_entry
111
117
  say "can't find entry" && return unless entry
@@ -0,0 +1,29 @@
1
+ module Timetrap
2
+ module Config
3
+ extend self
4
+ PATH = ENV['TIMETRAP_CONFIG_FILE'] || File.join(ENV['HOME'], '.timetrap.yml')
5
+
6
+ def defaults
7
+ {
8
+ 'database_file' => "#{ENV['HOME']}/.timetrap.db"
9
+ }
10
+ end
11
+
12
+ def [](key)
13
+ overrides = File.exist?(PATH) ? YAML.load(File.read(PATH)) : {}
14
+ defaults.merge(overrides)[key]
15
+ rescue => e
16
+ puts "invalid config file"
17
+ puts e.message
18
+ defaults[key]
19
+ end
20
+
21
+ def configure!
22
+ unless File.exist?(PATH)
23
+ File.open(PATH, 'w') do |fh|
24
+ fh.puts(defaults.to_yaml)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,7 @@
1
1
  TEST_MODE = true
2
2
  require File.join(File.dirname(__FILE__), '..', 'lib', 'timetrap')
3
3
  require 'spec'
4
+ require 'fakefs/safe'
4
5
 
5
6
  describe Timetrap do
6
7
  def create_entry atts = {}
@@ -48,6 +49,25 @@ describe Timetrap do
48
49
  end
49
50
  end
50
51
 
52
+ describe 'config' do
53
+ it "should write a config file" do
54
+ FakeFS do
55
+ FileUtils.mkdir_p(ENV['HOME'])
56
+ FileUtils.rm(ENV['HOME'] + '/.timetrap.yml')
57
+ File.exist?(ENV['HOME'] + '/.timetrap.yml').should be_false
58
+ invoke "configure"
59
+ File.exist?(ENV['HOME'] + '/.timetrap.yml').should be_true
60
+ end
61
+ end
62
+
63
+ it "should descirve config file" do
64
+ FakeFS do
65
+ invoke "configure"
66
+ $stdout.string.should == "Config file is at \"#{ENV['HOME']}/.timetrap.yml\"\n"
67
+ end
68
+ end
69
+ end
70
+
51
71
  describe 'edit' do
52
72
  before do
53
73
  Timetrap.start "running entry", nil
data/timetrap.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{timetrap}
8
- s.version = "1.1.3"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Goldstein"]
12
- s.date = %q{2009-11-27}
12
+ s.date = %q{2009-12-06}
13
13
  s.default_executable = %q{t}
14
- s.description = %q{Timetrap is a lightweight command line time tracker, written in ruby. See http://github.com/samg/timetrap for more details}
14
+ s.description = %q{Command line time tracker}
15
15
  s.email = %q{sgrock@gmail.com}
16
16
  s.executables = ["t"]
17
17
  s.extra_rdoc_files = [
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".gitignore",
23
+ "CONTRIBUTORS",
23
24
  "LICENSE.txt",
24
25
  "README.md",
25
26
  "Rakefile",
@@ -28,6 +29,7 @@ Gem::Specification.new do |s|
28
29
  "bin/t",
29
30
  "lib/timetrap.rb",
30
31
  "lib/timetrap/cli.rb",
32
+ "lib/timetrap/config.rb",
31
33
  "lib/timetrap/formatters/csv.rb",
32
34
  "lib/timetrap/formatters/ical.rb",
33
35
  "lib/timetrap/formatters/text.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Goldstein
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-27 00:00:00 -08:00
12
+ date: 2009-12-06 00:00:00 -08:00
13
13
  default_executable: t
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -82,7 +82,7 @@ dependencies:
82
82
  - !ruby/object:Gem::Version
83
83
  version: 1.1.2
84
84
  version:
85
- description: Timetrap is a lightweight command line time tracker, written in ruby. See http://github.com/samg/timetrap for more details
85
+ description: Command line time tracker
86
86
  email: sgrock@gmail.com
87
87
  executables:
88
88
  - t
@@ -93,6 +93,7 @@ extra_rdoc_files:
93
93
  - README.md
94
94
  files:
95
95
  - .gitignore
96
+ - CONTRIBUTORS
96
97
  - LICENSE.txt
97
98
  - README.md
98
99
  - Rakefile
@@ -101,6 +102,7 @@ files:
101
102
  - bin/t
102
103
  - lib/timetrap.rb
103
104
  - lib/timetrap/cli.rb
105
+ - lib/timetrap/config.rb
104
106
  - lib/timetrap/formatters/csv.rb
105
107
  - lib/timetrap/formatters/ical.rb
106
108
  - lib/timetrap/formatters/text.rb