mongo3 0.0.9 → 0.1.0

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.
Files changed (95) hide show
  1. data/.bnignore +3 -0
  2. data/.bnsignore +16 -0
  3. data/.gitignore +1 -0
  4. data/HISTORY +11 -1
  5. data/README.rdoc +2 -0
  6. data/bin/mongo3 +7 -6
  7. data/config/mongo3.yml +33 -0
  8. data/data/populate +37 -0
  9. data/lib/controllers/collections.rb +2 -10
  10. data/lib/controllers/databases.rb +12 -1
  11. data/lib/controllers/explore.rb +20 -6
  12. data/lib/helpers/collection_helper.rb +34 -2
  13. data/lib/helpers/explore_helper.rb +0 -5
  14. data/lib/helpers/main_helper.rb +5 -0
  15. data/lib/helpers/paths_helper.rb +15 -0
  16. data/lib/mongo3/connection.rb +39 -24
  17. data/lib/mongo3/user.rb +10 -4
  18. data/lib/mongo3/zone.rb +24 -8
  19. data/lib/mongo3.rb +4 -7
  20. data/lib/public/.DS_Store +0 -0
  21. data/lib/public/images/favicon.png +0 -0
  22. data/lib/public/images/information.png +0 -0
  23. data/lib/public/images/tree/Thumbs.db +0 -0
  24. data/lib/public/images/tree/array.png +0 -0
  25. data/lib/public/images/tree/arrow_refresh.png +0 -0
  26. data/lib/public/images/tree/collapsable-last.gif +0 -0
  27. data/lib/public/images/tree/collapsable.gif +0 -0
  28. data/lib/public/images/tree/collection.png +0 -0
  29. data/lib/public/images/tree/cross.png +0 -0
  30. data/lib/public/images/tree/disk.png +0 -0
  31. data/lib/public/images/tree/expandable-last.gif +0 -0
  32. data/lib/public/images/tree/expandable-last.png +0 -0
  33. data/lib/public/images/tree/expandable.gif +0 -0
  34. data/lib/public/images/tree/expandable.png +0 -0
  35. data/lib/public/images/tree/folder_add.png +0 -0
  36. data/lib/public/images/tree/folder_delete.png +0 -0
  37. data/lib/public/images/tree/folder_edit.png +0 -0
  38. data/lib/public/images/tree/icons.png +0 -0
  39. data/lib/public/images/tree/leaf-last.gif +0 -0
  40. data/lib/public/images/tree/leaf-last.png +0 -0
  41. data/lib/public/images/tree/leaf.gif +0 -0
  42. data/lib/public/images/tree/leaf.png +0 -0
  43. data/lib/public/images/tree/line_bg.gif +0 -0
  44. data/lib/public/images/tree/line_bg_over.gif +0 -0
  45. data/lib/public/images/tree/line_bg_over_last.gif +0 -0
  46. data/lib/public/images/tree/minus.gif +0 -0
  47. data/lib/public/images/tree/page_add.png +0 -0
  48. data/lib/public/images/tree/page_delete.png +0 -0
  49. data/lib/public/images/tree/page_edit.png +0 -0
  50. data/lib/public/images/tree/plus.gif +0 -0
  51. data/lib/public/images/tree/root.gif +0 -0
  52. data/lib/public/images/tree/spacer.gif +0 -0
  53. data/lib/public/images/tree/spinner.gif +0 -0
  54. data/lib/public/images/tree/tree_line.gif +0 -0
  55. data/lib/public/javascripts/.DS_Store +0 -0
  56. data/lib/public/javascripts/jquery.simple.tree.js +451 -0
  57. data/lib/public/javascripts/jquery.tiptip.min.js +6 -0
  58. data/lib/public/javascripts/jquery.tree.min.js +1 -0
  59. data/lib/public/javascripts/jstree/jquery.tree.js +2058 -0
  60. data/lib/public/javascripts/themes/mongo3/bg.jpg +0 -0
  61. data/lib/public/javascripts/themes/mongo3/dot_for_ie.gif +0 -0
  62. data/lib/public/javascripts/themes/mongo3/icons.png +0 -0
  63. data/lib/public/javascripts/themes/mongo3/style.css +39 -0
  64. data/lib/public/javascripts/themes/mongo3/throbber.gif +0 -0
  65. data/lib/public/stylesheets/mongo3.css +201 -65
  66. data/lib/views/collections/_fields_form.erb +1 -1
  67. data/lib/views/collections/_index_form.erb +1 -1
  68. data/lib/views/collections/_index_rows.erb +40 -15
  69. data/lib/views/collections/_nodes.erb +0 -0
  70. data/lib/views/collections/_results.erb +4 -4
  71. data/lib/views/collections/{_rows.erb → _rows_table.erb} +11 -9
  72. data/lib/views/collections/_rows_tree.erb +81 -0
  73. data/lib/views/collections/_search_form.erb +1 -1
  74. data/lib/views/collections/blee.erb +20 -0
  75. data/lib/views/collections/list.erb +1 -1
  76. data/lib/views/collections/update.js.erb +1 -1
  77. data/lib/views/databases/_results.erb +9 -7
  78. data/lib/views/explore/_node_info.erb +21 -4
  79. data/lib/views/explore/explore.erb +11 -1
  80. data/lib/views/explore/load_collection.js.erb +1 -0
  81. data/lib/views/explore/load_database.js.erb +1 -0
  82. data/lib/views/layout.erb +13 -7
  83. data/lib/views/users/_results.erb +2 -2
  84. data/spec/configs/crap.yml +20 -0
  85. data/spec/configs/hosed.yml +4 -0
  86. data/spec/configs/landscape.yml +9 -0
  87. data/spec/mongo3/connection_spec.rb +105 -12
  88. data/spec/mongo3/node_spec.rb +38 -0
  89. data/spec/mongo3/user_spec.rb +72 -0
  90. data/spec/mongo3/zone_spec.rb +69 -0
  91. data/spec/mongo3_spec.rb +20 -0
  92. data/spec/spec_helper.rb +13 -0
  93. data/tasks/setup.rb +1 -1
  94. metadata +71 -6
  95. data/spec/landscape.yml +0 -3
