oughtve 110.e2f5bb28
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.
- data/.gitignore +9 -0
- data/README +115 -0
- data/Rakefile +44 -0
- data/bin/oughtve +62 -0
- data/doc/HOWTO.using +131 -0
- data/doc/LICENCE +44 -0
- data/doc/README.markdown +115 -0
- data/doc/TODO +13 -0
- data/lib/oughtve.rb +87 -0
- data/lib/oughtve/chapter.rb +93 -0
- data/lib/oughtve/database.rb +83 -0
- data/lib/oughtve/errors.rb +6 -0
- data/lib/oughtve/options.rb +193 -0
- data/lib/oughtve/tangent.rb +353 -0
- data/lib/oughtve/verse.rb +83 -0
- data/setup.rb +1360 -0
- data/spec/bootstrap_creates_db_spec.rb +38 -0
- data/spec/bootstrap_creates_default_tangent_spec.rb +40 -0
- data/spec/bootstrap_raises_if_db_exists_spec.rb +37 -0
- data/spec/chapter_spec.rb +36 -0
- data/spec/delete_spec.rb +59 -0
- data/spec/list_spec.rb +25 -0
- data/spec/scribe_spec.rb +137 -0
- data/spec/show_spec.rb +247 -0
- data/spec/spec.rb +87 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/strike_spec.rb +150 -0
- data/spec/tangent_locating_spec.rb +63 -0
- data/spec/tangent_spec.rb +211 -0
- metadata +146 -0
data/doc/TODO
ADDED
data/lib/oughtve.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# LICENCE
|
2
|
+
# =========
|
3
|
+
#
|
4
|
+
# Authors
|
5
|
+
# ---------
|
6
|
+
#
|
7
|
+
# See doc/AUTHORS.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright
|
11
|
+
# -----------
|
12
|
+
#
|
13
|
+
# Copyright (c) 2006-2010 Eero Saynatkari, all rights reserved.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Licence
|
17
|
+
# ---------
|
18
|
+
#
|
19
|
+
# Redistribution and use in source and binary forms, with or without
|
20
|
+
# modification, are permitted provided that the following conditions
|
21
|
+
# are met:
|
22
|
+
#
|
23
|
+
# - Redistributions of source code must retain the above copyright
|
24
|
+
# notice, this list of conditions, the following disclaimer and
|
25
|
+
# attribution to the original authors.
|
26
|
+
#
|
27
|
+
# - Redistributions in binary form must reproduce the above copyright
|
28
|
+
# notice, this list of conditions, the following disclaimer and
|
29
|
+
# attribution to the original authors in the documentation and/or
|
30
|
+
# other materials provided with the distribution.
|
31
|
+
#
|
32
|
+
# - The names of the authors may not be used to endorse or promote
|
33
|
+
# products derived from this software without specific prior
|
34
|
+
# written permission.
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# Disclaimer
|
38
|
+
# ------------
|
39
|
+
#
|
40
|
+
# This software is provided "as is" and without any express or
|
41
|
+
# implied warranties, including, without limitation, the implied
|
42
|
+
# warranties of merchantability and fitness for a particular purpose.
|
43
|
+
# Authors are not responsible for any damages, direct or indirect.
|
44
|
+
#
|
45
|
+
|
46
|
+
require "fileutils"
|
47
|
+
|
48
|
+
|
49
|
+
# Project
|
50
|
+
require "oughtve/errors"
|
51
|
+
require "oughtve/options"
|
52
|
+
|
53
|
+
|
54
|
+
module Oughtve
|
55
|
+
|
56
|
+
#
|
57
|
+
# Directory in which our resources are stored.
|
58
|
+
#
|
59
|
+
ResourceDirectory = File.expand_path File.join(ENV["HOME"], ".oughtve")
|
60
|
+
|
61
|
+
|
62
|
+
#
|
63
|
+
# Entry point to the library.
|
64
|
+
#
|
65
|
+
# Parses arguments and performs the requested action.
|
66
|
+
#
|
67
|
+
def self.run(arguments)
|
68
|
+
options = parse_from arguments
|
69
|
+
|
70
|
+
Database.connect and self.send options.action, options
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Bootstrap a brand new setup.
|
75
|
+
#
|
76
|
+
def self.bootstrap(*)
|
77
|
+
FileUtils.mkdir_p ResourceDirectory and Database.bootstrap
|
78
|
+
run %w[ --new --tangent default --directory / ]
|
79
|
+
|
80
|
+
"Oughtve has been set up. A default tangent has been created."
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
require "oughtve/database"
|
87
|
+
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# LICENCE
|
2
|
+
# =========
|
3
|
+
#
|
4
|
+
# Authors
|
5
|
+
# ---------
|
6
|
+
#
|
7
|
+
# See doc/AUTHORS.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright
|
11
|
+
# -----------
|
12
|
+
#
|
13
|
+
# Copyright (c) 2006-2010 Eero Saynatkari, all rights reserved.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Licence
|
17
|
+
# ---------
|
18
|
+
#
|
19
|
+
# Redistribution and use in source and binary forms, with or without
|
20
|
+
# modification, are permitted provided that the following conditions
|
21
|
+
# are met:
|
22
|
+
#
|
23
|
+
# - Redistributions of source code must retain the above copyright
|
24
|
+
# notice, this list of conditions, the following disclaimer and
|
25
|
+
# attribution to the original authors.
|
26
|
+
#
|
27
|
+
# - Redistributions in binary form must reproduce the above copyright
|
28
|
+
# notice, this list of conditions, the following disclaimer and
|
29
|
+
# attribution to the original authors in the documentation and/or
|
30
|
+
# other materials provided with the distribution.
|
31
|
+
#
|
32
|
+
# - The names of the authors may not be used to endorse or promote
|
33
|
+
# products derived from this software without specific prior
|
34
|
+
# written permission.
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# Disclaimer
|
38
|
+
# ------------
|
39
|
+
#
|
40
|
+
# This software is provided "as is" and without any express or
|
41
|
+
# implied warranties, including, without limitation, the implied
|
42
|
+
# warranties of merchantability and fitness for a particular purpose.
|
43
|
+
# Authors are not responsible for any damages, direct or indirect.
|
44
|
+
#
|
45
|
+
|
46
|
+
|
47
|
+
module Oughtve
|
48
|
+
|
49
|
+
# Forward-declare Tangent
|
50
|
+
class Tangent; end
|
51
|
+
|
52
|
+
|
53
|
+
#
|
54
|
+
# A Chapter is a (hopefully) logical section of a Tangent.
|
55
|
+
#
|
56
|
+
class Chapter
|
57
|
+
include DataMapper::Resource
|
58
|
+
|
59
|
+
# Unique identifier
|
60
|
+
property :id, Serial
|
61
|
+
|
62
|
+
# Time when closed
|
63
|
+
property :ended, Time
|
64
|
+
|
65
|
+
# Summary of what the chapter was about
|
66
|
+
property :summary, Text
|
67
|
+
|
68
|
+
|
69
|
+
has n, :verses
|
70
|
+
belongs_to :tangent
|
71
|
+
|
72
|
+
|
73
|
+
#
|
74
|
+
# Hash representation of data, including all verses.
|
75
|
+
#
|
76
|
+
def to_hash()
|
77
|
+
closed, open = verses.partition {|verse| verse.struck }
|
78
|
+
hash = {:open => open.map {|v| v.to_hash },
|
79
|
+
:closed => closed.map {|v| v.to_hash }
|
80
|
+
}
|
81
|
+
|
82
|
+
if ended
|
83
|
+
hash[:ended] = ended
|
84
|
+
hash[:summary] = summary
|
85
|
+
end
|
86
|
+
|
87
|
+
hash
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# LICENCE
|
2
|
+
# =========
|
3
|
+
#
|
4
|
+
# Authors
|
5
|
+
# ---------
|
6
|
+
#
|
7
|
+
# See doc/AUTHORS.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright
|
11
|
+
# -----------
|
12
|
+
#
|
13
|
+
# Copyright (c) 2006-2010 Eero Saynatkari, all rights reserved.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Licence
|
17
|
+
# ---------
|
18
|
+
#
|
19
|
+
# Redistribution and use in source and binary forms, with or without
|
20
|
+
# modification, are permitted provided that the following conditions
|
21
|
+
# are met:
|
22
|
+
#
|
23
|
+
# - Redistributions of source code must retain the above copyright
|
24
|
+
# notice, this list of conditions, the following disclaimer and
|
25
|
+
# attribution to the original authors.
|
26
|
+
#
|
27
|
+
# - Redistributions in binary form must reproduce the above copyright
|
28
|
+
# notice, this list of conditions, the following disclaimer and
|
29
|
+
# attribution to the original authors in the documentation and/or
|
30
|
+
# other materials provided with the distribution.
|
31
|
+
#
|
32
|
+
# - The names of the authors may not be used to endorse or promote
|
33
|
+
# products derived from this software without specific prior
|
34
|
+
# written permission.
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# Disclaimer
|
38
|
+
# ------------
|
39
|
+
#
|
40
|
+
# This software is provided "as is" and without any express or
|
41
|
+
# implied warranties, including, without limitation, the implied
|
42
|
+
# warranties of merchantability and fitness for a particular purpose.
|
43
|
+
# Authors are not responsible for any damages, direct or indirect.
|
44
|
+
#
|
45
|
+
|
46
|
+
require "rubygems"
|
47
|
+
require "dm-core"
|
48
|
+
|
49
|
+
require "oughtve/tangent"
|
50
|
+
require "oughtve/chapter"
|
51
|
+
require "oughtve/verse"
|
52
|
+
|
53
|
+
|
54
|
+
module Oughtve
|
55
|
+
|
56
|
+
module Database
|
57
|
+
|
58
|
+
# The database file path.
|
59
|
+
Path = File.expand_path "#{Oughtve::ResourceDirectory}/data.db"
|
60
|
+
|
61
|
+
# The full URI to access the DB.
|
62
|
+
URI = "sqlite3:///#{Path}"
|
63
|
+
|
64
|
+
|
65
|
+
#
|
66
|
+
# Connect to database (new or existing)
|
67
|
+
#
|
68
|
+
def self.connect()
|
69
|
+
DataMapper::Logger.new(STDOUT, :debug) if $VERBOSE
|
70
|
+
DataMapper.setup :default, URI
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# Create a brand-new database.
|
75
|
+
#
|
76
|
+
def self.bootstrap()
|
77
|
+
raise OughtveError, "#{Path} already exists!" if File.exist? Path
|
78
|
+
connect and DataMapper.auto_migrate!
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
@@ -0,0 +1,193 @@
|
|
1
|
+
# LICENCE
|
2
|
+
# =========
|
3
|
+
#
|
4
|
+
# Authors
|
5
|
+
# ---------
|
6
|
+
#
|
7
|
+
# See doc/AUTHORS.
|
8
|
+
#
|
9
|
+
#
|
10
|
+
# Copyright
|
11
|
+
# -----------
|
12
|
+
#
|
13
|
+
# Copyright (c) 2006-2010 Eero Saynatkari, all rights reserved.
|
14
|
+
#
|
15
|
+
#
|
16
|
+
# Licence
|
17
|
+
# ---------
|
18
|
+
#
|
19
|
+
# Redistribution and use in source and binary forms, with or without
|
20
|
+
# modification, are permitted provided that the following conditions
|
21
|
+
# are met:
|
22
|
+
#
|
23
|
+
# - Redistributions of source code must retain the above copyright
|
24
|
+
# notice, this list of conditions, the following disclaimer and
|
25
|
+
# attribution to the original authors.
|
26
|
+
#
|
27
|
+
# - Redistributions in binary form must reproduce the above copyright
|
28
|
+
# notice, this list of conditions, the following disclaimer and
|
29
|
+
# attribution to the original authors in the documentation and/or
|
30
|
+
# other materials provided with the distribution.
|
31
|
+
#
|
32
|
+
# - The names of the authors may not be used to endorse or promote
|
33
|
+
# products derived from this software without specific prior
|
34
|
+
# written permission.
|
35
|
+
#
|
36
|
+
#
|
37
|
+
# Disclaimer
|
38
|
+
# ------------
|
39
|
+
#
|
40
|
+
# This software is provided "as is" and without any express or
|
41
|
+
# implied warranties, including, without limitation, the implied
|
42
|
+
# warranties of merchantability and fitness for a particular purpose.
|
43
|
+
# Authors are not responsible for any damages, direct or indirect.
|
44
|
+
#
|
45
|
+
|
46
|
+
require "optparse"
|
47
|
+
require "ostruct"
|
48
|
+
|
49
|
+
|
50
|
+
module Oughtve
|
51
|
+
|
52
|
+
#
|
53
|
+
# Parse allowed options from given arguments
|
54
|
+
#
|
55
|
+
def self.parse_from(arguments)
|
56
|
+
result = OpenStruct.new
|
57
|
+
|
58
|
+
# Grab time here to be a bit closer to true
|
59
|
+
result.time = Time.now
|
60
|
+
|
61
|
+
def result.action!(given)
|
62
|
+
raise ArgumentError, "Two actions given: 1) --#{action}, 2) --#{given}" if action
|
63
|
+
self.action = given
|
64
|
+
end
|
65
|
+
|
66
|
+
OptionParser.new do |opts|
|
67
|
+
|
68
|
+
opts.banner = "Usage: #{$0} [--ACTION [OPTIONS]]"
|
69
|
+
|
70
|
+
opts.separator ""
|
71
|
+
opts.separator " Actions:"
|
72
|
+
|
73
|
+
|
74
|
+
# Actions
|
75
|
+
|
76
|
+
opts.on "-s", "--scribe [TEXT]", "Enter a new note." do |text|
|
77
|
+
result.action! :scribe
|
78
|
+
result.text = text
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on "-S", "--strike [ID_OR_REGEXP]", "Strike out a note." do |id_or_regexp|
|
82
|
+
result.action! :strike
|
83
|
+
|
84
|
+
if id_or_regexp
|
85
|
+
begin
|
86
|
+
result.serial = Integer(id_or_regexp)
|
87
|
+
rescue ArgumentError
|
88
|
+
result.regexp = /#{Regexp.escape id_or_regexp}/
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
opts.on "-w", "--show [all | old]", "Show notes for tangent(s). [All notes / old chapters too]" do |specifier|
|
94
|
+
result.action! :show
|
95
|
+
|
96
|
+
if specifier
|
97
|
+
case specifier
|
98
|
+
when "all"
|
99
|
+
result.all = true
|
100
|
+
when "old"
|
101
|
+
result.all = true
|
102
|
+
result.old = true
|
103
|
+
else
|
104
|
+
raise ArgumentError, "--show #{specifier} is not a valid option!"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
opts.on "-l", "--list", "Show defined Tangents and their base directories." do
|
110
|
+
result.action! :list
|
111
|
+
end
|
112
|
+
|
113
|
+
opts.on "-c", "--chapter ENDNOTE", "Mark end of chapter and start new one." do |endnote|
|
114
|
+
result.action! :chapter
|
115
|
+
result.endnote = endnote
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# Options
|
120
|
+
opts.separator ""
|
121
|
+
opts.separator " Maintenance Actions:"
|
122
|
+
|
123
|
+
opts.on "-b", "--bootstrap", "Set up database and initial structures." do
|
124
|
+
result.action! :bootstrap
|
125
|
+
end
|
126
|
+
|
127
|
+
opts.on "-n", "--new", "Create new Tangent. (Use -t to give it a name.)" do
|
128
|
+
result.action! :tangent
|
129
|
+
end
|
130
|
+
|
131
|
+
opts.on "-D", "--delete [NAME]", "Delete tangent." do |name|
|
132
|
+
result.action! :delete
|
133
|
+
result.name = name
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
# Options
|
138
|
+
opts.separator ""
|
139
|
+
opts.separator " Options:"
|
140
|
+
|
141
|
+
opts.on "-d", "--directory DIR", "Use given directory instead of Dir.pwd." do |dir|
|
142
|
+
result.dir = dir
|
143
|
+
end
|
144
|
+
|
145
|
+
opts.on "-i", "--id ID", "Use specific note ID." do |id|
|
146
|
+
result.serial = id
|
147
|
+
end
|
148
|
+
|
149
|
+
opts.on "-m", "--match REGEXP", "Match note using regexp, specific branch only." do |regexp|
|
150
|
+
result.regexp = /#{Regexp.escape regexp}/
|
151
|
+
end
|
152
|
+
|
153
|
+
opts.on "-t", "--tangent NAME", "Use named Tangent specifically." do |name|
|
154
|
+
result.name = name
|
155
|
+
end
|
156
|
+
|
157
|
+
opts.on "-x", "--text TEXT", "Text to use for note." do |text|
|
158
|
+
result.text = text
|
159
|
+
end
|
160
|
+
|
161
|
+
opts.on "-v", "--verbose", "Give extra information for some actions." do
|
162
|
+
result.verbose = true
|
163
|
+
end
|
164
|
+
|
165
|
+
opts.on "-J", "--json", "JSON output" do
|
166
|
+
result.format = :json
|
167
|
+
end
|
168
|
+
|
169
|
+
opts.on "-Y", "--yaml", "YAML output" do
|
170
|
+
result.format = :yaml
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
# Bookkeeping stuff
|
175
|
+
|
176
|
+
opts.on_tail "-h", "--help", "Display this message." do
|
177
|
+
puts opts
|
178
|
+
exit!
|
179
|
+
end
|
180
|
+
|
181
|
+
end.parse! arguments
|
182
|
+
|
183
|
+
rescue OptionParser::InvalidOption => e
|
184
|
+
$stderr.print "\n#{e.message}\n\n"
|
185
|
+
parse_from %w[ -h ]
|
186
|
+
|
187
|
+
else
|
188
|
+
result.rest = arguments
|
189
|
+
result.action = :scribe unless result.action
|
190
|
+
result
|
191
|
+
end
|
192
|
+
|
193
|
+
end
|