humongous 0.1.9.beta → 0.2.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.
data/lib/humongous.rb CHANGED
@@ -3,6 +3,7 @@ require "sinatra/base"
3
3
  require "mongo"
4
4
  require "json"
5
5
  require 'humongous/monkey_patch'
6
+ require 'humongous/helpers'
6
7
  require 'humongous/application'
7
8
  require 'humongous/version'
8
9
 
@@ -1,4 +1,3 @@
1
- # require './monkey_patch'
2
1
  module Humongous
3
2
 
4
3
  MonkeyPatch.activate!
@@ -39,81 +38,7 @@ module Humongous
39
38
  end
40
39
 
41
40
  helpers do
42
-
43
- def connection(params)
44
- opts = opts_to_connect(params)
45
- session[:connection] ||= Mongo::Connection.new(opts[:url], opts[:port])
46
- end
47
-
48
- def autanticate!
49
- @connection.apply_saved_authentication and return unless @connection.auths.blank?
50
- return if params[:auth].blank?
51
- @connection.add_auth(params[:auth][:db], params[:auth][:username], params[:auth][:password])
52
- @connection.apply_saved_authentication
53
- end
54
-
55
- def opts_to_connect(params = {})
56
- return @options if @options && @options[:freeze]
57
- @options = DEFAULT_OPTIONS
58
- return @options if params.blank?
59
- @options[:url] = params[:url]
60
- @options[:port] = params[:port]
61
- @options[:freeze] = true
62
- @options
63
- end
64
-
65
- def get_uri(params = {})
66
- @options = DEFAULT_OPTIONS
67
- @options = @options.merge(params)
68
- unless @options[:username].empty? && @options[:password].empty?
69
- "mongodb://#{@options[:username]}:#{@options[:password]}@#{@options[:url]}:#{@options[:port]}"
70
- else
71
- "mongodb://#{@options[:url]}:#{@options[:port]}"
72
- end
73
- end
74
-
75
- def default_opts
76
- { :skip => 0, :limit => 10 }
77
- end
78
-
79
- def to_bson( options )
80
- ids = options.keys.grep /_id$/
81
- ids.each do |id|
82
- begin
83
- options[id] = BSON::ObjectId.from_string(options[id])
84
- rescue BSON::InvalidObjectId
85
- puts "found illegal ObjectId, skipping..."
86
- next
87
- rescue e
88
- puts e.message
89
- end
90
- end
91
- options
92
- end
93
-
94
- def doc_to_bson( doc, converter )
95
- doc = send(converter, doc)
96
- doc.each do |k,v|
97
- case v
98
- when Hash
99
- send(converter, v )
100
- end
101
- end
102
- doc
103
- end
104
-
105
- def from_bson( options )
106
- ids = options.select{ |k,v| v.is_a? BSON::ObjectId }
107
- ids.each do | k, v |
108
- options[k] = v.to_s
109
- end
110
- options
111
- end
112
-
113
- def json_converter( params_json )
114
- params_json.gsub(/(\w+):/, '"\1":')
115
- end
116
-
41
+ include Humongous::Helpers::SinatraHelpers
117
42
  end
118
43
 
119
44
  reciever = lambda do
@@ -228,6 +153,19 @@ module Humongous
228
153
  content_type :json
229
154
  { :created => created, :id => true, :status => "OK" }.to_json
230
155
  end
156
+
157
+ post "/database/:database_name/collection/:collection_name/mapreduce" do
158
+ opts = { :out => { :inline => true }, :raw => true }
159
+ opts[:finalize] = params[:finalize] unless params[:finalize].blank?
160
+ opts[:out] = params[:out] unless params[:out].blank?
161
+ opts[:query] = JSON.parse(json_converter(params[:query])) unless params[:query].blank?
162
+ opts[:sort] = params[:sort] unless params[:sort].blank?
163
+ opts[:limit] = params[:limit] unless params[:limit].blank?
164
+ @database = @connection.db(params[:database_name])
165
+ @collection = @database.collection(params[:collection_name])
166
+ content_type :json
167
+ @collection.map_reduce( params[:map], params[:reduce], opts ).to_json
168
+ end
231
169
 
232
170
  end
233
171
 
