boom 0.1.1 → 0.1.2

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/CHANGELOG.markdown CHANGED
@@ -1,6 +1,16 @@
1
1
  # boom changes
2
2
 
3
- ## 0.1.11
3
+ ## head
4
+
5
+ ## 0.1.2
6
+ - Copy to clipboard doesn't hang anymore. Sweet. Thanks,
7
+ [mcollina](https://github.com/mcollina).
8
+ - Holy hell, [brettbuddin](https://github.com/brettbuddin) added completion for
9
+ zsh. Pretty awesome too.
10
+ - [antonlindstrom](https://github.com/antonlindstrom) fixed up the MongoDB
11
+ backend.
12
+
13
+ ## 0.1.1
4
14
  - Don't force Redis on everyone.
5
15
 
6
16
  ## 0.1.0
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.1.1'
17
- s.date = '2011-02-28'
16
+ s.version = '0.1.2'
17
+ s.date = '2011-03-11'
18
18
  s.rubyforge_project = 'boom'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -71,6 +71,7 @@ Gem::Specification.new do |s|
71
71
  Rakefile
72
72
  bin/boom
73
73
  boom.gemspec
74
+ completion/README.md
74
75
  completion/boom.bash
75
76
  completion/boom.zsh
76
77
  lib/boom.rb
@@ -0,0 +1,7 @@
1
+ # boom completion
2
+
3
+ To add autocompletion to your shell, look in this directory and grab the script
4
+ that matches your corresponding shell.
5
+
6
+ I use the Z shell, so hey, I picked `boom.zsh`. And trust me: after a couple minutes of
7
+ playing with it, you'll never look back. NEVER!
data/completion/boom.zsh CHANGED
@@ -1,18 +1,29 @@
1
- # oh hai!
2
- #
3
- # someone should fork this and add autocompletion for zsh
4
- #
5
- # you'd be pretty cool
6
- #
7
- # and I'd give you a high-five
8
- #
9
- #
10
- #
11
- # and maybe a whiskey
12
- #
13
- #
14
- #
15
- #
16
- #
17
- #
18
- # a couple of whiskeys
1
+ #compdef boom
2
+
3
+ local state line cmds ret=1
4
+
5
+ _arguments -C '1: :->cmds' '*: :->args'
6
+
7
+ case $state in
8
+ cmds)
9
+ local -a cmds
10
+ cmds=(
11
+ 'all:show all items in all lists'
12
+ 'edit:edit the boom JSON file in $EDITOR'
13
+ 'help:help text'
14
+ )
15
+ _describe -t commands 'boom command' cmds && ret=0
16
+ _values 'lists' $(boom | awk '{print $1}')
17
+ ;;
18
+ args)
19
+ case $line[1] in
20
+ (boom|all|edit|help)
21
+ ;;
22
+ *)
23
+ _values 'items' `boom $line[1] | awk '{print $1}' | sed -e 's/://'` 2>/dev/null && ret=0
24
+ ;;
25
+ esac
26
+ ;;
27
+ esac
28
+
29
+ return ret
data/lib/boom/config.rb CHANGED
@@ -48,7 +48,7 @@ module Boom
48
48
  # Returns whether the attributes were saved.
49
49
  def bootstrap
50
50
  @attributes = {
51
- :backend => 'JSON'
51
+ :backend => 'json'
52
52
  }
53
53
  save
54
54
  end
data/lib/boom/platform.rb CHANGED
@@ -45,7 +45,7 @@ module Boom
45
45
  def copy(item)
46
46
  copy_command = darwin? ? "pbcopy" : "xclip -selection clipboard"
47
47
 
48
- `echo '#{item.value.gsub("\'","\\'")}' | tr -d "\n" | #{copy_command}`
48
+ Kernel.system("echo '#{item.value.gsub("\'","\\'")}' | tr -d \"\n\" | #{copy_command}")
49
49
 
