map_reduced 0.0.2 → 0.0.5
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/map_reduced.rb +2 -2
- data/lib/map_reduced/config.rb +6 -2
- data/lib/map_reduced/document.rb +14 -11
- metadata +4 -4
data/lib/map_reduced.rb
CHANGED
data/lib/map_reduced/config.rb
CHANGED
@@ -3,12 +3,16 @@ module MapReduced
|
|
3
3
|
class << self
|
4
4
|
|
5
5
|
attr_writer :template_path
|
6
|
-
attr_reader :db
|
7
6
|
|
8
|
-
def database(string)
|
7
|
+
def database=(string)
|
9
8
|
@db = Mongo::Connection.new.db(string)
|
10
9
|
end
|
11
10
|
|
11
|
+
def db
|
12
|
+
warn "Tell MapReduced which database to use, like this:\nMapReduced::Config.database = 'my_awesome_database'" unless defined? @db
|
13
|
+
@db
|
14
|
+
end
|
15
|
+
|
12
16
|
def template_path
|
13
17
|
return @template_path if defined?(@template_path)
|
14
18
|
defined?(Rails) ? Rails.root + "app/functions" : Pathname.new(File.expand_path("./functions"))
|
data/lib/map_reduced/document.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
module MapReduced
|
2
2
|
module Document
|
3
3
|
module ClassMethods
|
4
|
-
@@added_functions = []
|
5
4
|
def map_reduce(*names)
|
6
5
|
names.each do |name|
|
7
6
|
self.class_eval %Q{
|
8
|
-
def self.run_#{name}
|
7
|
+
def self.run_#{name}(opts = {})
|
9
8
|
begin
|
10
9
|
setup_functions
|
11
|
-
collection.map_reduce(map("#{name}"), reduce("#{name}"))
|
10
|
+
collection.map_reduce(map("#{name}"), reduce("#{name}"), opts)
|
12
11
|
ensure
|
13
12
|
teardown_functions
|
14
13
|
end
|
@@ -25,18 +24,22 @@ module MapReduced
|
|
25
24
|
db.collection(collection_name)
|
26
25
|
end
|
27
26
|
|
27
|
+
def collection_name=(name)
|
28
|
+
@collection_name = name
|
29
|
+
end
|
30
|
+
|
28
31
|
def use_functions(*names)
|
29
|
-
|
32
|
+
@added_functions = names
|
30
33
|
end
|
31
34
|
|
32
35
|
private
|
33
36
|
|
34
|
-
def
|
35
|
-
|
37
|
+
def added_functions
|
38
|
+
@added_functions ||= []
|
36
39
|
end
|
37
|
-
|
38
|
-
def collection_name
|
39
|
-
|
40
|
+
|
41
|
+
def collection_name
|
42
|
+
@collection_name ||= "#{self.to_s.downcase}s"
|
40
43
|
end
|
41
44
|
|
42
45
|
def map(function)
|
@@ -48,13 +51,13 @@ module MapReduced
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def setup_functions
|
51
|
-
|
54
|
+
added_functions.each do |function_name|
|
52
55
|
db.add_stored_function(function_name.to_s, function_string(function_name))
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
56
59
|
def teardown_functions
|
57
|
-
|
60
|
+
added_functions.each {|name| db.remove_stored_function(name.to_s)}
|
58
61
|
end
|
59
62
|
|
60
63
|
def function_string(name)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: map_reduced
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Scott Burton
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-09-05 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|