goldie 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -0
- data/Gemfile.lock +36 -0
- data/LICENSE +7 -0
- data/bin/goldie +18 -0
- data/goldie.gemspec +25 -0
- data/lib/goldie/commands.rb +102 -0
- data/lib/goldie/database.rb +21 -0
- data/lib/goldie/item.rb +14 -0
- data/lib/goldie.rb +8 -0
- metadata +119 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
goldie (0.0.1)
|
5
|
+
activerecord
|
6
|
+
bundler
|
7
|
+
sqlite3
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activemodel (3.2.8)
|
13
|
+
activesupport (= 3.2.8)
|
14
|
+
builder (~> 3.0.0)
|
15
|
+
activerecord (3.2.8)
|
16
|
+
activemodel (= 3.2.8)
|
17
|
+
activesupport (= 3.2.8)
|
18
|
+
arel (~> 3.0.2)
|
19
|
+
tzinfo (~> 0.3.29)
|
20
|
+
activesupport (3.2.8)
|
21
|
+
i18n (~> 0.6)
|
22
|
+
multi_json (~> 1.0)
|
23
|
+
arel (3.0.2)
|
24
|
+
builder (3.0.3)
|
25
|
+
i18n (0.6.1)
|
26
|
+
multi_json (1.3.6)
|
27
|
+
rake (0.9.2.2)
|
28
|
+
sqlite3 (1.3.6)
|
29
|
+
tzinfo (0.3.33)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
goldie!
|
36
|
+
rake
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Jeremy Ruten
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/bin/goldie
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "goldie"
|
5
|
+
|
6
|
+
ActiveRecord::Migration.verbose = false
|
7
|
+
|
8
|
+
DIR = ENV["GOLDIE_DIR"] || File.join(ENV["HOME"], ".goldie")
|
9
|
+
FileUtils.mkdir_p DIR unless File.exists? DIR
|
10
|
+
|
11
|
+
DB_ADAPTER = "sqlite3"
|
12
|
+
DB_PATH = File.join(DIR, "todo.sqlite3")
|
13
|
+
|
14
|
+
db = Goldie::Database.new(DB_ADAPTER, DB_PATH)
|
15
|
+
|
16
|
+
ARGV << "progress_list" if ARGV.empty?
|
17
|
+
|
18
|
+
Goldie::Commands.send(*ARGV)
|
data/goldie.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "goldie"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.date = "2012-09-21"
|
5
|
+
s.summary = "A todo list with a progress bar."
|
6
|
+
s.description = "Goldie is a simple command line todo list with a progress bar."
|
7
|
+
s.author = "Jeremy Ruten"
|
8
|
+
s.email = "jeremy.ruten@gmail.com"
|
9
|
+
s.homepage = "http://github.com/yjerem/goldie"
|
10
|
+
s.license = "MIT"
|
11
|
+
s.required_ruby_version = ">= 1.9.2"
|
12
|
+
s.executables << "goldie"
|
13
|
+
|
14
|
+
s.files = ["Gemfile", "Gemfile.lock", "LICENSE", "goldie.gemspec"]
|
15
|
+
s.files += ["bin/goldie"]
|
16
|
+
s.files += Dir["lib/**/*.rb"]
|
17
|
+
|
18
|
+
%w(bundler sqlite3 activerecord).each do |gem_name|
|
19
|
+
s.add_runtime_dependency gem_name
|
20
|
+
end
|
21
|
+
|
22
|
+
%w(rake).each do |gem_name|
|
23
|
+
s.add_development_dependency gem_name
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module Goldie
|
2
|
+
module Commands
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def add(title, weight = 1)
|
6
|
+
item = Item.new(title: title, weight: weight)
|
7
|
+
if item.save
|
8
|
+
puts "Item saved."
|
9
|
+
else
|
10
|
+
puts "Item couldn't be saved:"
|
11
|
+
item.errors.messages.each do |field, messages|
|
12
|
+
messages.each do |message|
|
13
|
+
puts "- #{field} #{message}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def check(id)
|
20
|
+
if item = _find_item(id)
|
21
|
+
item.update_column :done, true
|
22
|
+
puts "Item checked off."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def uncheck(id)
|
27
|
+
if item = _find_item(id)
|
28
|
+
item.update_column :done, false
|
29
|
+
puts "Item unchecked."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def archive(id)
|
34
|
+
if item = _find_item(id)
|
35
|
+
item.update_column :archived, true
|
36
|
+
puts "Item archived."
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def unarchive(id)
|
41
|
+
if item = _find_item(id)
|
42
|
+
item.update_column :archived, false
|
43
|
+
puts "Item unarchived."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def delete(id)
|
48
|
+
if item = _find_item(id)
|
49
|
+
item.destroy
|
50
|
+
puts "Item deleted."
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def list(*flags)
|
55
|
+
items = Item.latest
|
56
|
+
if flags.include? "archived"
|
57
|
+
items = Item.archived
|
58
|
+
elsif not flags.include? "all"
|
59
|
+
items = Item.active
|
60
|
+
end
|
61
|
+
if items.empty?
|
62
|
+
puts "No items."
|
63
|
+
else
|
64
|
+
puts "id\tweight\titem"
|
65
|
+
items.each do |item|
|
66
|
+
archived = item.archived? ? "[A] " : ""
|
67
|
+
done = item.done? ? "[X] " : "[ ] "
|
68
|
+
puts "#{item.id}\t#{item.weight}\t#{done}#{archived}#{item.title}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def progress
|
74
|
+
if Item.active.empty?
|
75
|
+
puts "No active items."
|
76
|
+
else
|
77
|
+
total_weight = Item.active.sum(:weight)
|
78
|
+
checked_weight = Item.active.done.sum(:weight)
|
79
|
+
percent = checked_weight * 100 / total_weight
|
80
|
+
puts "[" + ("X" * (percent / 2)) + (" " * (50 - percent / 2)) + "] " + percent.to_s + "%"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def progress_list
|
85
|
+
if Item.active.empty?
|
86
|
+
puts "No active items."
|
87
|
+
else
|
88
|
+
list
|
89
|
+
puts
|
90
|
+
progress
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def _find_item(id)
|
95
|
+
if item = Item.where(id: id).first
|
96
|
+
item
|
97
|
+
else
|
98
|
+
puts "Couldn't find item with id '#{id}'."
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Goldie
|
2
|
+
class Database
|
3
|
+
def initialize(adapter, path)
|
4
|
+
@adapter, @path = adapter, path
|
5
|
+
ActiveRecord::Base.establish_connection(adapter: @adapter, database: @path)
|
6
|
+
generate_schema unless File.exists? @path
|
7
|
+
end
|
8
|
+
|
9
|
+
def generate_schema
|
10
|
+
ActiveRecord::Schema.define do
|
11
|
+
create_table :items do |t|
|
12
|
+
t.string :title, null: false
|
13
|
+
t.integer :weight, null: false, default: 1
|
14
|
+
t.boolean :done, null: false, default: false
|
15
|
+
t.boolean :archived, null: false, default: false
|
16
|
+
t.timestamps
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/goldie/item.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Goldie
|
2
|
+
class Item < ActiveRecord::Base
|
3
|
+
attr_accessible :title, :weight, :done, :archived
|
4
|
+
|
5
|
+
validates :title, presence: true
|
6
|
+
validates :weight, numericality: { only_integer: true }
|
7
|
+
|
8
|
+
scope :archived, where(archived: true)
|
9
|
+
scope :active, where(archived: false)
|
10
|
+
scope :done, where(done: true)
|
11
|
+
scope :not_done, where(done: false)
|
12
|
+
scope :latest, order("items.created_at DESC")
|
13
|
+
end
|
14
|
+
end
|
data/lib/goldie.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: goldie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy Ruten
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: sqlite3
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: activerecord
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: Goldie is a simple command line todo list with a progress bar.
|
79
|
+
email: jeremy.ruten@gmail.com
|
80
|
+
executables:
|
81
|
+
- goldie
|
82
|
+
extensions: []
|
83
|
+
extra_rdoc_files: []
|
84
|
+
files:
|
85
|
+
- Gemfile
|
86
|
+
- Gemfile.lock
|
87
|
+
- LICENSE
|
88
|
+
- goldie.gemspec
|
89
|
+
- bin/goldie
|
90
|
+
- lib/goldie/commands.rb
|
91
|
+
- lib/goldie/database.rb
|
92
|
+
- lib/goldie/item.rb
|
93
|
+
- lib/goldie.rb
|
94
|
+
homepage: http://github.com/yjerem/goldie
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.9.2
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.23
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: A todo list with a progress bar.
|
119
|
+
test_files: []
|