Skip to content

Commit d4692e1

Browse files
committed
Reved up sinatra and bug fixes
1 parent 65b4d5a commit d4692e1

12 files changed

+85
-34
lines changed

Gemfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source :rubygems
2+
3+
gem 'rake', '~> 0.9.0'
4+
gem 'bson'
5+
gem 'bson_ext'
6+
gem 'mongo'
7+
gem 'sinatra'
8+
gem 'mongo_rack'
9+
gem 'main'
10+
gem 'agnostic-will_paginate'

Gemfile.lock

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
GEM
2+
remote: http://rubygems.org/
3+
specs:
4+
agnostic-will_paginate (3.0.0)
5+
arrayfields (4.7.4)
6+
bson (1.5.2)
7+
bson_ext (1.5.2)
8+
bson (= 1.5.2)
9+
chronic (0.6.7)
10+
fattr (2.2.1)
11+
main (4.8.1)
12+
arrayfields (~> 4.7.4)
13+
chronic (~> 0.6.2)
14+
fattr (~> 2.2.0)
15+
map (~> 5.1.0)
16+
map (5.1.0)
17+
mongo (1.5.2)
18+
bson (= 1.5.2)
19+
mongo_ext (0.19.3)
20+
mongo_rack (0.0.5)
21+
mongo (>= 0.18.2)
22+
mongo_ext (>= 0.18.2)
23+
rack (>= 1.0.1)
24+
rack (1.4.1)
25+
rack-protection (1.2.0)
26+
rack
27+
rake (0.9.2.2)
28+
sinatra (1.3.2)
29+
rack (~> 1.3, >= 1.3.6)
30+
rack-protection (~> 1.2)
31+
tilt (~> 1.3, >= 1.3.3)
32+
tilt (1.3.3)
33+
34+
PLATFORMS
35+
ruby
36+
37+
DEPENDENCIES
38+
agnostic-will_paginate
39+
bson
40+
bson_ext
41+
main
42+
mongo
43+
mongo_rack
44+
rake (~> 0.9.0)
45+
sinatra

HISTORY

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,7 @@
4646
0 Bugs and fixes
4747

4848
0.1.3
49-
o Updated to mongo ruby 1.0.1 - Fixed issue with lib breakage on OrderedHash
49+
o Updated to mongo ruby 1.0.1 - Fixed issue with lib breakage on OrderedHash
50+
51+
0.1.4
52+
o Updated to sinatra rev 1.3.2 and bug fixes

README.rdoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
== INSTALL:
5454

55-
sudo gem install mongo3
55+
gem install mongo3
5656

5757
== USAGE:
5858

@@ -99,7 +99,7 @@
9999

100100
== LICENSE:
101101

102-
Copyright 2009-2010 LiquidRail LLC
102+
Copyright 2011-2012 LiquidRail LLC
103103

104104
Licensed under the Apache License, Version 2.0 (the "License");
105105
you may not use this file except in compliance with the License.

lib/app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'will_paginate'
88
require 'mongo_rack'
99

10-
set :public, File.join( File.dirname(__FILE__), %w[public] )
10+
set :public_folder, File.join( File.dirname(__FILE__), %w[public] )
1111
set :views , File.join( File.dirname(__FILE__), %w[views] )
1212

1313
# -----------------------------------------------------------------------------

lib/controllers/collections.rb

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module Collections
3939
@page = params[:page].to_i || 1
4040

4141
@indexes = options.connection.indexes_for( session[:path_names] )
42-
puts "INDEXES #{@indexes.inspect}"
4342
load_cltn( params[:page].to_i )
4443

4544
erb :'collections/list'
@@ -115,7 +114,7 @@ def load_cltn( page=1 )
115114
end
116115
@page = page
117116
path_names = session[:path_names]
118-
117+
puts "PARAMS ", query_params.inspect
119118
@cltn = options.connection.paginate_cltn( path_names, query_params, @page, 15 )
120119
end
121120
end

lib/helpers/collection_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ def format_index( pair )
7272

7373
# converts orientation to human
7474
def orientation( value )
75-
puts "VALUE #{value.inspect}"
7675
return "id" if value.is_a?(Hash)
7776
case( value.to_i )
7877
when Mongo::ASCENDING

lib/helpers/main_helper.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ def javascripts( scripts )
1818
end
1919

