Skip to content

Commit

Permalink
Reved up sinatra and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
derailed committed Apr 20, 2012
1 parent 65b4d5a commit d4692e1
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 34 deletions.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source :rubygems

gem 'rake', '~> 0.9.0'
gem 'bson'
gem 'bson_ext'
gem 'mongo'
gem 'sinatra'
gem 'mongo_rack'
gem 'main'
gem 'agnostic-will_paginate'
45 changes: 45 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GEM
remote: http://rubygems.org/
specs:
agnostic-will_paginate (3.0.0)
arrayfields (4.7.4)
bson (1.5.2)
bson_ext (1.5.2)
bson (= 1.5.2)
chronic (0.6.7)
fattr (2.2.1)
main (4.8.1)
arrayfields (~> 4.7.4)
chronic (~> 0.6.2)
fattr (~> 2.2.0)
map (~> 5.1.0)
map (5.1.0)
mongo (1.5.2)
bson (= 1.5.2)
mongo_ext (0.19.3)
mongo_rack (0.0.5)
mongo (>= 0.18.2)
mongo_ext (>= 0.18.2)
rack (>= 1.0.1)
rack (1.4.1)
rack-protection (1.2.0)
rack
rake (0.9.2.2)
sinatra (1.3.2)
rack (~> 1.3, >= 1.3.6)
rack-protection (~> 1.2)
tilt (~> 1.3, >= 1.3.3)
tilt (1.3.3)

PLATFORMS
ruby

DEPENDENCIES
agnostic-will_paginate
bson
bson_ext
main
mongo
mongo_rack
rake (~> 0.9.0)
sinatra
5 changes: 4 additions & 1 deletion HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@
0 Bugs and fixes

0.1.3
o Updated to mongo ruby 1.0.1 - Fixed issue with lib breakage on OrderedHash
o Updated to mongo ruby 1.0.1 - Fixed issue with lib breakage on OrderedHash

0.1.4
o Updated to sinatra rev 1.3.2 and bug fixes
4 changes: 2 additions & 2 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

== INSTALL:

sudo gem install mongo3
gem install mongo3

== USAGE:

Expand Down Expand Up @@ -99,7 +99,7 @@

== LICENSE:

Copyright 2009-2010 LiquidRail LLC
Copyright 2011-2012 LiquidRail LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion lib/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
require 'will_paginate'
require 'mongo_rack'

set :public, File.join( File.dirname(__FILE__), %w[public] )
set :public_folder, File.join( File.dirname(__FILE__), %w[public] )
set :views , File.join( File.dirname(__FILE__), %w[views] )

# -----------------------------------------------------------------------------
Expand Down
3 changes: 1 addition & 2 deletions lib/controllers/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module Collections
@page = params[:page].to_i || 1

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

erb :'collections/list'
Expand Down Expand Up @@ -115,7 +114,7 @@ def load_cltn( page=1 )
end
@page = page
path_names = session[:path_names]

puts "PARAMS ", query_params.inspect
@cltn = options.connection.paginate_cltn( path_names, query_params, @page, 15 )
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/helpers/collection_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ def format_index( pair )

# converts orientation to human
def orientation( value )
puts "VALUE #{value.inspect}"
return "id" if value.is_a?(Hash)
case( value.to_i )
when Mongo::ASCENDING
Expand Down
4 changes: 2 additions & 2 deletions lib/helpers/main_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ def javascripts( scripts )
end

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

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

def zone_locator
Expand Down
2 changes: 1 addition & 1 deletion lib/mongo3.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Mongo3

# :stopdoc:
VERSION = '0.1.3' unless defined? Mongo3::VERSION
VERSION = '0.1.4' unless defined? Mongo3::VERSION
LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR unless defined? Mongo3::LIBPATH
PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR unless defined? Mongo3::PATH
# :startdoc:
Expand Down
28 changes: 16 additions & 12 deletions lib/mongo3/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,14 @@ def show( path_names )
connect_for( zone ) do |con|
db = con.db( db_name )
info[:links][:manage] = "/databases/1"
info[:size] = to_mb( con.database_info[db_name] )
# info[:node] = db.nodes
info[:collections] = collection_names( db ).size
info[:error] = db.error
info[:last_status] = db.last_status
info.merge!(db.stats)
info['dataSize'] = to_mb( info['dataSize'] )
info['storageSize'] = to_mb( info['storageSize'] )
info['avgObjSize'] = to_mb( info['avgObjSize'] )
info['fileSize'] = to_mb( info['fileSize'] )
info['indexSize'] = to_mb( info['indexSize'] )
info.delete('ok')
info[:errors] = db.error?
end
elsif path_name_tokens.size == 4
cltn_name = path_name_tokens.pop
Expand Down Expand Up @@ -183,7 +186,7 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )
db = con.db( db_name )
cltn = db[cltn_name]
count = cltn.find( query_params.first ).count

puts "Count #{count} -- #{query_params.first}"
list = WillPaginate::Collection.create( page, per_page, count ) do |pager|
offset = (page-1)*per_page
sort = query_params.last.empty? ? [ ['_id', Mongo::DESCENDING] ] : query_params.last
Expand All @@ -198,7 +201,8 @@ def paginate_cltn( path_names, query_params=[{},[]], page=1, per_page=10 )
results = cltn.find( query,
:sort => sort,
:skip => offset,
:limit => per_page ).to_a
:limit => per_page ).to_a
puts "RESULTS #{results.count}"
pager.replace( results )
end
end
Expand Down Expand Up @@ -426,8 +430,8 @@ def connect_for( zone, &block )
yield con
con.close()
rescue => boom
# puts boom
# puts boom.backtrace.each {|l| puts l }
puts boom
puts boom.backtrace.each {|l| puts l }
raise "MongoDB connection failed for `#{@info['host'].inspect}:#{@info['port'].inspect} with #{boom}"
end
end
Expand Down Expand Up @@ -456,10 +460,10 @@ def format_indexes( indexes )
end

# Convert size to mb
def to_mb( val )
def to_mb( val )
return 0 unless val
return val if val < 1_000_000
"#{format_number(val/1_000_000)}Mb"
return ("%5.2f" % val ) if val < 1_000_000
"%5.2f Mb" % (val/1_000_000.0)
end

# Add thousand markers
Expand Down
1 change: 0 additions & 1 deletion lib/views/collections/_index_rows.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
<img class="wait" id="wait_<%=name%>" src="/images/loading.gif"/>
</td>
<td><%=name%></td>
<% puts @indexes[name].inspect %>
<% buff = [];@indexes[name].each_pair do |k,v| %>
<% buff << format_index( [k,v] ) %>
<% end %>
Expand Down
14 changes: 3 additions & 11 deletions lib/views/collections/_results.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
<% unless @cltn.empty? %>
<!-- <div id="fields">
<= partial :'collections/fields_form' %>
</div> -->

<div class="table">
<%= partial :'collections/rows_tree' %>
</div>
<% else %>
<div class="no_items">Oh snap! No items found...</span>
<% end %>
<div class="table">
<%= partial :'collections/rows_tree' %>
</div>

0 comments on commit d4692e1

Please sign in to comment.