boom 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +3 -1
- data/Gemfile.lock +1 -1
- data/Rakefile +0 -16
- data/boom.gemspec +2 -3
- data/completion/boom.bash +11 -17
- data/lib/boom/color.rb +7 -1
- data/lib/boom/command.rb +19 -8
- data/lib/boom/platform.rb +11 -11
- data/lib/boom/storage/gist.rb +0 -2
- data/lib/boom/storage/keychain.rb +12 -6
- data/lib/boom/storage/redis.rb +7 -2
- data/lib/boom.rb +1 -1
- data/test/test_color.rb +6 -2
- data/test/test_command.rb +26 -0
- data/test/test_platform.rb +37 -0
- metadata +4 -5
- data/lib/boom/storage/gist/json_parser.rb +0 -8
data/CHANGELOG.markdown
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# boom changes
|
2
|
-
|
3
2
|
## head
|
3
|
+
- [@Dlom](https://github.com/Dlom) fixed some troubles in #49.
|
4
|
+
- Some additional test coverage added by
|
5
|
+
[@nickhammond](https://github.com/nickhammond).
|
4
6
|
|
5
7
|
## 0.2.3
|
6
8
|
- [@culvr](https://github.com/culvr) added `boom random <list>` that lets you
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -52,22 +52,6 @@ Rake::TestTask.new(:test) do |test|
|
|
52
52
|
test.verbose = true
|
53
53
|
end
|
54
54
|
|
55
|
-
desc "Generate RCov test coverage and open in your browser"
|
56
|
-
task :coverage do
|
57
|
-
require 'rcov'
|
58
|
-
sh "rm -fr coverage"
|
59
|
-
sh "rcov test/test_*.rb"
|
60
|
-
sh "open coverage/index.html"
|
61
|
-
end
|
62
|
-
|
63
|
-
require 'rake/rdoctask'
|
64
|
-
Rake::RDocTask.new do |rdoc|
|
65
|
-
rdoc.rdoc_dir = 'rdoc'
|
66
|
-
rdoc.title = "#{name} #{version}"
|
67
|
-
rdoc.rdoc_files.include('README*')
|
68
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
-
end
|
70
|
-
|
71
55
|
desc "Open an irb session preloaded with this library"
|
72
56
|
task :console do
|
73
57
|
sh "irb -rubygems -r ./lib/#{name}.rb"
|
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.2.
|
17
|
-
s.date = '
|
16
|
+
s.version = '0.2.4'
|
17
|
+
s.date = '2013-03-15'
|
18
18
|
s.rubyforge_project = 'boom'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -89,7 +89,6 @@ Gem::Specification.new do |s|
|
|
89
89
|
lib/boom/storage.rb
|
90
90
|
lib/boom/storage/base.rb
|
91
91
|
lib/boom/storage/gist.rb
|
92
|
-
lib/boom/storage/gist/json_parser.rb
|
93
92
|
lib/boom/storage/json.rb
|
94
93
|
lib/boom/storage/keychain.rb
|
95
94
|
lib/boom/storage/mongodb.rb
|
data/completion/boom.bash
CHANGED
@@ -1,23 +1,17 @@
|
|
1
1
|
_boom_complete() {
|
2
|
-
local cur prev lists
|
2
|
+
local cur prev lists curr_list items
|
3
3
|
COMPREPLY=()
|
4
4
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
5
5
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
6
|
+
curr_list=`eval echo "$prev"`
|
7
|
+
local IFS=$'\n'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
*)
|
15
|
-
for ((i = 0; i < ${#lists}; i++)); do
|
16
|
-
local items=`boom $prev | awk '{print $1}' | sed -e 's/://'`
|
17
|
-
COMPREPLY=( $(compgen -W "${items}" -- ${cur}))
|
18
|
-
return 0
|
19
|
-
done
|
20
|
-
;;
|
21
|
-
esac
|
9
|
+
if [ $COMP_CWORD -eq 1 ]; then
|
10
|
+
lists=`boom | sed 's/^ \(.*\) ([0-9]\+)$/\1/'`
|
11
|
+
COMPREPLY=( $( compgen -W '${lists}' -- ${cur} ) )
|
12
|
+
elif [ $COMP_CWORD -eq 2 ]; then
|
13
|
+
items=`boom $curr_list | sed 's/^ \(.\{0,16\}\):.*$/\1/'`
|
14
|
+
COMPREPLY=( $( compgen -W '${items}' -- ${cur} ) )
|
15
|
+
fi
|
22
16
|
}
|
23
|
-
complete -F _boom_complete boom
|
17
|
+
complete -o filenames -F _boom_complete boom
|
data/lib/boom/color.rb
CHANGED
@@ -33,8 +33,14 @@ module Boom
|
|
33
33
|
# colorize("Boom!", :magenta)
|
34
34
|
# # => "\e[35mBoom!\e[0m"
|
35
35
|
#
|
36
|
-
# Returns the wrapped String
|
36
|
+
# Returns the wrapped String unless the the platform is windows and
|
37
|
+
# does not have Win32::Console, in which case, returns the String.
|
37
38
|
def colorize(string, color_code)
|
39
|
+
if !defined?(Win32::Console) && !!(RUBY_PLATFORM =~ /win32/ || RUBY_PLATFORM =~ /mingw32/)
|
40
|
+
# looks like this person doesn't have Win32::Console and is on windows
|
41
|
+
# just return the uncolorized string
|
42
|
+
return string
|
43
|
+
end
|
38
44
|
"#{CODES[color_code] || color_code}#{string}#{CODES[:reset]}"
|
39
45
|
end
|
40
46
|
|
data/lib/boom/command.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
# Command is the main point of entry for boom commands; shell arguments are
|
4
|
-
# passd through to Command, which then filters and parses through
|
4
|
+
# passd through to Command, which then filters and parses through individual
|
5
5
|
# commands and reroutes them to constituent object classes.
|
6
6
|
#
|
7
7
|
# Command also keeps track of one connection to Storage, which is how new data
|
@@ -108,12 +108,12 @@ module Boom
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
return search_items(command) if storage.item_exists?(command)
|
112
|
-
|
113
111
|
if minor == 'delete' and storage.item_exists?(major)
|
114
112
|
return delete_item(command, major)
|
115
113
|
end
|
116
114
|
|
115
|
+
return search_items(command) if storage.item_exists?(command) and !major
|
116
|
+
|
117
117
|
return create_list(command, major, stdin.read) if !minor && stdin.stat.size > 0
|
118
118
|
return create_list(command, major, minor)
|
119
119
|
end
|
@@ -273,10 +273,17 @@ module Boom
|
|
273
273
|
#
|
274
274
|
# Returns nothing.
|
275
275
|
def delete_item(list_name,name)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
276
|
+
if storage.list_exists?(list_name)
|
277
|
+
list = List.find(list_name)
|
278
|
+
if list.delete_item(name)
|
279
|
+
output "#{cyan("Boom!")} #{yellow(name)} is gone forever."
|
280
|
+
save
|
281
|
+
else
|
282
|
+
output "#{yellow(name)} #{red("not found in")} #{yellow(list_name)}"
|
283
|
+
end
|
284
|
+
else
|
285
|
+
output "We couldn't find that list."
|
286
|
+
end
|
280
287
|
end
|
281
288
|
|
282
289
|
# Public: search for an Item in all lists by name. Drops the
|
@@ -329,7 +336,11 @@ module Boom
|
|
329
336
|
#
|
330
337
|
# Returns nothing.
|
331
338
|
def edit
|
332
|
-
|
339
|
+
if storage.respond_to?("json_file")
|
340
|
+
output "#{cyan("Boom!")} #{Platform.edit(storage.json_file)}"
|
341
|
+
else
|
342
|
+
output "This storage backend does not store #{cyan("Boom!")} data on your computer"
|
343
|
+
end
|
333
344
|
end
|
334
345
|
|
335
346
|
# Public: prints all the commands of boom.
|
data/lib/boom/platform.rb
CHANGED
@@ -48,9 +48,9 @@ module Boom
|
|
48
48
|
# Returns a String of the Item value.
|
49
49
|
def open(item)
|
50
50
|
unless windows?
|
51
|
-
system("#{open_command} '#{item.url.gsub("\'","
|
51
|
+
system("#{open_command} '#{item.url.gsub("\'","'\\\\''")}'")
|
52
52
|
else
|
53
|
-
system("#{open_command} #{item.url.gsub("\'","
|
53
|
+
system("#{open_command} #{item.url.gsub("\'","'\\\\''")}")
|
54
54
|
end
|
55
55
|
|
56
56
|
item.value
|
@@ -75,25 +75,25 @@ module Boom
|
|
75
75
|
#
|
76
76
|
# Returns the String value of the Item.
|
77
77
|
def copy(item)
|
78
|
-
|
79
|
-
system("printf '#{item.value.gsub("\'","\\'")}' | #{copy_command}")
|
80
|
-
else
|
81
|
-
system("echo #{item.value.gsub("\'","\\'")} | #{copy_command}")
|
82
|
-
end
|
83
|
-
|
78
|
+
IO.popen(copy_command,"w") {|cc| cc.write(item.value)}
|
84
79
|
item.value
|
85
80
|
end
|
86
81
|
|
87
82
|
# Public: opens the JSON file in an editor for you to edit. Uses the
|
88
83
|
# $EDITOR environment variable, or %EDITOR% on Windows for editing.
|
89
84
|
# This method is designed to handle multiple platforms.
|
85
|
+
# If $EDITOR is nil, try to open using the open_command.
|
90
86
|
#
|
91
87
|
# Returns a String with a helpful message.
|
92
88
|
def edit(json_file)
|
93
|
-
unless
|
94
|
-
|
89
|
+
unless $EDITOR.nil?
|
90
|
+
unless windows?
|
91
|
+
system("`echo $EDITOR` #{json_file} &")
|
92
|
+
else
|
93
|
+
system("start %EDITOR% #{json_file}")
|
94
|
+
end
|
95
95
|
else
|
96
|
-
system("
|
96
|
+
system("#{open_command} #{json_file}")
|
97
97
|
end
|
98
98
|
|
99
99
|
"Make your edits, and do be sure to save."
|
data/lib/boom/storage/gist.rb
CHANGED
@@ -29,10 +29,8 @@ module Boom
|
|
29
29
|
def bootstrap
|
30
30
|
begin
|
31
31
|
require "httparty"
|
32
|
-
require "boom/storage/gist/json_parser"
|
33
32
|
|
34
33
|
self.class.send(:include, HTTParty)
|
35
|
-
self.class.parser JsonParser
|
36
34
|
self.class.base_uri "https://api.github.com"
|
37
35
|
rescue LoadError
|
38
36
|
puts "The Gist backend requires HTTParty: gem install httparty"
|
@@ -19,15 +19,21 @@ module Boom
|
|
19
19
|
|
20
20
|
alias_method :json_file, :open_keychain_app
|
21
21
|
|
22
|
-
# Boostraps Keychain by
|
22
|
+
# Boostraps Keychain by checking if you're using a Mac which is a prereq
|
23
23
|
#
|
24
|
-
# Returns
|
24
|
+
# Returns
|
25
25
|
def bootstrap
|
26
|
-
raise RuntimeError unless
|
27
|
-
true
|
26
|
+
raise RuntimeError unless is_mac?
|
28
27
|
rescue
|
29
|
-
puts(
|
30
|
-
|
28
|
+
puts('No Keychain utility to access, maybe try another storage option?')
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
# Asks if you're using Mac OS X
|
33
|
+
#
|
34
|
+
# Returns true on a Mac
|
35
|
+
def is_mac?
|
36
|
+
return Boom::Platform.darwin?
|
31
37
|
end
|
32
38
|
|
33
39
|
# Populate the in-memory store with all the lists and items from Keychain
|
data/lib/boom/storage/redis.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
begin
|
6
6
|
require 'digest'
|
7
7
|
require 'redis'
|
8
|
+
require 'uri'
|
8
9
|
rescue LoadError
|
9
10
|
end
|
10
11
|
|
@@ -13,8 +14,12 @@ module Boom
|
|
13
14
|
class Redis < Base
|
14
15
|
|
15
16
|
def redis
|
16
|
-
|
17
|
-
|
17
|
+
uri = URI.parse(Boom.config.attributes['uri'] || '')
|
18
|
+
|
19
|
+
@redis ||= ::Redis.new :host => (uri.host || Boom.config.attributes["redis"]["host"]),
|
20
|
+
:port => (uri.port || Boom.config.attributes["redis"]["port"]),
|
21
|
+
:user => (uri.user || Boom.config.attributes["redis"]["user"]),
|
22
|
+
:password => (uri.password || Boom.config.attributes["redis"]["password"])
|
18
23
|
rescue NameError => e
|
19
24
|
puts "You don't have Redis installed yet:\n gem install redis"
|
20
25
|
exit
|
data/lib/boom.rb
CHANGED
data/test/test_color.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
1
|
require 'helper'
|
4
2
|
|
5
3
|
class TestColor < Test::Unit::TestCase
|
@@ -23,4 +21,10 @@ class TestColor < Test::Unit::TestCase
|
|
23
21
|
assert_equal "\e[33mYellow!\e[0m",
|
24
22
|
Boom::Color.yellow("Yellow!")
|
25
23
|
end
|
24
|
+
|
25
|
+
def test_cyan
|
26
|
+
assert_equal "\e[36mCyan!\e[0m",
|
27
|
+
Boom::Color.cyan("Cyan!")
|
28
|
+
end
|
29
|
+
|
26
30
|
end
|
data/test/test_command.rb
CHANGED
@@ -74,12 +74,19 @@ class TestCommand < Test::Unit::TestCase
|
|
74
74
|
assert_match /a new list called newlist.* item in newlist is blah/, command('newlist item')
|
75
75
|
end
|
76
76
|
|
77
|
+
def test_list_creation_with_existing_items_name
|
78
|
+
command('list item foo')
|
79
|
+
assert_match /a new list called item.* key in item is bar/, command('item key bar')
|
80
|
+
end
|
81
|
+
|
77
82
|
def test_item_access
|
83
|
+
IO.stubs(:popen)
|
78
84
|
assert_match /copied https:\/\/github\.com to your clipboard/,
|
79
85
|
command('github')
|
80
86
|
end
|
81
87
|
|
82
88
|
def test_item_access_scoped_by_list
|
89
|
+
IO.stubs(:popen)
|
83
90
|
assert_match /copied https:\/\/github\.com to your clipboard/,
|
84
91
|
command('urls github')
|
85
92
|
end
|
@@ -209,4 +216,23 @@ class TestCommand < Test::Unit::TestCase
|
|
209
216
|
assert_match /couldn't find that list\./, command('random 39jc02jlskjbbac9')
|
210
217
|
end
|
211
218
|
|
219
|
+
def test_delete_item_list_not_exist
|
220
|
+
assert_match /couldn't find that list\./, command('urlz github delete')
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_delete_item_wrong_list
|
224
|
+
command('urlz twitter https://twitter.com/')
|
225
|
+
assert_match /github not found in urlz/, command('urlz github delete')
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_delete_item_different_name
|
229
|
+
command('foo bar baz')
|
230
|
+
assert_match /bar is gone forever/, command('foo bar delete')
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_delete_item_same_name
|
234
|
+
command('duck duck goose')
|
235
|
+
assert_match /duck is gone forever/, command('duck duck delete')
|
236
|
+
end
|
237
|
+
|
212
238
|
end
|
data/test/test_platform.rb
CHANGED
@@ -3,6 +3,7 @@ require 'helper'
|
|
3
3
|
class TestPlatform < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def setup
|
6
|
+
|
6
7
|
end
|
7
8
|
|
8
9
|
def test_darwin
|
@@ -12,4 +13,40 @@ class TestPlatform < Test::Unit::TestCase
|
|
12
13
|
def test_windows
|
13
14
|
assert_equal Boom::Platform.windows?, true if RUBY_PLATFORM =~ /mswin|mingw/
|
14
15
|
end
|
16
|
+
|
17
|
+
def test_open_command_darwin
|
18
|
+
Boom::Platform.stubs(:darwin?).returns(true)
|
19
|
+
assert_equal Boom::Platform.open_command, 'open'
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_open_command_windows
|
23
|
+
Boom::Platform.stubs(:darwin?).returns(false)
|
24
|
+
Boom::Platform.stubs(:windows?).returns(true)
|
25
|
+
assert_equal Boom::Platform.open_command, 'start'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_open_command_linux
|
29
|
+
Boom::Platform.stubs(:darwin?).returns(false)
|
30
|
+
Boom::Platform.stubs(:windows?).returns(false)
|
31
|
+
assert_equal Boom::Platform.open_command, 'xdg-open'
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_copy_command_darwin
|
35
|
+
Boom::Platform.stubs(:darwin?).returns(true)
|
36
|
+
Boom::Platform.stubs(:windows?).returns(false)
|
37
|
+
assert_equal Boom::Platform.copy_command, 'pbcopy'
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_copy_command_windows
|
41
|
+
Boom::Platform.stubs(:darwin?).returns(false)
|
42
|
+
Boom::Platform.stubs(:windows?).returns(true)
|
43
|
+
assert_equal Boom::Platform.copy_command, 'clip'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_copy_command_linux
|
47
|
+
Boom::Platform.stubs(:darwin?).returns(false)
|
48
|
+
Boom::Platform.stubs(:windows?).returns(false)
|
49
|
+
assert_equal Boom::Platform.copy_command, 'xclip -selection clipboard'
|
50
|
+
end
|
51
|
+
|
15
52
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
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:
|
18
|
+
date: 2013-03-15 00:00:00 -07:00
|
19
19
|
default_executable: boom
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -121,7 +121,6 @@ files:
|
|
121
121
|
- lib/boom/storage.rb
|
122
122
|
- lib/boom/storage/base.rb
|
123
123
|
- lib/boom/storage/gist.rb
|
124
|
-
- lib/boom/storage/gist/json_parser.rb
|
125
124
|
- lib/boom/storage/json.rb
|
126
125
|
- lib/boom/storage/keychain.rb
|
127
126
|
- lib/boom/storage/mongodb.rb
|