mongo_utils 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .rvmrc
2
+ Gemfile.lock
3
+ .rspec
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
6
+ - ruby-head
7
+ - rbx-master
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gemspec
4
+ gem 'rake'
5
+
6
+ group :test do
7
+ gem 'rspec'
8
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 Alex Sharp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.md ADDED
@@ -0,0 +1,6 @@
1
+ [![Build Status](http://travis-ci.org/ajsharp/mongo_utils.png)](http://travis-ci.org/ajsharp/mongo_utils)
2
+
3
+ ## Mongo Utils
4
+
5
+ This project is intended to be a collection of useful utilities for
6
+ working with MongoDB.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks :name => 'mongo_utils'
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,23 @@
1
+ module MongoUtils
2
+ module Aggregation
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+
7
+ # Groups by the created_at date by the interval passed in
8
+ #
9
+ # @param [Symbol] interval valid values are :month, :day and :year
10
+ # @return [Array] returns an array of Hashes, containing the keys
11
+ # "count" and the grouping name
12
+ def group_by_created_at(interval = :month)
13
+ interval = interval.to_s
14
+
15
+ collection.group(
16
+ :initial => {:count => 0},
17
+ :keyf => "function(d) { return {#{interval}: d.created_at.get#{interval.capitalize}() + 1} }",
18
+ :reduce => "function(doc, out) { out.count++; }"
19
+ )
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module MongoUtils
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.dirname(File.expand_path(__FILE__)))
2
+
3
+ module MongoUtils
4
+ autoload :Aggregation, 'mongo_utils/aggregation'
5
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'mongo_utils'
4
+ require "mongo_utils/version"
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mongo_utils"
8
+ s.version = MongoUtils::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Alex Sharp"]
11
+ s.email = ["ajsharp@gmail.com"]
12
+ s.homepage = "https://github.com/ajsharp/mongo_utils"
13
+ s.summary = %q{A collection of utilities for working with MongoDB.}
14
+ s.description = %q{A collection of utilities for working with MongoDB.}
15
+
16
+ s.rubyforge_project = "mongo_utils"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ s.add_dependency 'mongo', '~> 1.3.0'
24
+ s.add_dependency 'activesupport', '~> 3.0'
25
+ s.add_dependency 'mongoid', '~> 2.0'
26
+ s.add_dependency 'bson_ext'
27
+ end
@@ -0,0 +1,4 @@
1
+
2
+ class Person
3
+ include Mongoid::Document
4
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'mongo_utils/aggregation'
3
+
4
+ describe MongoUtils::Aggregation do
5
+ class Person
6
+ include MongoUtils::Aggregation
7
+ end
8
+
9
+ before { Person.collection.drop }
10
+
11
+ describe ".group_by_created_at" do
12
+ it 'adds a method' do
13
+ Person.should respond_to :group_by_created_at
14
+ end
15
+
16
+ it "groups by the created_at date" do
17
+ Time.stub!(:now => Time.new(2011, 11))
18
+ Person.create! :created_at => Time.now
19
+
20
+ Person.group_by_created_at.should == [{'month' => 11.0, 'count' => 1.0}]
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+
4
+ $:.unshift(File.dirname(File.expand_path(__FILE__)))
5
+
6
+ require File.join(File.dirname(File.expand_path(__FILE__)), "..", "lib", "mongo_utils")
7
+
8
+ require 'active_support'
9
+ require 'mongoid'
10
+
11
+ Mongoid.database = Mongo::Connection.new.db('mongo_utils_test')
12
+ Dir['spec/models/*'].each { |f| require File.expand_path(f) }
13
+
14
+ RSpec.configure do |c|
15
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Sharp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mongo
16
+ requirement: &70282811935040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70282811935040
25
+ - !ruby/object:Gem::Dependency
26
+ name: activesupport
27
+ requirement: &70282812067280 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70282812067280
36
+ - !ruby/object:Gem::Dependency
37
+ name: mongoid
38
+ requirement: &70282812065480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '2.0'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70282812065480
47
+ - !ruby/object:Gem::Dependency
48
+ name: bson_ext
49
+ requirement: &70282812062060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70282812062060
58
+ description: A collection of utilities for working with MongoDB.
59
+ email:
60
+ - ajsharp@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .travis.yml
67
+ - Gemfile
68
+ - MIT-LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - lib/mongo_utils.rb
72
+ - lib/mongo_utils/aggregation.rb
73
+ - lib/mongo_utils/version.rb
74
+ - mongo_utils.gemspec
75
+ - spec/models/person.rb
76
+ - spec/mongo_utils/aggregation_spec.rb
77
+ - spec/spec_helper.rb
78
+ homepage: https://github.com/ajsharp/mongo_utils
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project: mongo_utils
98
+ rubygems_version: 1.8.10
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: A collection of utilities for working with MongoDB.
102
+ test_files:
103
+ - spec/models/person.rb
104
+ - spec/mongo_utils/aggregation_spec.rb
105
+ - spec/spec_helper.rb