@@ -0,0 +1,93 @@
1
+ module Humongous
2
+ module Helpers
3
+
4
+ module SinatraHelpers
5
+
6
+ def connection(params)
7
+ opts = opts_to_connect(params)
8
+ session[:connection] ||= Mongo::Connection.new(opts[:url], opts[:port])
9
+ end
10
+
11
+ def autanticate!
12
+ @connection.apply_saved_authentication and return unless @connection.auths.blank?
13
+ return if params[:auth].blank?
14
+ @connection.add_auth(params[:auth][:db], params[:auth][:username], params[:auth][:password])
15
+ @connection.apply_saved_authentication
16
+ end
17
+
18
+ def opts_to_connect(params = {})
19
+ return @options if @options && @options[:freeze]
20
+ @options = {
21
+ :url => "localhost",
22
+ :port => "27017",
23
+ :username => "",
24
+ :password => ""
25
+ }
26
+ return @options if params.blank?
27
+ @options[:url] = params[:url]
28
+ @options[:port] = params[:port]
29
+ @options[:freeze] = true
30
+ @options
31
+ end
32
+
33
+ def get_uri(params = {})
34
+ @options = {
35
+ :url => "localhost",
36
+ :port => "27017",
37
+ :username => "",
38
+ :password => ""
39
+ }
40
+ @options = @options.merge(params)
41
+ unless @options[:username].empty? && @options[:password].empty?
42
+ "mongodb://#{@options[:username]}:#{@options[:password]}@#{@options[:url]}:#{@options[:port]}"
43
+ else
44
+ "mongodb://#{@options[:url]}:#{@options[:port]}"
45
+ end
46
+ end
47
+
48
+ def default_opts
49
+ { :skip => 0, :limit => 10 }
50
+ end
51
+
52
+ def to_bson( options )
53
+ ids = options.keys.grep /_id$/
54
+ ids.each do |id|
55
+ begin
56
+ options[id] = BSON::ObjectId.from_string(options[id])
57
+ rescue BSON::InvalidObjectId
58
+ puts "found illegal ObjectId, skipping..."
59
+ next
60
+ rescue e
61
+ puts e.message
62
+ end
63
+ end
64
+ options
65
+ end
66
+
67
+ def doc_to_bson( doc, converter )
68
+ doc = send(converter, doc)
69
+ doc.each do |k,v|
70
+ case v
71
+ when Hash
72
+ send(converter, v )
73
+ end
74
+ end
75
+ doc
76
+ end
77
+
78
+ def from_bson( options )
79
+ ids = options.select{ |k,v| v.is_a? BSON::ObjectId }
80
+ ids.each do | k, v |
81
+ options[k] = v.to_s
82
+ end
83
+ options
84
+ end
85
+
86
+ def json_converter( params_json )
87
+ params_json.gsub(/(\w+):/, '"\1":')
88
+ end
89
+
90
+ end
91
+
92
+ end
93
+ end
@@ -7,6 +7,7 @@ app.helpers = {};
7
7
  app.isObject = function (value) {
8
8
  return Object.prototype.toString.call(value) == "[object Object]";
9
9
  };
10
+ app.isArray = $.isArray;
10
11
  //adding storage event
11
12
  $( document ).bind( 'storage', function( e, action, on, values ){
12
13
  console.log(arguments);
@@ -51,7 +51,7 @@ app.html.query_browser = {
51
51
  { tag: "LI", cls: "active", child: { tag: "A", href: "#", text: "Find", show: "find_form" }, onClick: this._pills_click_handler },
52
52
  { tag: "LI", child: { tag: "A", href: "#", text: "Remove", show: "remove_form" }, onClick: this._pills_click_handler },
53
53
  { tag: "LI", child: { tag: "A", href: "#", text: "Insert", show: "insert_form" }, onClick: this._pills_click_handler },
54
- // { tag: "LI", child: { tag: "A", href: "#", text: "MapReduce", show: "mapreduce_form" }, onClick: this._pills_click_handler }
54
+ { tag: "LI", child: { tag: "A", href: "#", text: "MapReduce", show: "mapreduce_form" }, onClick: this._pills_click_handler }
55
55
  ]}
56
56
  )
57
57
  },
@@ -277,8 +277,68 @@ app.query_forms = {
277
277
  }
278
278
  });
279
279
  }
