Permalink
Browse files

Bumping an initial version

  • Loading branch information...
1 parent 4715716 commit 40b46d5281af31a70f0221c86a55e9c74b60b703 @robertomiranda committed Jul 25, 2012
Showing with 194 additions and 9 deletions.
  1. +5 −6 .gitignore
  2. +34 −0 .rvmrc
  3. +4 −0 Gemfile
  4. +22 −0 LICENSE
  5. +28 −3 README.md
  6. +2 −0 Rakefile
  7. +6 −0 lib/mini_mongo.rb
  8. +15 −0 lib/mini_mongo/base.rb
  9. +17 −0 lib/mini_mongo/connection.rb
  10. +38 −0 lib/mini_mongo/mapper.rb
  11. +3 −0 lib/mini_mongo/version.rb
  12. +20 −0 mini_mongo.gemspec
View
@@ -2,17 +2,16 @@
*.rbc
.bundle
.config
-coverage
+.yardoc
+Gemfile.lock
InstalledFiles
+_yardoc
+coverage
+doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
-
-# YARD artifacts
-.yardoc
-_yardoc
-doc/
View
@@ -0,0 +1,34 @@
+#!/usr/bin/env bash
+
+# This is an RVM Project .rvmrc file, used to automatically load the ruby
+# development environment upon cd'ing into the directory
+
+# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
+# Only full ruby name is supported here, for short names use:
+# echo "rvm use 1.9.2" > .rvmrc
+environment_id="ruby-1.9.2-p318@mini_mongo"
+
+# Uncomment the following lines if you want to verify rvm version per project
+# rvmrc_rvm_version="1.11.6" # 1.10.1 seams as a safe start
+# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
+# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
+# return 1
+# }
+
+# First we attempt to load the desired environment directly from the environment
+# file. This is very fast and efficient compared to running through the entire
+# CLI and selector. If you want feedback on which environment was used then
+# insert the word 'use' after --create as this triggers verbose mode.
+if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
+then
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
+else
+ # If the environment file has not yet been created, use the RVM CLI to select.
+ rvm --create "$environment_id" || {
+ echo "Failed to create RVM environment '${environment_id}'."
+ return 1
+ }
+fi
View
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in mini_mongo.gemspec
+gemspec
View
@@ -0,0 +1,22 @@
+Copyright (c) 2012 robertomiranda
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -1,4 +1,29 @@
-mini_mongo
-==========
+# MiniMongo
-Mini Mongo Mapper
+A Ruby Object Mapper for Mongo
+
+## Installation
+
+Add this line to your application's Gemfile:
+
+ gem 'mini_mongo'
+
+And then execute:
+
+ $ bundle
+
+Or install it yourself as:
+
+ $ gem install mini_mongo
+
+## Usage
+
+TODO: Write usage instructions here
+
+## Contributing
+
+1. Fork it
+2. Create your feature branch (`git checkout -b my-new-feature`)
+3. Commit your changes (`git commit -am 'Added some feature'`)
+4. Push to the branch (`git push origin my-new-feature`)
+5. Create new Pull Request
View
@@ -0,0 +1,2 @@
+#!/usr/bin/env rake
+require "bundler/gem_tasks"
View
@@ -0,0 +1,6 @@
+module MiniMongo
+ autoload :Connection, 'mini_mongo/connection'
+ autoload :Mapper, 'mini_mongo/mapper'
+ autoload :Base, 'mini_mongo/base'
+ extend Connection
+end
@@ -0,0 +1,15 @@
+require "json"
+class MiniMongo::Base
+ include MiniMongo::Mapper
+
+ def initialize(attrs = {})
+ attrs["id"] = attrs["_id"].to_s
+ attrs.delete("_id")
+ attrs.each do |key, value|
+ instance_variable_set("@#{key}", value)
+ self.instance_eval("def #{key};@#{key};end")
+ self.instance_eval("def #{key}=(val);@#{key}=val;end")
+ end
+ self.instance_eval("def to_json;#{attrs}.to_json;end")
+ end
+end
@@ -0,0 +1,17 @@
+require "uri"
+require "mongo"
+module MiniMongo
+ module Connection
+ def database_url=(url)
+ @@database_url = url
+ end
+
+ def db_connection
+ db = URI.parse(@@database_url)
+ db_name = db.path.gsub(/^\//, '')
+ @@db_connection ||= Mongo::Connection.new(db.host, db.port, :slave_ok => true).db(db_name)
+ @@db_connection.authenticate(db.user, db.password) if db.user && !db.user.empty?
+ @@db_connection
+ end
+ end
+end
@@ -0,0 +1,38 @@
+require "uri"
+require "mongo"
+module MiniMongo
+ module Mapper
+ def self.included(base)
+ base.send :extend, ClassMethods
+ end
+
+
+ module ClassMethods
+ def find(id, attrs={})
+ doc = @@collection.find("_id" => BSON::ObjectId(id)).to_a.first
+ self.class_eval("new(#{doc})")
+ end
+
+ def insert(attrs={})
+ doc = {}
+ doc["_id"] = @@collection.insert(attrs).to_s
+ doc.merge!(attrs)
+ self.class_eval("new(#{doc})")
+ end
+
+ def update(id, attrs={})
+ doc = @@collection.update({"_id" => BSON::ObjectId(id)}, attrs)
+ self.find(id)
+ end
+
+ def remove(id)
+ @@collection.remove("_id" => BSON::ObjectId(id))
+ end
+
+ def maps(name)
+ @@collection_name = name.to_s
+ @@collection = MiniMongo.db_connection.collection(name.to_s)
+ end
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module MiniMongo
+ VERSION = "0.0.1"
+end
View
@@ -0,0 +1,20 @@
+# -*- encoding: utf-8 -*-
+require File.expand_path('../lib/mini_mongo/version', __FILE__)
+
+Gem::Specification.new do |gem|
+ gem.authors = ["Roberto Miranda", "Guillermo Iguaran"]
+ gem.email = ["rjmaltamar@gmail.com", "guilleiguaran@gmail.com"]
+ gem.description = %q{Basics Object Mapper for Mongo}
+ gem.summary = %q{A Ruby Object Mapper for Mongo}
+ gem.homepage = "https://github.com/robertomiranda/mini_mongo"
+
+ gem.files = `git ls-files`.split($\)
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
+ gem.name = "mini_mongo"
+ gem.require_paths = ["lib"]
+ gem.version = MiniMongo::VERSION
+
+ gem.add_dependency "mongo", "~> 1.6.4"
+ gem.add_dependency "bson_ext", "~> 1.6.4"
+end

0 comments on commit 40b46d5

Please sign in to comment.