seinfeld 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'thor'
7
+ gem 'yajl-ruby'
8
+
9
+ # Add dependencies to develop your gem here.
10
+ # Include everything needed to run rake, tests, features, etc.
11
+ group :development do
12
+ gem "rspec", "~> 2.8.0"
13
+ gem "rdoc", "~> 3.12"
14
+ gem "bundler", "~> 1.0.0"
15
+ gem "jeweler", "~> 1.8.3"
16
+ gem "rcov", ">= 0"
17
+ end
@@ -0,0 +1,37 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.3)
5
+ git (1.2.5)
6
+ jeweler (1.8.3)
7
+ bundler (~> 1.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rdoc
11
+ json (1.7.3)
12
+ rake (0.9.2.2)
13
+ rcov (0.9.11)
14
+ rdoc (3.12)
15
+ json (~> 1.4)
16
+ rspec (2.8.0)
17
+ rspec-core (~> 2.8.0)
18
+ rspec-expectations (~> 2.8.0)
19
+ rspec-mocks (~> 2.8.0)
20
+ rspec-core (2.8.0)
21
+ rspec-expectations (2.8.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.8.0)
24
+ thor (0.15.2)
25
+ yajl-ruby (1.1.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bundler (~> 1.0.0)
32
+ jeweler (~> 1.8.3)
33
+ rcov
34
+ rdoc (~> 3.12)
35
+ rspec (~> 2.8.0)
36
+ thor
37
+ yajl-ruby
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 T.J. VanSlyke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ Seinfeld
2
+ ========
3
+
4
+ A command line utility for tracking daily habits.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ $ gem install seinfeld
10
+
11
+ Usage
12
+ -----
13
+
14
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "seinfeld"
18
+ gem.homepage = "http://github.com/teejayvanslyke/seinfeld"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Command line habit management}
21
+ gem.description = %Q{A command line utility for tracking daily habits}
22
+ gem.email = "teejay.vanslyke@gmail.com"
23
+ gem.authors = ["T.J. VanSlyke"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "seinfeld #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'seinfeld'
5
+
6
+ Seinfeld::Application.start
@@ -0,0 +1,113 @@
1
+ require 'thor'
2
+ require 'json'
3
+ require 'date'
4
+
5
+ module Seinfeld
6
+
7
+ class Entry
8
+ def initialize(attributes={})
9
+ @attributes = attributes
10
+ @attributes['date'] ||= Date.today
11
+ end
12
+
13
+ attr_reader :attributes
14
+
15
+ def as_json
16
+ attributes
17
+ end
18
+
19
+ def method_missing(name, *args)
20
+ if attributes[name.to_s]
21
+ return attributes[name.to_s]
22
+ else
23
+ super
24
+ end
25
+ end
26
+ end
27
+
28
+ class Habit
29
+ def initialize(attributes={})
30
+ @attributes = attributes
31
+ if @attributes['entries']
32
+ @entries = @attributes['entries'].map {|attrs| Entry.new(attrs)}
33
+ else
34
+ @entries = []
35
+ end
36
+ end
37
+
38
+ attr_reader :attributes, :entries
39
+
40
+ def as_json(options={})
41
+ attributes.merge(
42
+ 'entries' => entries.map(&:as_json)
43
+ )
44
+ end
45
+
46
+ def has_entry_for_date?(date)
47
+ @entries.any? {|e| e.date.to_s == date.to_s }
48
+ end
49
+
50
+ def increment!
51
+ unless has_entry_for_date?(Date.today)
52
+ @entries << Entry.new
53
+ end
54
+ end
55
+
56
+ def day_count
57
+ @entries.length
58
+ end
59
+
60
+ def method_missing(name, *args)
61
+ if attributes[name.to_s]
62
+ return attributes[name.to_s]
63
+ else
64
+ super
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ class Application < Thor
71
+
72
+ def initialize(*args)
73
+ super *args
74
+
75
+ @file = ENV['SEINFILE'] || File.join(ENV['HOME'], '.seinfile')
76
+
77
+ if File.exists?(@file)
78
+ data = JSON.parse(File.read(@file))
79
+ @habits = data.inject({}) { |_, a| _.merge(a[0] => Habit.new(a[1])) }
80
+ else
81
+ @habits = {}
82
+ end
83
+ end
84
+
85
+ attr_reader :habits
86
+
87
+ desc "do", "Increment the day counter for the specified habit"
88
+ def do(id)
89
+ @habits[id] ||= Habit.new(id: id)
90
+ @habits[id].increment!
91
+ save!
92
+ puts "[#{id}] #{@habits[id].day_count} consecutive day(s)."
93
+ end
94
+
95
+ desc "list", "List all habits and their current day counts"
96
+ def list
97
+ @habits.each do |id, habit|
98
+ puts "[#{id}] #{habit.day_count} consecutive day(s)."
99
+ end
100
+ end
101
+
102
+
103
+ no_tasks do
104
+ def save!
105
+ File.open(@file, 'w') do |file|
106
+ file.write(JSON.pretty_generate(habits.inject({}) {|_, a| _.merge(a[0] => a[1].as_json)} ))
107
+ end
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "seinfeld"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["T.J. VanSlyke"]
12
+ s.date = "2012-06-15"
13
+ s.description = "A command line utility for tracking daily habits"
14
+ s.email = "teejay.vanslyke@gmail.com"
15
+ s.executables = ["seinfeld"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/seinfeld",
30
+ "lib/seinfeld.rb",
31
+ "seinfeld.gemspec",
32
+ "spec/seinfeld_spec.rb",
33
+ "spec/spec_helper.rb"
34
+ ]
35
+ s.homepage = "http://github.com/teejayvanslyke/seinfeld"
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = "1.8.10"
39
+ s.summary = "Command line habit management"
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<thor>, [">= 0"])
46
+ s.add_runtime_dependency(%q<yajl-ruby>, [">= 0"])
47
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
48
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
49
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
50
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
51
+ s.add_development_dependency(%q<rcov>, [">= 0"])
52
+ else
53
+ s.add_dependency(%q<thor>, [">= 0"])
54
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
55
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
56
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
57
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ s.add_dependency(%q<rcov>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<thor>, [">= 0"])
63
+ s.add_dependency(%q<yajl-ruby>, [">= 0"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
65
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ end
70
+ end
71
+
@@ -0,0 +1,67 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ require 'fileutils'
4
+
5
+ describe Seinfeld::Application do
6
+ def test_seinfile_path
7
+ File.dirname(__FILE__) + '/test-seinfile'
8
+ end
9
+
10
+ before { ENV['SEINFILE'] = test_seinfile_path }
11
+ after { ENV['SEINFILE'] = nil }
12
+
13
+ subject { Seinfeld::Application.new }
14
+ describe "do" do
15
+ before do
16
+ subject.do 'yoga'
17
+ end
18
+
19
+ its(:habits) { should have(1).item }
20
+ end
21
+ end
22
+
23
+ describe Seinfeld::Habit do
24
+ before { @habit = Seinfeld::Habit.new(id: 'yoga') }
25
+ subject { @habit }
26
+ its(:day_count) { should == 0 }
27
+
28
+ describe "#increment!" do
29
+ before { @habit.increment! }
30
+ subject { @habit }
31
+ its(:day_count) { should == 1 }
32
+ its(:entries) { should have(1).item }
33
+ describe "first entry" do
34
+ subject { @habit.entries.first }
35
+ its(:date) { should == Date.today }
36
+ end
37
+
38
+ describe "adding two entries for the same day" do
39
+ before { @habit.increment! }
40
+ subject { @habit }
41
+ its(:day_count) { should == 1 }
42
+ its(:entries) { should have(1).item }
43
+ end
44
+ end
45
+ end
46
+
47
+ describe "persistence" do
48
+
49
+ def test_seinfile_path
50
+ File.dirname(__FILE__) + '/test-seinfile'
51
+ end
52
+
53
+ before do
54
+ @app = Seinfeld::Application.new
55
+ @app.do 'yoga'
56
+ end
57
+
58
+ after do
59
+ FileUtils.rm test_seinfile_path
60
+ end
61
+
62
+ it "should persist the data when reinstantiating with the same file" do
63
+ new_app = Seinfeld::Application.new
64
+
65
+ new_app.habits['yoga'].id.should == "yoga"
66
+ end
67
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'seinfeld'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seinfeld
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - T.J. VanSlyke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-15 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70219906594620 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70219906594620
25
+ - !ruby/object:Gem::Dependency
26
+ name: yajl-ruby
27
+ requirement: &70219906593200 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70219906593200
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70219906592360 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.8.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70219906592360
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70219906591580 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70219906591580
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70219906590900 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 1.0.0
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70219906590900
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: &70219906590040 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 1.8.3
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70219906590040
80
+ - !ruby/object:Gem::Dependency
81
+ name: rcov
82
+ requirement: &70219906585860 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70219906585860
91
+ description: A command line utility for tracking daily habits
92
+ email: teejay.vanslyke@gmail.com
93
+ executables:
94
+ - seinfeld
95
+ extensions: []
96
+ extra_rdoc_files:
97
+ - LICENSE.txt
98
+ - README.markdown
99
+ files:
100
+ - .document
101
+ - .rspec
102
+ - Gemfile
103
+ - Gemfile.lock
104
+ - LICENSE.txt
105
+ - README.markdown
106
+ - Rakefile
107
+ - VERSION
108
+ - bin/seinfeld
109
+ - lib/seinfeld.rb
110
+ - seinfeld.gemspec
111
+ - spec/seinfeld_spec.rb
112
+ - spec/spec_helper.rb
113
+ homepage: http://github.com/teejayvanslyke/seinfeld
114
+ licenses:
115
+ - MIT
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ segments:
127
+ - 0
128
+ hash: 1271641201725858572
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 1.8.10
138
+ signing_key:
139
+ specification_version: 3
140
+ summary: Command line habit management
141
+ test_files: []