50
50
  "Boom! We just copied #{item.value} to your clipboard."
51
51
  end
@@ -1,67 +1,57 @@
1
1
  # coding: utf-8
2
2
 
3
3
  # Storage adapter that saves data from boom to MongoDB instead of JSON file.
4
- #
5
- # This was grabbed from antonlindstrom's fork, but he wrote it before the 0.1.0
6
- # changes to boom. It would need to be updated to use Boom::Config and to
7
- # inherit methods from Boom::Storage::Base. Until then, this is chillin' here
8
- # until it gets fixed.
4
+ begin
5
+ require 'mongo'
6
+ require 'json/pure' # Will be here for now See Issue#21
7
+ rescue LoadError
8
+ end
9
9
 
10
10
  module Boom
11
11
  module Storage
12
- class MongoDB
12
+ class Mongodb < Base
13
13
 
14
- MONGO_CFG = "#{ENV['HOME']}/.boomdb.conf"
15
-
16
- # Public: the path to the JSON Mongo config file, userdata.
17
- #
18
- # Returns the String path of boom's MongoDB userdata
19
- def mongo_cfg
20
- MONGO_CFG
21
- end
22
-
23
- # Public: initializes a Storage instance by loading in your persisted data.
14
+ # Public: Initialize MongoDB connection and check dep.
24
15
  #
25
- # Returns the Storage instance.
26
- def initialize
27
- require 'mongo'
16
+ # Returns Mongo connection
17
+ def mongo
18
+ @mongo ||= ::Mongo::Connection.new(
19
+ Boom.config.attributes["mongodb"]["host"],
20
+ Boom.config.attributes["mongodb"]["port"]
21
+ ).db(Boom.config.attributes["mongodb"]["database"])
28
22
 
29
- @lists = []
30
- @mongo_coll = nil
31
- mongo_initialize(mongo_cfg) # Initialize the MongoDB and set data in memory
32
- collect
23
+ @mongo.authenticate(
24
+ Boom.config.attributes['mongodb']['username'],
25
+ Boom.config.attributes['mongodb']['password']
26
+ )
27
+
28
+ # Return connection
29
+ @mongo
30
+ rescue NameError => e
31
+ puts "You don't have the Mongo gem installed yet:\n gem install mongo"
32
+ exit
33
33
  end
34
-
35
- # Public: return the list from mongodb
34
+
35
+ # Public: The MongoDB collection
36
36
  #
37
- # Returns list
38
- def lists
39
- @lists
37
+ # Returns the MongoDB collection
38
+ def collection
39
+ @collection ||= mongo.collection(Boom.config.attributes["mongodb"]["collection"])
40
40
  end
41
-
42
- # Public: Save to MongoDB
43
- #
44
- # lists_json - the list to be saved in JSON format
41
+
42
+ # Public: Bootstrap
45
43
  #
46
- # Returns whatever mongo returns.
47
- def save(lists_json)
48
- doc = @mongo_coll.find_one()
49
- @mongo_coll.update({"_id" => doc["_id"]}, {'boom' => lists_json})
50
- end
51
-
52
- # INTERNAL METHODS ##########################################################
44
+ # Returns
45
+ def bootstrap
46
+ collection.insert("boom" => '{"lists": [{}]}') if collection.find_one.nil?
47
+ end
53
48
 
54
- # Take a JSON representation of data and explode it out into the consituent
55
- # Lists and Items for the given Storage instance.
49
+ # Public: Populates the memory list from MongoDB
56
50
  #
57
- # Returns nothing.
58
- def collect
59
-
60
- s = @mongo_coll.find_one['boom']
61
- storage = Yajl::Parser.new.parse(s)
62
-
63
- return if storage['lists'].nil?
64
-
51
+ # Returns nothing
52
+ def populate
53
+ storage = JSON.parse(collection.find_one['boom']) || []
54
+
65
55
  storage['lists'].each do |lists|