280
- }//,
281
- // mapreduce_form: {
282
- // tag: "DIV", cls: "mapreduce_form", text: "mapreduce_form"
283
- // },
280
+ },
281
+ mapreduce_form: { tag: "FORM", cls: "mapreduce_form", children:
282
+ [
283
+ { tag: "FIELDSET", children: [
284
+ // this._get_legend(),
285
+ { tag: "DIV", cls: "input_row", children: [
286
+ { tag: "DIV", cls: "map_form", children: [
287
+ { tag: "LABEL", "for": "map", text: "Map" },
288
+ { tag: "TEXTAREA", style: "height: 100px; width: 150px", type: "text", placeholder: "Map function", id: "map", size: "41", name: "map" }
289
+ ] },
290
+ { tag: "DIV", cls: "reduce_form", children: [
291
+ { tag: "LABEL", "for": "reduce", text: "Reduce" },
292
+ { tag: "TEXTAREA", type: "text", style: "height: 100px; width: 150px", placeholder: "Reduce function", id: "reduce", name: "reduce" }
293
+ ] },
294
+ { tag: "DIV", cls: "finalize_form", children: [
295
+ { tag: "LABEL", "for": "finalize", text: "Finalize" },
296
+ { tag: "TEXTAREA", type: "text", style: "height: 100px; width: 150px", placeholder: "Finalize function", id: "finalize", name: "finalize" }
297
+ ] },
298
+ { tag: "DIV", cls: "clear" }
299
+ ] },
300
+ // { tag: "DIV", cls: "clear" },
301
+ { tag: "DIV", cls: "input_row", children: [
302
+ { tag: "DIV", cls: "query_form", children: [
303
+ { tag: "LABEL", "for": "query", text: "Query" },
304
+ { tag: "INPUT", type: "text", placeholder: "Find All", id: "query", size: "20", name: "query" }
305
+ ] },
306
+ { tag: "DIV", cls: "sort_form", children: [
307
+ { tag: "LABEL", "for": "sort", text: "Sort" },
308
+ { tag: "INPUT", type: "text", placeholder: "[\"name\", \"asc\"]", id: "sort", size: "15", name: "sort" }
309
+ ] },
310
+ { tag: "DIV", cls: "limit_form", children: [
311
+ { tag: "LABEL", "for": "limit", text: "Limit" },
312
+ { tag: "INPUT", type: "text", placeholder: "10", id: "limit", size: "5", name: "limit", value: "10", cls: 'number' }
313
+ ] },
314
+ { tag: "DIV", cls: "out_form", children: [
315
+ { tag: "LABEL", "for": "out", text: "Out" },
316
+ { tag: "INPUT", type: "text", placeholder: "{inline: 1}", id: "out", size: "5", name: "out", cls: 'number' }
317
+ ] },
318
+ { tag: "INPUT", type: 'submit', cls: "submit_btn btn", value: "Search" },
319
+ { tag: "DIV", cls: "clear" }
320
+ ] }
321
+ ] }
322
+ ], onSubmit: function(e){
323
+ e.preventDefault();
324
+ app.ax({
325
+ url: "/database/" + app.storage.get("database") + "/collection/" + app.storage.get("collection") + "/mapreduce",
326
+ data: $(this).serialize(),
327
+ type: $(this).attr("method"),
328
+ success: function( data ){
329
+ console.log(data);
330
+ $( ".query_result" ).children().remove();
331
+ if(app.isArray( data.results )){
332
+ $( app.html.build_results.create( data.results ) ).appendTo( '.query_result' );
333
+ }else{
334
+ var alert = { tag: "DIV", cls: "alert-message success fade in", "data-alert": "true", children: [
335
+ { tag: "A", cls: "close", href: "#", text: "x" },
336
+ { tag: "P", text: "Query ran successfully. Output is saved in " + data.result + "document." }
337
+ ] };
338
+ $( alert ).appendTo( '.query_result' );
339
+ }
340
+ }
341
+ });
342
+ }
343
+ }
284
344
  }