2020
def v_styles(stylesheet)
21-
"/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra::Application.root, "..", "lib", "public", "stylesheets", "#{stylesheet}.css")).to_i.to_s
21+
"/stylesheets/#{stylesheet}.css?" + File.mtime(File.join(Sinatra::Application.root, "lib", "public", "stylesheets", "#{stylesheet}.css")).to_i.to_s
2222
end
2323

2424
def v_js(js)
25-
"/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra::Application.root, "..", "lib", "public", "javascripts", "#{js}.js")).to_i.to_s
25+
"/javascripts/#{js}.js?" + File.mtime(File.join(Sinatra::Application.root, "lib", "public", "javascripts", "#{js}.js")).to_i.to_s
2626
end
2727

2828
def zone_locator

lib/mongo3.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Mongo3
22

33
# :stopdoc:
4-
VERSION = '0.1.3' unless defined? Mongo3::VERSION
4+
VERSION = '0.1.4' unless defined? Mongo3::VERSION
55
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
66
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::PATH
77
# :startdoc:

lib/mongo3/connection.rb

+16-12
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,14 @@ def show( path_names )
125125
connect_for( zone ) do |con|
126126
db = con.db( db_name )
127127
info[:links][:manage] = "/databases/1"
128-
info[:size] = to_mb( con.database_info[db_name] )
129-
# info[:node] = db.nodes
130-
info[:collections] = collection_names( db ).size
131-
info[:error] = db.error
132-
info[:last_status] = db.last_status
128+
info.merge!(db.stats)
129+
info['dataSize'] = to_mb( info['dataSize'] )
130+
info['storageSize'] = to_mb( info['storageSize'] )
131+
info['avgObjSize'] = to_mb( info['avgObjSize'] )
132+
info['fileSize'] = to_mb( info['fileSize'] )
133+
info['indexSize'] = to_mb( info['indexSize'] )
134+
info.delete('ok')
135+
info[:errors] = db.error?
133136
end
134137
elsif path_name_tokens.size == 4
135138
cltn_name = path_name_tokens.pop
@@ -183,7 +186,7 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )
183186
db = con.db( db_name )
184187
cltn = db[cltn_name]
185188
count = cltn.find( query_params.first ).count
186-
189+
puts "Count #{count} -- #{query_params.first}"
187190
list = WillPaginate::Collection.create( page, per_page, count ) do |pager|
188191
offset = (page-1)*per_page
189192
sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
@@ -198,7 +201,8 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )
198201
results = cltn.find( query,
199202
:sort => sort,
200203
:skip => offset,
201-
:limit => per_page ).to_a
204+
:limit => per_page ).to_a
205+
puts "RESULTS #{results.count}"
202206
pager.replace( results )
203207
end
204208
end
@@ -426,8 +430,8 @@ def connect_for( zone, &block )
426430
yield con
427431
con.close()
428432
rescue => boom
429-
# puts boom
430-
# puts boom.backtrace.each {|l| puts l }
433+
puts boom
434+
puts boom.backtrace.each {|l| puts l }
431435
raise "MongoDB connection failed for `#{@info['host'].inspect}:#{@info['port'].inspect} with #{boom}"
432436
end
433437
end
@@ -456,10 +460,10 @@ def format_indexes( indexes )
456460
end
457461

458462
# Convert size to mb
459-
def to_mb( val )
463+
def to_mb( val )
460464
return 0 unless val
461-
return val if val < 1_000_000
462-
"#{format_number(val/1_000_000)}Mb"
465+
return ("%5.2f" % val ) if val < 1_000_000
466+
"%5.2f Mb" % (val/1_000_000.0)
463467
end
464468

465469
# Add thousand markers

lib/views/collections/_index_rows.erb

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
<img class="wait" id="wait_<%=name%>" src="/images/loading.gif"/>
1818
</td>
1919
<td><%=name%></td>
20-
<% puts @indexes[name].inspect %>
2120
<% buff = [];@indexes[name].each_pair do |k,v| %>
2221
<% buff << format_index( [k,v] ) %>
2322
<% end %>

lib/views/collections/_results.erb

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
<% unless @cltn.empty? %>
2-
<!-- <div id="fields">
3-
<= partial :'collections/fields_form' %>
4-
</div> -->
5-
6-
<div class="table">
7-
<%= partial :'collections/rows_tree' %>
8-
</div>
9-
<% else %>
10-
<div class="no_items">Oh snap! No items found...</span>
11-
<% end %>
1+
<div class="table">
2+
<%= partial :'collections/rows_tree' %>
3+
</div>

0 commit comments

Comments
 (0)