66
56
  lists.each do |list_name, items|
67
57
  @lists << list = List.new(list_name)
@@ -72,68 +62,24 @@ module Boom
72
62
  end
73
63
  end
74
64
  end
75
- end
65
+ end
76
66
  end
77
-
78
- ##### MONGODB ######
79
-
80
- # Initialize MongoDB and set data in memory
81
- #
82
- # config_file - The MongoDB config_file path defined
83
- #
84
- # Returns database obj.
85
- def mongo_initialize(config_file)
86
- bootstrap_config(config_file) unless File.exists?(config_file)
87
- config = parse_mongo_cfg(config_file)
88
-
89
- db = Mongo::Connection.new(config['host'], config['port']).db(config['database'])
90
- auth = db.authenticate(config['username'], config['password'])
91
-
92
- # Get collection collection;
93
- @mongo_coll = db.collection(config['collection'])
94
-
95
- @mongo_coll.insert("boom" => '{"lists": [{}]}') if @mongo_coll.find_one.nil?
96
-
97
- return @mongo_coll
98
- end
99
-
100
- # Parse Mongo JSON Config
101
- #
102
- # config_file - The MongoDB config_file path defined
67
+
68
+ # Public: Save to MongoDB
103
69
  #
104
- # Returns a hash of Mongo Userdata
105
- def parse_mongo_cfg(config_file)
106
-
107
- mongod = Hash.new
108
- config = Yajl::Parser.new.parse(File.open(config_file, 'r'))
109
-
110
- config.each_pair do |type, data|
111
- mongod[type] = data
112
- end
113
- return mongod
70
+ # Returns Mongo ID
71
+ def save
72
+ doc = collection.find_one()
73
+ collection.update({"_id" => doc["_id"]}, {'boom' => to_json})
114
74
  end
115
-
116
- # Run a default config
117
- #
118
- # config_file - The MongoDB config_file path defined
75
+
76
+ # Public: Convert to JSON
119
77
  #
120
- # Returns File obj.
121
- def bootstrap_config(config_file)
122
- config = Hash.new
123
-
124
- config['host'] = 'localhost'
125
- config['port'] = '27017'
126
- config['database'] = 'boom'
127
- config['username'] = 'boom'
128
- config['password'] = 's3cr3t'
129
- config['collection'] = 'boom'
130
-
131
- # Write to CFG
132
- json_cfg = Yajl::Encoder.encode(config, :pretty => true)
133
- File.open(config_file, 'w') {|f| f.write(json_cfg) }
78
+ # Returns
79
+ def to_json
80
+ JSON.generate(to_hash)
134
81
  end
135
-
136
-
82
+
137
83
  end
138
84
  end
139
- end
85
+ end
data/lib/boom.rb CHANGED
@@ -25,7 +25,7 @@ require 'boom/storage/mongodb'
25
25
  require 'boom/core_ext/symbol'
26
26
 
27
27
  module Boom
28
- VERSION = '0.1.1'
28
+ VERSION = '0.1.2'
29
29
 
30
30
  extend self
31
31
 
data/test/test_config.rb CHANGED
@@ -14,7 +14,7 @@ class TestConfig < Test::Unit::TestCase
14
14
 
15
15
  def test_bootstraps_config
16
16
  @config.bootstrap
17
- assert_equal ({:backend => 'JSON'}), @config.attributes
17
+ assert_equal ({:backend => 'json'}), @config.attributes
18
18
  end
19
19
 
20
20
  def test_attributes
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: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
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: 2011-02-28 00:00:00 -08:00
18
+ date: 2011-03-11 00:00:00 -08:00
19
19
  default_executable: boom
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -73,6 +73,7 @@ files:
73
73
  - Rakefile
74
74
  - bin/boom
75
75
  - boom.gemspec
76
+ - completion/README.md
76
77
  - completion/boom.bash
77
78
  - completion/boom.zsh
78
79
  - lib/boom.rb