@@ -55,10 +55,10 @@ body {
55
55
  label{
56
56
  width: auto;
57
57
  }
58
- .query_form, .sort_form, .skip_form, .fields_form, .limit_form, .submit_btn{
58
+ .query_form, .sort_form, .skip_form, .fields_form, .limit_form, .submit_btn, .map_form, .reduce_form, .finalize_form, .out_form{
59
59
  float: left;
60
60
  }
61
- input{
61
+ input, textarea{
62
62
  margin: 0px 10px 0px 5px;
63
63
  width: auto;
64
64
  }
@@ -1,3 +1,3 @@
1
1
  module Humongous
2
- VERSION = "0.1.9.beta"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,118 +1,87 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: humongous
3
- version: !ruby/object:Gem::Version
4
- hash: 1605700641
5
- prerelease: 6
6
- segments:
7
- - 0
8
- - 1
9
- - 9
10
- - beta
11
- version: 0.1.9.beta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
12
6
  platform: ruby
13
- authors:
7
+ authors:
14
8
  - bagwanpankaj
15
9
  autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2012-01-21 00:00:00 Z
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2012-02-20 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: vegas
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152825240 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - "="
28
- - !ruby/object:Gem::Version
29
- hash: 11
30
- segments:
31
- - 0
32
- - 1
33
- - 8
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
34
21
  version: 0.1.8
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: sinatra
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152825240
25
+ - !ruby/object:Gem::Dependency
26
+ name: sinatra
27
+ requirement: &2152824760 !ruby/object:Gem::Requirement
41
28
  none: false
42
- requirements:
43
- - - "="
44
- - !ruby/object:Gem::Version
45
- hash: 31
46
- segments:
47
- - 1
48
- - 3
49
- - 2
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
50
32
  version: 1.3.2
51
33
  type: :runtime
52
- version_requirements: *id002
53
- - !ruby/object:Gem::Dependency
54
- name: bson_ext
55
34
  prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152824760
36
+ - !ruby/object:Gem::Dependency
37
+ name: bson_ext
38
+ requirement: &2152824280 !ruby/object:Gem::Requirement
57
39
  none: false
58
- requirements:
59
- - - "="
60
- - !ruby/object:Gem::Version
61
- hash: 7
62
- segments:
63
- - 1
64
- - 5
65
- - 2
40
+ requirements:
41
+ - - =
42
+ - !ruby/object:Gem::Version
66
43
  version: 1.5.2
67
44
  type: :runtime
68
- version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: mongo
71
45
  prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2152824280
47
+ - !ruby/object:Gem::Dependency
48
+ name: mongo
49
+ requirement: &2152823800 !ruby/object:Gem::Requirement
73
50
  none: false
74
- requirements:
75
- - - "="
76
- - !ruby/object:Gem::Version
77
- hash: 7
78
- segments:
79
- - 1
80
- - 5
81
- - 2
51
+ requirements:
52
+ - - =
53
+ - !ruby/object:Gem::Version
82
54
  version: 1.5.2
83
55
  type: :runtime
84
- version_requirements: *id004
85
- - !ruby/object:Gem::Dependency
86
- name: json
87
56
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2152823800
58
+ - !ruby/object:Gem::Dependency
59
+ name: json
60
+ requirement: &2152823320 !ruby/object:Gem::Requirement
89
61
  none: false
90
- requirements:
91
- - - "="
92
- - !ruby/object:Gem::Version
93
- hash: 5
94
- segments:
95
- - 1
96
- - 6
97
- - 5
62
+ requirements:
63
+ - - =
64
+ - !ruby/object:Gem::Version
98
65
  version: 1.6.5
99
66
  type: :runtime
100
- version_requirements: *id005
101
- description: "Humongous: A Ruby way to browse and maintain mongo instance. Using HTML5."
67
+ prerelease: false
68
+ version_requirements: *2152823320
69
+ description: ! 'Humongous: A Ruby way to browse and maintain mongo instance. Using
70
+ HTML5.'
102
71
  email: bagwanpankaj@gmail.com
103
- executables:
72
+ executables:
104
73
  - humongous
105
74
  extensions: []
106
-
107
- extra_rdoc_files:
75
+ extra_rdoc_files:
108
76
  - LICENSE.txt
109
77
  - README.markdown
110
- files:
78
+ files:
111
79
  - LICENSE.txt
112
80
  - bin/humongous
113
81
  - lib/humongous.rb
114
82
  - lib/humongous/version.rb
115
83
  - lib/humongous/monkey_patch.rb
84
+ - lib/humongous/helpers.rb
116
85
  - lib/humongous/application.rb
117
86
  - lib/humongous/public/images/favicon.ico
118
87
  - lib/humongous/public/images/ajax-loader.gif
@@ -128,42 +97,29 @@ files:
128
97
  - lib/humongous/views/index.erb
129
98
  - README.markdown
130
99
  homepage: http://github.com/bagwanpankaj/humongous
131
- licenses:
100
+ licenses:
132
101
  - MIT
133
102
  post_install_message:
134
103
  rdoc_options: []
135
-
136
- require_paths:
104
+ require_paths:
137
105
  - lib
138
- required_ruby_version: !ruby/object:Gem::Requirement
106
+ required_ruby_version: !ruby/object:Gem::Requirement
139
107
  none: false
140
- requirements:
141
- - - ">="
142
- - !ruby/object:Gem::Version
143
- hash: 57
144
- segments:
145
- - 1
146
- - 8
147
- - 7
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
148
111
  version: 1.8.7
149
- required_rubygems_version: !ruby/object:Gem::Requirement
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
113
  none: false
151
- requirements:
152
- - - ">"
153
- - !ruby/object:Gem::Version
154
- hash: 25
155
- segments:
156
- - 1
157
- - 3
158
- - 1
114
+ requirements:
115
+ - - ! '>'
116
+ - !ruby/object:Gem::Version
159
117
  version: 1.3.1
160
118
  requirements: []
161
-
162
119
  rubyforge_project:
163
120
  rubygems_version: 1.8.10
164
121
  signing_key:
165
122
  specification_version: 3
166
- summary: "Humongous: A Mongo Browser for Ruby"
123
+ summary: ! 'Humongous: A Mongo Browser for Ruby'
167
124
  test_files: []
168
-
169
125
  has_rdoc: