boom 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.markdown +7 -0
- data/bin/boom +1 -2
- data/boom.gemspec +2 -2
- data/lib/boom.rb +5 -1
- data/lib/boom/command.rb +24 -15
- data/lib/boom/list.rb +29 -1
- data/lib/boom/storage.rb +1 -1
- data/test/helper.rb +4 -17
- data/test/test_command.rb +7 -4
- data/test/test_list.rb +17 -0
- metadata +4 -4
data/Readme.markdown
CHANGED
@@ -81,6 +81,13 @@ can have multiple lists.
|
|
81
81
|
blog: http://zachholman.com
|
82
82
|
github: https://github.com
|
83
83
|
|
84
|
+
** Manual edit **
|
85
|
+
|
86
|
+
If you want to edit the underlying JSON directly, make sure your `$EDITOR`
|
87
|
+
environment variable is set, and run:
|
88
|
+
|
89
|
+
$ boom edit
|
90
|
+
|
84
91
|
** It's just the command line, silly **
|
85
92
|
|
86
93
|
So don't forget all your other favorites are there to help you, too:
|
data/bin/boom
CHANGED
data/boom.gemspec
CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
14
14
|
## the sub! line in the Rakefile
|
15
15
|
s.name = 'boom'
|
16
|
-
s.version = '0.0.
|
17
|
-
s.date = '2010-11-
|
16
|
+
s.version = '0.0.3'
|
17
|
+
s.date = '2010-11-28'
|
18
18
|
s.rubyforge_project = 'boom'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
data/lib/boom.rb
CHANGED
data/lib/boom/command.rb
CHANGED
@@ -10,18 +10,18 @@ module Boom
|
|
10
10
|
class Command
|
11
11
|
class << self
|
12
12
|
|
13
|
-
|
13
|
+
# Public: accesses the in-memory JSON representation.
|
14
|
+
#
|
15
|
+
# Returns a Storage instance.
|
16
|
+
def storage
|
17
|
+
Boom.storage
|
18
|
+
end
|
14
19
|
|
15
20
|
# Public: executes a command.
|
16
21
|
#
|
17
|
-
# storage - The Storage instance off which to run commands. This is
|
18
|
-
# likely just Boom::Storage.new, since Boom::Storage should
|
19
|
-
# pick up the appropriate JSON file paths on its own.
|
20
22
|
# args - The actual commands to operate on. Can be as few as zero
|
21
23
|
# arguments or as many as three.
|
22
|
-
def execute(
|
23
|
-
@storage = storage
|
24
|
-
|
24
|
+
def execute(*args)
|
25
25
|
command = args[0]
|
26
26
|
major = args[1]
|
27
27
|
minor = args[2]
|
@@ -67,7 +67,8 @@ module Boom
|
|
67
67
|
#
|
68
68
|
# Returns output based on method calls.
|
69
69
|
def delegate(command, major, minor)
|
70
|
-
return all
|
70
|
+
return all if command == 'all'
|
71
|
+
return edit if command == 'edit'
|
71
72
|
|
72
73
|
# if we're operating on a List
|
73
74
|
if storage.list_exists?(command)
|
@@ -90,11 +91,11 @@ module Boom
|
|
90
91
|
|
91
92
|
# Public: prints all Items over a List.
|
92
93
|
#
|
93
|
-
#
|
94
|
+
# name - the List object to iterate over
|
94
95
|
#
|
95
96
|
# Returns nothing.
|
96
|
-
def list_detail(
|
97
|
-
list =
|
97
|
+
def list_detail(name)
|
98
|
+
list = List.find(name)
|
98
99
|
list.items.sort{ |x,y| x.name <=> y.name }.each do |item|
|
99
100
|
output " #{item.name}: #{item.value}"
|
100
101
|
end
|
@@ -126,10 +127,9 @@ module Boom
|
|
126
127
|
#
|
127
128
|
# Returns nothing.
|
128
129
|
def list_delete(name)
|
129
|
-
lists = storage.lists.reverse.reject { |list| list.name == name }
|
130
130
|
output "You sure you want to delete everything in \"#{name}\"? (y/n):"
|
131
131
|
if $stdin.gets.chomp == 'y'
|
132
|
-
|
132
|
+
List.delete(name)
|
133
133
|
output "Boom! Deleted all your #{name}."
|
134
134
|
save!
|
135
135
|
else
|
@@ -149,7 +149,7 @@ module Boom
|
|
149
149
|
#
|
150
150
|
# Returns the newly created Item.
|
151
151
|
def add_item(list,name,value)
|
152
|
-
list =
|
152
|
+
list = List.find(list)
|
153
153
|
list.add_item(Item.new(name,value))
|
154
154
|
output "Boom! \"#{name}\" in \"#{list.name}\" is \"#{value}\". Got it."
|
155
155
|
save!
|
@@ -194,7 +194,7 @@ module Boom
|
|
194
194
|
#
|
195
195
|
# Returns the matching Item.
|
196
196
|
def search_list_for_item(list_name, item_name)
|
197
|
-
list =
|
197
|
+
list = List.find(list_name)
|
198
198
|
item = list.items.first { |item| item.name == item_name }
|
199
199
|
|
200
200
|
output Clipboard.copy(item)
|
@@ -207,6 +207,15 @@ module Boom
|
|
207
207
|
storage.save!
|
208
208
|
end
|
209
209
|
|
210
|
+
# Public: launches JSON file in an editor for you to edit manually. Uses
|
211
|
+
# the $EDITOR environment variable for editing.
|
212
|
+
#
|
213
|
+
# Returns nothing.
|
214
|
+
def edit
|
215
|
+
system "`echo $EDITOR` #{storage.json_file} &"
|
216
|
+
output "Boom! Make your edits, and do be sure to save."
|
217
|
+
end
|
218
|
+
|
210
219
|
end
|
211
220
|
end
|
212
221
|
end
|
data/lib/boom/list.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
# individual Items. The relationship is maintained in a simple array on the
|
3
3
|
# List-level.
|
4
4
|
#
|
5
|
-
module Boom
|
5
|
+
module Boom
|
6
|
+
class List
|
6
7
|
|
7
8
|
# Public: creates a new List instance in-memory.
|
8
9
|
#
|
@@ -14,6 +15,13 @@ module Boom class List
|
|
14
15
|
@name = name
|
15
16
|
end
|
16
17
|
|
18
|
+
# Public: accesses the in-memory JSON representation.
|
19
|
+
#
|
20
|
+
# Returns a Storage instance.
|
21
|
+
def self.storage
|
22
|
+
Boom.storage
|
23
|
+
end
|
24
|
+
|
17
25
|
# Public: lets you access the array of items contained within this List.
|
18
26
|
#
|
19
27
|
# Returns an Array of Items.
|
@@ -33,6 +41,26 @@ module Boom class List
|
|
33
41
|
@items << item
|
34
42
|
end
|
35
43
|
|
44
|
+
# Public: finds any given List by name.
|
45
|
+
#
|
46
|
+
# name - String name of the list to search for
|
47
|
+
#
|
48
|
+
# Returns the first instance of List that it finds.
|
49
|
+
def self.find(name)
|
50
|
+
storage.lists.find { |list| list.name == name }
|
51
|
+
end
|
52
|
+
|
53
|
+
# Public: deletes a List by name.
|
54
|
+
#
|
55
|
+
# name - String name of the list to delete
|
56
|
+
#
|
57
|
+
# Returns whether one or more lists were removed.
|
58
|
+
def self.delete(name)
|
59
|
+
previous = storage.lists.size
|
60
|
+
storage.lists = storage.lists.reject { |list| list.name == name }
|
61
|
+
previous != storage.lists.size
|
62
|
+
end
|
63
|
+
|
36
64
|
# Public: a Hash representation of this List.
|
37
65
|
#
|
38
66
|
# Returns a Hash of its own data and its child Items.
|
data/lib/boom/storage.rb
CHANGED
@@ -75,7 +75,7 @@ module Boom
|
|
75
75
|
#
|
76
76
|
# Returns a String JSON representation of its Lists and their Items.
|
77
77
|
def to_json
|
78
|
-
Yajl::Encoder.encode(to_hash)
|
78
|
+
Yajl::Encoder.encode(to_hash, :pretty => true)
|
79
79
|
end
|
80
80
|
|
81
81
|
# Public: creates a Hash of the representation of the in-memory data
|
data/test/helper.rb
CHANGED
@@ -13,21 +13,8 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
13
13
|
|
14
14
|
require 'boom'
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
def context(*args, &block)
|
21
|
-
return super unless (name = args.first) && block
|
22
|
-
require 'test/unit'
|
23
|
-
klass = Class.new(defined?(ActiveSupport::TestCase) ? ActiveSupport::TestCase : Test::Unit::TestCase) do
|
24
|
-
def self.test(name, &block)
|
25
|
-
define_method("test_#{name.gsub(/\W/,'_')}", &block) if block
|
26
|
-
end
|
27
|
-
def self.xtest(*args) end
|
28
|
-
def self.setup(&block) define_method(:setup, &block) end
|
29
|
-
def self.teardown(&block) define_method(:teardown, &block) end
|
30
|
-
end
|
31
|
-
(class << klass; self end).send(:define_method, :name) { name.gsub(/\W/,'_') }
|
32
|
-
klass.class_eval &block
|
16
|
+
def boom_json(name)
|
17
|
+
Boom::Storage.any_instance.stubs(:json_file).
|
18
|
+
returns("test/examples/#{name}.json")
|
19
|
+
Boom.stubs(:storage).returns(Boom::Storage.new)
|
33
20
|
end
|
data/test/test_command.rb
CHANGED
@@ -24,15 +24,13 @@ end
|
|
24
24
|
class TestCommand < Test::Unit::TestCase
|
25
25
|
|
26
26
|
def setup
|
27
|
-
|
28
|
-
returns('test/examples/urls.json')
|
29
|
-
@storage = Boom::Storage.new
|
27
|
+
boom_json :urls
|
30
28
|
end
|
31
29
|
|
32
30
|
def command(cmd)
|
33
31
|
cmd = cmd.split(' ') if cmd
|
34
32
|
Boom::Command.capture_output
|
35
|
-
Boom::Command.execute(
|
33
|
+
Boom::Command.execute(*cmd)
|
36
34
|
Boom::Command.captured_output
|
37
35
|
end
|
38
36
|
|
@@ -82,4 +80,9 @@ class TestCommand < Test::Unit::TestCase
|
|
82
80
|
def test_item_deletion
|
83
81
|
assert_match /"github" is gone forever/, command('urls github delete')
|
84
82
|
end
|
83
|
+
|
84
|
+
def test_edit
|
85
|
+
Boom::Command.stubs(:system).returns('')
|
86
|
+
assert_match 'Make your edits', command('edit')
|
87
|
+
end
|
85
88
|
end
|
data/test/test_list.rb
CHANGED
@@ -5,6 +5,7 @@ class TestList < Test::Unit::TestCase
|
|
5
5
|
def setup
|
6
6
|
@list = Boom::List.new('urls')
|
7
7
|
@item = Boom::Item.new('github','https://github.com')
|
8
|
+
boom_json :urls
|
8
9
|
end
|
9
10
|
|
10
11
|
def test_name
|
@@ -23,4 +24,20 @@ class TestList < Test::Unit::TestCase
|
|
23
24
|
assert_equal 1, @list.to_hash[@list.name].size
|
24
25
|
end
|
25
26
|
|
27
|
+
def test_find
|
28
|
+
assert_equal 'urls', Boom::List.find('urls').name
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_delete_success
|
32
|
+
assert_equal 1, Boom.storage.lists.size
|
33
|
+
assert Boom::List.delete('urls')
|
34
|
+
assert_equal 0, Boom.storage.lists.size
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_delete_fail
|
38
|
+
assert_equal 1, Boom.storage.lists.size
|
39
|
+
assert !Boom::List.delete('robocop')
|
40
|
+
assert_equal 1, Boom.storage.lists.size
|
41
|
+
end
|
42
|
+
|
26
43
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: boom
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Zach Holman
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-28 00:00:00 -08:00
|
19
19
|
default_executable: boom
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|