mini_mongo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rvmrc +34 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/mini_mongo/base.rb +13 -0
- data/lib/mini_mongo/connection.rb +17 -0
- data/lib/mini_mongo/mapper.rb +36 -0
- data/lib/mini_mongo/version.rb +3 -0
- data/lib/mini_mongo.rb +6 -0
- data/mini_mongo.gemspec +20 -0
- metadata +91 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.2" > .rvmrc
|
9
|
+
environment_id="ruby-1.9.2-p318@mini_mongo"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.11.6" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 robertomiranda
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# MiniMongo
|
2
|
+
|
3
|
+
A Ruby Object Mapper for Mongo
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mini_mongo'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mini_mongo
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class MiniMongo::Base
|
2
|
+
include MiniMongo::Mapper
|
3
|
+
|
4
|
+
def initialize(attrs = {})
|
5
|
+
attrs["id"] = attrs["_id"].to_s
|
6
|
+
attrs.delete("_id")
|
7
|
+
attrs.each do |key, value|
|
8
|
+
instance_variable_set("@#{key}", value)
|
9
|
+
self.instance_eval("def #{key};@#{key};end")
|
10
|
+
self.instance_eval("def #{key}=(val);@#{key}=val;end")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "mongo"
|
3
|
+
module MiniMongo
|
4
|
+
module Connection
|
5
|
+
def database_url=(url)
|
6
|
+
@@database_url = url
|
7
|
+
end
|
8
|
+
|
9
|
+
def db_connection
|
10
|
+
db = URI.parse(@@database_url)
|
11
|
+
db_name = db.path.gsub(/^\//, '')
|
12
|
+
@@db_connection ||= Mongo::Connection.new(db.host, db.port, :slave_ok => true).db(db_name)
|
13
|
+
@@db_connection.authenticate(db.user, db.password) if db.user && !db.user.empty?
|
14
|
+
@@db_connection
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "mongo"
|
3
|
+
module MiniMongo
|
4
|
+
module Mapper
|
5
|
+
def self.included(base)
|
6
|
+
base.send :extend, ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def find(id, attrs={})
|
12
|
+
doc = @@collection.find("_id" => BSON::ObjectId(id))
|
13
|
+
self.class_eval("new(#{doc})")
|
14
|
+
end
|
15
|
+
|
16
|
+
def insert(attrs={})
|
17
|
+
doc = @@collection.insert(attrs)
|
18
|
+
self.class_eval("new(#{doc})")
|
19
|
+
end
|
20
|
+
|
21
|
+
def update(id, attrs={})
|
22
|
+
doc = @@collection.update({"_id" => BSON::ObjectId(id)}, attrs)
|
23
|
+
self.class_eval("new(#{doc})")
|
24
|
+
end
|
25
|
+
|
26
|
+
def remove(id)
|
27
|
+
@@collection.remove("_id" => BSON::ObjectId(id))
|
28
|
+
end
|
29
|
+
|
30
|
+
def maps(name)
|
31
|
+
@@collection_name = name.to_s
|
32
|
+
@@collection = MiniMogo.db_connection.collection(name.to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mini_mongo.rb
ADDED
data/mini_mongo.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/mini_mongo/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Roberto Miranda", "Guillermo Iguaran"]
|
6
|
+
gem.email = ["rjmaltamar@gmail.com", "guilleiguaran@gmail.com"]
|
7
|
+
gem.description = %q{Basics Object Mapper for Mongo}
|
8
|
+
gem.summary = %q{A Ruby Object Mapper for Mongo}
|
9
|
+
gem.homepage = "https://github.com/robertomiranda/mini_mongo"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "mini_mongo"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = MiniMongo::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "mongo", "~> 1.6.4"
|
19
|
+
gem.add_dependency "bson_ext", "~> 1.6.4"
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mini_mongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roberto Miranda
|
9
|
+
- Guillermo Iguaran
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-07-25 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mongo
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.6.4
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 1.6.4
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bson_ext
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.6.4
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.6.4
|
47
|
+
description: Basics Object Mapper for Mongo
|
48
|
+
email:
|
49
|
+
- rjmaltamar@gmail.com
|
50
|
+
- guilleiguaran@gmail.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .gitignore
|
56
|
+
- .rvmrc
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- lib/mini_mongo.rb
|
62
|
+
- lib/mini_mongo/base.rb
|
63
|
+
- lib/mini_mongo/connection.rb
|
64
|
+
- lib/mini_mongo/mapper.rb
|
65
|
+
- lib/mini_mongo/version.rb
|
66
|
+
- mini_mongo.gemspec
|
67
|
+
homepage: https://github.com/robertomiranda/mini_mongo
|
68
|
+
licenses: []
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 1.8.21
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: A Ruby Object Mapper for Mongo
|
91
|
+
test_files: []
|