data/.bnignore ADDED
@@ -0,0 +1,3 @@
1
+ *.log
2
+ *.psd
3
+ .git
data/.bnsignore ADDED
@@ -0,0 +1,16 @@
1
+ # The list of files that should be ignored by Mr Bones.
2
+ # Lines that start with '#' are comments.
3
+ #
4
+ # A .gitignore file can be used instead by setting it as the ignore
5
+ # file in your Rakefile:
6
+ #
7
+ # PROJ.ignore_file = '.gitignore'
8
+ #
9
+ # For a project with a C extension, the following would be a good set of
10
+ # exclude patterns (uncomment them if you want to use them):
11
+ # *.[oa]
12
+ # *~
13
+ announcement.txt
14
+ coverage
15
+ doc
16
+ pkg
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.psd
data/HISTORY CHANGED
@@ -26,4 +26,14 @@
26
26
  o Added user administration - should be able to crub users on zone now
27
27
  o Added mongo based session store using mongo_rack. (Per Kyle's suggestion! ). This is now the default session store.
28
28
  You can alternatively still use memcache ( see README for instructions )
29
- o Bug fixes and some cleanup
29
+ o Bug fixes and some cleanup
30
+
31
+ 0.0.8 - Bug fixes and clean up
32
+
33
+ 0.0.9 - Bug fixes and clean up
34
+
35
+ 0.1.0 - Big improvements!
36
+ o Added better support for docs and embedded docs.
37
+ o Change navigation to make it easier to drilldown ( Tx Tyler !).
38
+ o More tests
39
+ o Improved browser support for saf and chrome - sorry don't do windoze ;-(
data/README.rdoc CHANGED
@@ -34,8 +34,10 @@
34
34
  * CRUD on dbs, collections, indexes [done]
35
35
  * Administer users [done]
36
36
  * Collection rename
37
+ * Database creation
37
38
  * Manage logs
38
39
  * Support for shards and replication
40
+ * Add support for drilling down array and embedded documents [done]
39
41
 
40
42
  == DEPENDENCIES
41
43
 
data/bin/mongo3 CHANGED
@@ -33,20 +33,21 @@ Main {
33
33
  puts "\n"*2
34
34
  puts ">>> Opening console..."
35
35
  puts "\n"*2
36
- open( "http://localhost:6666/explore" )
36
+ open( "http://localhost:#{default_port}/explore" )
37
37
  end
38
38
 
39
39
  # Clearing args for franky!
40
40
  ARGV.clear
41
41
  require 'sinatra'
42
42
  require File.join(File.dirname(__FILE__), %w[.. lib app.rb])
43
- Sinatra::Application.run! :port => 6666, :environment => 'production'
43
+ Sinatra::Application.run! :port => default_port, :environment => 'production'
44
44
  end
45
45
 
46
+ # default port
47
+ def default_port() 6663; end
48
+
46
49
  # sleepy time...
47
- def sleep_time
48
- 3
49
- end
50
+ def sleep_time() 3; end
50
51
 
51
52
  # open console...
52
53
  def open(path)
@@ -73,4 +74,4 @@ Main {
73
74
  end
74
75
  opts
75
76
  end
76
- }
77
+ }
data/config/mongo3.yml ADDED
@@ -0,0 +1,33 @@
1
+ development:
2
+ host: localhost
3
+ port: 27017
4
+
5
+ beta:
6
+ host: dev8
7
+ port: 27018
8
+ user: "blee"
9
+ password: "fred"
10
+
11
+ # production:
12
+ # :host: dev8
13
+ # :port: 27018
14
+ # :user: "blee"
15
+ # :password: "fred"
16
+ #
17
+ # serv1:
18
+ # :host: dev8
19
+ # :port: 27018
20
+ # :user: "blee"
21
+ # :password: "fred"
22
+ #
23
+ # serv2:
24
+ # :host: dev8
25
+ # :port: 27018
26
+ # :user: "blee"
27
+ # :password: "fred"
28
+ #
29
+ # serv3:
30
+ # :host: dev8
31
+ # :port: 27018
32
+ # :user: "blee"
33
+ # :password: "fred"
data/data/populate ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'mongo'
4
+
5
+ connection = Mongo::Connection.new( 'localhost', 27017 )
6
+
7
+ db_name = "fernand_mdb"
8
+ cltn_names = %w[blee bobo]
9
+
10
+
11
+ db = connection.db( db_name )
12
+
13
+ cltn_names.each do |cltn_name|
14
+ cltn = db.create_collection( cltn_name )
15
+ cltn.remove
16
+
17
+ 20.times do |i|
18
+ row = {
19
+ :name => "#{cltn_name}_#{i}",
20
+ :last_name => "#{db_name}.#{cltn_name}_#{i}",
21
+ :array => 10.times.to_a,
22
+ :hash => {
23
+ :blee => 5.times.to_a,
24
+ :duh => "Hello",
25
+ :hash => {
26
+ :duh => 10
27
+ }
28
+ }
29
+ }
30
+ puts "Inserting row #{row.inspect}"
31
+ cltn.insert( row )
32
+ end
33
+
34
+ cltn = db[cltn_name]
35
+ puts ""
36
+ puts "Inserted `#{cltn.count} records in `#{cltn_name}"
37
+ end
@@ -3,6 +3,7 @@ require 'json'
3
3
  module Collections
4
4
 
5
5
  # ---------------------------------------------------------------------------
6
+ # BOZO - Move to indexes ctrl
6
7
  post "/collections/create_index/" do
7
8
  json = params[:index].gsub( /'/, "\"" )
8
9
  tokens = json.split( "|" )
@@ -34,7 +35,7 @@ module Collections
34
35
  # ---------------------------------------------------------------------------
35
36
  # Paginate on a collection
36
37
  get "/collections/:page" do
37
- @back_url = "/explore/back"
38
+ @back_url = "/databases/1"
38
39
  @page = params[:page].to_i || 1
39
40
 
40
41
  @indexes = options.connection.indexes_for( session[:path_names] )
@@ -46,9 +47,6 @@ module Collections
46
47
 
47
48
  # ---------------------------------------------------------------------------
48
49
  post "/collections/refresh/:page/" do
49
- selected_cols = params[:cols].keys.sort
50
- session[:selected_cols] = selected_cols
51
-
52
50
  load_cltn( params[:page].to_i )
53
51
 
54
52
  erb :'collections/update.js', :layout => false
@@ -119,12 +117,6 @@ module Collections
119
117
  path_names = session[:path_names]
120
118
 
121
119
  @cltn = options.connection.paginate_cltn( path_names, query_params, @page, 15 )
122
- @cols = []
123
- @selected_cols = []
124
- unless @cltn.empty?
125
- @cols = @cltn.first.keys.sort
126
- @selected_cols = session[:selected_cols] || @cols[0...5]
127
- end
128
120
  end
129
121
  end
130
122
  end
@@ -4,7 +4,18 @@ module Databases
4
4
  get "/databases/:page" do
5
5
  page = params[:page].to_i || 1
6
6
  path_names = session[:path_names]
7
-
7
+ tokens = path_names.split( "|" )
8
+
9
+ # Could be we have a cltn path. if so adjust for it
10
+ if tokens.size > 3
11
+ tokens.pop
12
+ session[:path_names] = tokens.join( "|")
13
+ path_names = session[:path_names]
14
+ path_ids = session[:path_ids].split( "|" )
15
+ path_ids.pop
16
+ session[:path_ids] = path_ids.join( "|" )
17
+ end
18
+
8
19
  @cltns = options.connection.paginate_db( path_names, page, 10 )
9
20
  @back_url = "/explore/back"
10
21
 
@@ -7,7 +7,7 @@ module Explore
7
7
  @node_id = params[:db_id]
8
8
  db_name = params[:db_name].gsub( /\(\d+\)/, '' )
9
9
 
10
- options.connection.drop_database( session[:path_names], db_name )
10
+ options.connection.drop_db( "#{session[:path_names]}|#{db_name}" )
11
11
 
12
12
  flash_it!( :info, "Database `#{db_name} was dropped successfully!" )
13
13
 
@@ -16,6 +16,9 @@ module Explore
16
16
 
17
17
  # -----------------------------------------------------------------------------
18
18
  get '/explore' do
19
+ session[:selected_cols] = nil
20
+ session[:query_params] = nil
21
+
19
22
  root = options.connection.build_tree
20
23
  @root = root.to_adjacencies
21
24
  @nodes = root.children
@@ -25,10 +28,6 @@ module Explore
25
28
 
26
29
  erb :'explore/explore'
27
30
  end
28
-
29
- get "/fred/:duh" do
30
- "Hello World #{params[:duh]}"
31
- end
32
31
 
33
32
  # -----------------------------------------------------------------------------
34
33
  get '/explore/back' do
@@ -51,7 +50,7 @@ module Explore
51
50
  end
52
51
 
53
52
  # -----------------------------------------------------------------------------
54
- get '/explore/show/:path_ids/:path_names' do
53
+ get '/explore/info/:path_ids/:path_names' do
55
54
  path_ids = params[:path_ids]
56
55
  path_names = params[:path_names]
57
56
 
@@ -79,6 +78,21 @@ module Explore
79
78
  erb :'explore/more_data_js', :layout => false
80
79
  end
81
80
 
81
+ # ---------------------------------------------------------------------------
82
+ get "/explore/show/:path_ids/:path_names" do
83
+ path_ids = params[:path_ids]
84
+ path_names = params[:path_names]
85
+
86
+ # crumbs_from_path( path_ids, path_names )
87
+ update_paths!( path_ids, path_names )
88
+
89
+ if cltn_path?( path_ids )
90
+ erb :'explore/load_collection.js', :layout => false
91
+ else
92
+ erb :'explore/load_database.js', :layout => false
93
+ end
94
+ end
95
+
82
96
  # -----------------------------------------------------------------------------
83
97
  get '/explore/update_crumb/:path_ids/:path_names' do
84
98
  path_ids = params[:path_ids]
@@ -15,6 +15,38 @@ module CollectionHelper
15
15
  helpers do
16
16
  include WillPaginate::ViewHelpers::Base
17
17
 
18
+ def format_nodes( item, col )
19
+ buff = []
20
+ _format_nodes( buff, item, col )
21
+ buff.join( "\n" )
22
+ end
23
+
24
+ def _format_nodes( buff, item, col=nil )
25
+ if item.is_a?( Array )
26
+ buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} <span class=\"meta\" style=\"color:#c1c1c1\">(#{item.size})</span></span>"
27
+ return buff if item.empty?
28
+ buff << "<ul>"
29
+ count = 0
30
+ item.each do |element|
31
+ _format_nodes( buff, element )
32
+ count += 1
33
+ end
34
+ buff << "</ul>"
35
+ buff << "</li>"
36
+ elsif item.is_a?( Hash )
37
+ buff << "<li><ins style=\"background-position:-48px -16px\"></ins><span>#{col} (#{item.size})</span>"
38
+ return buff if item.empty?
39
+ buff << "<ul>"
40
+ item.each_pair do |key,val|
41
+ _format_nodes( buff, val, key )
42
+ end
43
+ buff << "</ul>"
44
+ buff << "</li>"
45
+ else
46
+ buff << "<li><ins></ins><span title=\"#{item.to_s}\">#{truncate(item.to_s,90)} <span class=\"meta\" style=\"color:#c1c1c1\">#{col ? "[#{col} - #{item.class}]" : "[#{item.class}]"}</span></span></li>"
47
+ end
48
+ end
49
+
18
50
  # Attempts to format an attribute to some human readable format
19
51
  def format_value( value )
20
52
  if value.is_a?( Fixnum)
@@ -22,9 +54,9 @@ module CollectionHelper
22
54
  elsif value.is_a?(Hash)
23
55
  buff = []
24
56
  value.each_pair { |k,v| buff << "#{k}:#{format_value(v)}"}
25
- buff.join( "," )
57
+ buff.join( ", " )
26
58
  elsif value.is_a?(Array)
27
- value.join(",")
59
+ (value.empty? ? "[]" : value.join(", "))
28
60
  else
29
61
  value
30
62
  end
@@ -1,11 +1,6 @@
1
1
  module ExploreHelper
2
2
 
3
3
  helpers do
4
-
5
- # looking at zone path?
6
- def zone_path?( path )
7
- path.split( "|" ).size == 1
8
- end
9
4
 
10
5
  # compute legend title
11
6
  def legend_title( path )
@@ -61,6 +61,11 @@ module MainHelper
61
61
  end
62
62
 
63
63
  def partial( page, options={} )
64
+ if object = options.delete(:object)
65
+ template = page.to_s.split("/").last
66
+ options.merge!( :locals => { template.to_sym => object } )
67
+ end
68
+
64
69
  if page.to_s.index( /\// )
65
70
  page = page.to_s.gsub( /\//, '/_' )
66
71
  else
@@ -1,6 +1,21 @@
1
1
  module PathHelper
2
2
  helpers do
3
3
 
4
+ # looking at zone path?
5
+ def zone_path?( path )
6
+ path.split( "|" ).size == 1
7
+ end
8
+
9
+ # looking at db path?
10
+ def db_path?( path )
11
+ path.split( "|" ).size == 3
12
+ end
13
+
14
+ # looking at cltn path?
15
+ def cltn_path?( path )
16
+ path.split( "|" ).size == 4
17
+ end
18
+
4
19
  def reset_paths!
5
20
  session[:path_ids] = "home"
6
21
  session[:path_names] = "home"
@@ -1,6 +1,8 @@
1
1
  require 'yaml'
2
2
 
3
3
  # BOZO !! Time to refact no?
4
+ # TODO !! Arg check and errors
5
+ # TODO !! Add logging
4
6
  module Mongo3
5
7
  class Connection
6
8
 
@@ -8,15 +10,7 @@ module Mongo3
8
10
  @config_file = config_file
9
11
  end
10
12
 
11
- # drop a database using context and db name
12
- def drop_database( path_names, db_name )
13
- path_name_tokens = path_names.split( "|" )
14
- zone = path_name_tokens[1]
15
- connect_for( zone ) do |con|
16
- con.drop_database( db_name )
17
- end
18
- end
19
-
13
+ # drop a db using a db path
20
14
  def drop_db( path_names )
21
15
  path_name_tokens = path_names.split( "|" )
22
16
  zone = path_name_tokens[1]
@@ -42,12 +36,12 @@ module Mongo3
42
36
 
43
37
  def drop_index( path_names, index )
44
38
  path_name_tokens = path_names.split( "|" )
45
- zone = path_name_tokens[1]
39
+ zone = path_name_tokens[1]
46
40
  connect_for( zone ) do |con|
47
41
  cltn_name = path_name_tokens.pop
48
42
  db_name = path_name_tokens.pop
49
43
  db = con.db( db_name )
50
- cltn = db[cltn_name]
44
+ cltn = db[cltn_name]
51
45
  cltn.drop_index( index )
52
46
  end
53
47
  end
@@ -84,7 +78,7 @@ module Mongo3
84
78
  db_name = path_name_tokens.pop
85
79
  db = con.db( db_name )
86
80
  cltn = db[cltn_name]
87
- cltn.remove
81
+ cltn.remove( {} )
88
82
  end
89
83
  end
90
84
 
@@ -96,7 +90,7 @@ module Mongo3
96
90
  db_name = path_name_tokens.pop
97
91
  db = con.db( db_name )
98
92
  cltn = db[cltn_name]
99
- cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
93
+ res = cltn.remove( {:_id => Mongo::ObjectID.from_string(id) } )
100
94
  end
101
95
  end
102
96
 
@@ -150,7 +144,7 @@ module Mongo3
150
144
  end
151
145
 
152
146
  def paginate_db( path_names, page=1, per_page=10 )
153
- path_name_tokens = path_names.split( "|" )
147
+ path_name_tokens = path_names.split( "|" )
154
148
  zone = path_name_tokens[1]
155
149
  list = nil
156
150
  connect_for( zone ) do |con|
@@ -189,7 +183,15 @@ module Mongo3
189
183
  list = WillPaginate::Collection.create( page, per_page, count ) do |pager|
190
184
  offset = (page-1)*per_page
191
185
  sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
192
- results = cltn.find( query_params.first,
186
+ query = query_params.first
187
+
188
+ # Scan for regexes...
189
+ query.each_pair do |k,v|
190
+ if v.is_a?( String ) and v.index( /^\// )
191
+ query[k] = Regexp.new( v.gsub( "/", '' ) )
192
+ end
193
+ end
194
+ results = cltn.find( query,
193
195
  :sort => sort,
194
196
  :skip => offset,
195
197
  :limit => per_page ).to_a
@@ -398,14 +400,23 @@ module Mongo3
398
400
  # Connects to mongo given an zone
399
401
  def connect_for( zone, &block )
400
402
  info = landscape[zone]
401
- # puts ">>> Connecting for #{zone} -- #{info['host']}-#{info['port']}"
402
- con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
403
+ raise "Unable to find zone info in config file for zone `#{zone}" unless info
404
+ raise "Check your config. Unable to find `host information" unless info['host']
405
+ raise "Check your config. Unable to find `port information" unless info['port']
406
+
407
+ begin
408
+ con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
403
409
 
404
- if info['user'] and info['password']
405
- con.db( 'admin' ).authenticate( info['user'], info['password'] )
410
+ if info['user'] and info['password']
411
+ con.db( 'admin' ).authenticate( info['user'], info['password'] )
412
+ end
413
+ yield con
414
+ con.close()
415
+ rescue => boom
416
+ # puts boom
417
+ # puts boom.backtrace.each {|l| puts l }
418
+ raise "MongoDB connection failed for `#{info['host'].inspect}:#{info['port'].inspect}"
406
419
  end
407
- yield con
408
- con.close()
409
420
  end
410
421
 
411
422
  # db request occurs within dist 2
@@ -461,10 +472,14 @@ module Mongo3
461
472
  # Initialize the mongo installation landscape
462
473
  def config
463
474
  unless @config
464
- @config = YAML.load_file( @config_file )
475
+ begin
476
+ @config = YAML.load_file( @config_file )
477
+ rescue => boom
478
+ @config = nil
479
+ raise "Unable to grok yaml landscape file. #{boom}"
480
+ end
465
481
  end
466
482
  @config
467
- end
468
-
483
+ end
469
484
  end
470
485
  end
data/lib/mongo3/user.rb CHANGED
@@ -8,19 +8,25 @@ module Mongo3
8
8
  # add a new user
9
9
  def add( path, user_name, password )
10
10
  connect_for( path ) do |con|
11
- admin_db = con.db('admin')
12
- user_cltn = admin_db[Mongo::DB::SYSTEM_USER_COLLECTION]
11
+ user_cltn = users( con )
13
12
 
14
13
  row = { :user => user_name }
15
14
  user = user_cltn.find_one( row )
16
15
  raise "User #{user_name} already exists!" if user
17
16
 
18
- row[:pwd] = admin_db.send( :hash_password, user_name, password )
19
- user_cltn.save( row )
17
+ row[:pwd] = user_cltn.db.send( :hash_password, user_name, password )
18
+ return user_cltn.save( row )
20
19
  end
21
20
  end
22
21
 
22
+ def clear!( path )
23
+ connect_for( path ) do |con|
24
+ res = users( con ).remove( {} )
25
+ end
26
+ end
27
+
23
28
  def rename( zone, old_name, new_name )
29
+ raise "NYI"
24
30
  end
25
31
 
26
32
  def delete( path, id )
data/lib/mongo3/zone.rb CHANGED
@@ -15,20 +15,31 @@ module Mongo3
15
15
  end
16
16
 
17
17
  # Connects to mongo given an zone
18
+ # BOZO !! Shit is dupped in connection. Fix it !!
18
19
  def connect_for( path, &block )
19
- zone = zone_for_path( path )
20
+ zone = zone_for_path( path )
20
21
  info = config[zone]
21
- # puts ">>> Connecting for #{zone} -- #{info['host']}-#{info['port']}"
22
- con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
22
+ raise "Unable to find zone info in config file for zone `#{zone}" unless info
23
+ raise "Check your config. Unable to find `host information" unless info['host']
24
+ raise "Check your config. Unable to find `port information" unless info['port']
25
+
26
+ con = nil
27
+ begin
28
+ con = Mongo::Connection.new( info['host'], info['port'], { :slave_ok => true } )
23
29
 
24
- if info['user'] and info['password']
25
- con.db( 'admin' ).authenticate( info['user'], info['password'] )
26
- end
27
- yield con
30
+ if info['user'] and info['password']
31
+ con.db( 'admin' ).authenticate( info['user'], info['password'] )
32
+ end
33
+ rescue => boom
34
+ raise "MongoDB connection failed for `#{info['host']}:#{info['post']}"
35
+ end
36
+
37
+ yield con
28
38
  con.close()
29
39
  end
30
40
 
31
41
  # find zone matching the host and port combination
42
+ # BOZO !! Dupped in connection. Fix it !!
32
43
  def zone_for( host, port )
33
44
  config.each_pair do |zone, info|
34
45
  return zone if info['host'] == host and info['port'] == port.to_i
@@ -39,7 +50,12 @@ module Mongo3
39
50
  # Initialize the mongo installation landscape
40
51
  def config
41
52
  unless @config
42
- @config = YAML.load_file( @config_file )
53
+ begin
54
+ @config = YAML.load_file( @config_file )
55
+ rescue => boom
56
+ @config = nil
57
+ raise "Unable to grok yaml landscape file. #{boom}"
58
+ end
43
59
  end
44
60
  @config
45
61
  end
data/lib/mongo3.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  module Mongo3
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.0.9' unless defined? Mongo3::VERSION
4
+ VERSION = '0.1.0' unless defined? Mongo3::VERSION
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
6
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
6
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::PATH
7
7
  # :startdoc:
8
8
 
9
9
  # Returns the version string for the library.
@@ -48,9 +48,6 @@ module Mongo3
48
48
 
49
49
  Dir.glob(search_me).sort.each {|rb| load rb}
50
50
  end
51
+ end
51
52
 
52
- end # module Mongo3
53
-
54
- Mongo3.require_all_libs_relative_to(__FILE__)
55
-
56
- # EOF
53
+ Mongo3.require_all_libs_relative_to(__FILE__)
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file