Skip to content

Commit

Permalink
Renaming to something fake and less offensive
Browse files Browse the repository at this point in the history
  • Loading branch information
durran committed Sep 16, 2009
1 parent 8258af2 commit 0d36672
Show file tree
Hide file tree
Showing 19 changed files with 120 additions and 117 deletions.
18 changes: 9 additions & 9 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h2>Overview</h2>

<h3>About Mongoloid</h3>
<h3>About Mongoid</h3>

<p>
Mongoloid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby. MongoDB differs from other
Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby. MongoDB differs from other
mapping frameworks in that it constrains the models into behaving in a manner appropriate for a
document database. That is to say there are no relationships between documents in the underlying datastore.
If a relationship is set up in the Model the child models are automatically embedded within the parent document
Expand All @@ -15,26 +15,26 @@

<h3>Project Tracking</h3>

<a href="http://www.pivotaltracker.com/projects/27482">Mongoloid on Pivotal Tracker</a>
<a href="http://www.pivotaltracker.com/projects/27482">Mongoid on Pivotal Tracker</a>

<h2>Mongoloid in Action</h2>
<h2>Mongoid in Action</h2>

Initialize Mongoloid:
Initialize Mongoid:

<pre>
Mongoloid.connect_to("myapp_database_name")
Mongoid.connect_to("myapp_database_name")
</pre>

Example of a simple domain model:

<pre>
class Person < Mongoloid::Document
class Person < Mongoid::Document
fields :title
has_many :addresses
has_one :name
end

class Address < Mongoloid::Document
class Address < Mongoid::Document
fields \
:street,
:city,
Expand All @@ -43,7 +43,7 @@ Example of a simple domain model:
belongs_to :person
end

class Name < Mongoloid::Document
class Name < Mongoid::Document
fields \
:first_name,
:last_name
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ require "metric_fu"
begin
require "jeweler"
Jeweler::Tasks.new do |gem|
gem.name = "mongoloid"
gem.summary = %Q{Mongoloid}
gem.name = "mongoid"
gem.summary = %Q{Mongoid}
gem.email = "durran@gmail.com"
gem.homepage = "http://github.com/durran/mongoloid"
gem.homepage = "http://github.com/durran/mongoid"
gem.authors = ["Durran Jordan"]
gem.add_dependency "active_support"
gem.add_dependency "mongodb-mongo"
Expand Down
16 changes: 8 additions & 8 deletions lib/mongoloid.rb → lib/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
require "activesupport"
require "delegate"
require "mongo"
require "mongoloid/associations/association_factory"
require "mongoloid/associations/belongs_to_association"
require "mongoloid/associations/has_many_association"
require "mongoloid/associations/has_one_association"
require "mongoloid/document"
require "mongoloid/paginator"
require "mongoid/associations/association_factory"
require "mongoid/associations/belongs_to_association"
require "mongoid/associations/has_many_association"
require "mongoid/associations/has_one_association"
require "mongoid/document"
require "mongoid/paginator"

module Mongoloid
module Mongoid

# Thrown when the database connection has not been set up.
class NoConnectionError < RuntimeError
Expand Down Expand Up @@ -41,7 +41,7 @@ def self.connect_to(name)
@@database ||= @@connection.db(name)
end

# Get the MongoDB database. If initialization via Mongoloid.connect_to()
# Get the MongoDB database. If initialization via Mongoid.connect_to()
# has not happened, an exception will occur.
def self.database
raise NoConnectionError unless @@database
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
module Associations
class AssociationFactory

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
module Associations
class BelongsToAssociation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
module Associations
class HasManyAssociation < DelegateClass(Array)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
module Associations
class HasOneAssociation

Expand Down
10 changes: 5 additions & 5 deletions lib/mongoloid/document.rb → lib/mongoid/document.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
class Document

attr_reader :attributes, :parent
Expand All @@ -13,7 +13,7 @@ def belongs_to(association_name)
# Get the XGen::Mongo::Collection associated with this Document.
def collection
@collection_name = self.to_s.demodulize.tableize
@collection ||= Mongoloid.database.collection(@collection_name)
@collection ||= Mongoid.database.collection(@collection_name)
end

# Create a new Document with the supplied attribtues, and insert it into the database.
Expand Down Expand Up @@ -68,7 +68,7 @@ def has_one(association_name)
# Find all documents in paginated fashion given the supplied arguments.
# If no parameters are passed just default to offset 0 and limit 20.
def paginate(selector = nil, params = {})
collection.find(selector, Mongoloid::Paginator.new(params).options).collect { |doc| new(doc) }
collection.find(selector, Mongoid::Paginator.new(params).options).collect { |doc| new(doc) }
end

end
Expand Down Expand Up @@ -123,10 +123,10 @@ class << self
# then adds the accessors for the association.
def add_association(type, class_name, name)
define_method(name) do
Mongoloid::Associations::AssociationFactory.create(type, name, self)
Mongoid::Associations::AssociationFactory.create(type, name, self)
end
define_method("#{name}=") do |object|
Mongoloid::Associations::AssociationFactory.create(type, name, object)
Mongoid::Associations::AssociationFactory.create(type, name, object)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/mongoloid/paginator.rb → lib/mongoid/paginator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Mongoloid
module Mongoid
class Paginator

attr_reader :limit, :offset
Expand Down
29 changes: 16 additions & 13 deletions mongoloid.gemspec → mongoid.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{mongoloid}
s.name = %q{mongoid}
s.version = "0.0.1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Durran Jordan"]
s.date = %q{2009-09-05}
s.date = %q{2009-09-16}
s.email = %q{durran@gmail.com}
s.extra_rdoc_files = [
"README.textile"
Expand All @@ -21,32 +21,35 @@ Gem::Specification.new do |s|
"Rakefile",
"VERSION",
"lib/mongoloid.rb",
"lib/mongoloid/association.rb",
"lib/mongoloid/association_factory.rb",
"lib/mongoloid/associations/association_factory.rb",
"lib/mongoloid/associations/belongs_to_association.rb",
"lib/mongoloid/associations/has_many_association.rb",
"lib/mongoloid/associations/has_one_association.rb",
"lib/mongoloid/document.rb",
"lib/mongoloid/document_factory.rb",
"lib/mongoloid/paginator.rb",
"mongoloid.gemspec",
"spec/integration/mongoloid/document_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb",
"spec/unit/mongoloid/association_factory_spec.rb",
"spec/unit/mongoloid/association_spec.rb",
"spec/unit/mongoloid/document_factory_spec.rb",
"spec/unit/mongoloid/associations/association_factory_spec.rb",
"spec/unit/mongoloid/associations/belongs_to_association_spec.rb",
"spec/unit/mongoloid/associations/has_many_association_spec.rb",
"spec/unit/mongoloid/associations/has_one_association_spec.rb",
"spec/unit/mongoloid/document_spec.rb",
"spec/unit/mongoloid/paginator_spec.rb"
]
s.homepage = %q{http://github.com/durran/mongoloid}
s.homepage = %q{http://github.com/durran/mongoid}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{Mongoloid}
s.summary = %q{Mongoid}
s.test_files = [
"spec/integration/mongoloid/document_spec.rb",
"spec/spec_helper.rb",
"spec/unit/mongoloid/association_factory_spec.rb",
"spec/unit/mongoloid/association_spec.rb",
"spec/unit/mongoloid/document_factory_spec.rb",
"spec/unit/mongoloid/associations/association_factory_spec.rb",
"spec/unit/mongoloid/associations/belongs_to_association_spec.rb",
"spec/unit/mongoloid/associations/has_many_association_spec.rb",
"spec/unit/mongoloid/associations/has_one_association_spec.rb",
"spec/unit/mongoloid/document_spec.rb",
"spec/unit/mongoloid/paginator_spec.rb"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require File.join(File.dirname(__FILE__), "/../../spec_helper.rb")

describe Mongoloid::Document do
describe Mongoid::Document do

before do
Mongoloid.database.collection(:people).drop
Mongoid.database.collection(:people).drop
end

describe "#new" do
Expand Down
10 changes: 5 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
gem "mocha", "0.9.7"

require "mocha"
require "mongoloid"
require "mongoid"
require "spec"

Mongoloid.connect_to("mongoloid_test")
Mongoid.connect_to("mongoid_test")

Spec::Runner.configure do |config|
config.mock_with :mocha
end

class Person < Mongoloid::Document
class Person < Mongoid::Document
fields :title
has_many :addresses
has_one :name
end

class Address < Mongoloid::Document
class Address < Mongoid::Document
fields \
:street,
:city,
Expand All @@ -29,7 +29,7 @@ class Address < Mongoloid::Document
belongs_to :person
end

class Name < Mongoloid::Document
class Name < Mongoid::Document
fields \
:first_name,
:last_name
Expand Down
48 changes: 48 additions & 0 deletions spec/unit/mongoid/associations/association_factory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require File.join(File.dirname(__FILE__), "/../../../spec_helper.rb")

describe Mongoid::Associations::AssociationFactory do

describe "#create" do

before do
@document = Person.new
end

context "when type is has_many" do

it "returns a HasManyAssociationProxy" do
association = Mongoid::Associations::AssociationFactory.create(:has_many, :addresses, @document)
association.should be_a_kind_of(Mongoid::Associations::HasManyAssociation)
end

end

context "when type is has_one" do

it "returns a HashOneAssociationProxy" do
association = Mongoid::Associations::AssociationFactory.create(:has_one, :name, @document)
association.should be_a_kind_of(Mongoid::Associations::HasOneAssociation)
end

end

context "when type is belongs_to" do

it "returns a BelongsToAssociationProxy" do
association = Mongoid::Associations::AssociationFactory.create(:belongs_to, :person, @document)
association.should be_a_kind_of(Mongoid::Associations::BelongsToAssociation)
end

end

context "when type is invalid" do

it "should raise a InvalidAssociationError" do
lambda { Mongoid::Associations::AssociationFactory.create(:something, :person, @document) }.should raise_error
end

end

end

end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.join(File.dirname(__FILE__), "/../../../spec_helper.rb")

describe Mongoloid::Associations::BelongsToAssociation do
describe Mongoid::Associations::BelongsToAssociation do

before do
@parent = Name.new(:first_name => "Drexel")
Expand All @@ -10,7 +10,7 @@
describe "#method_missing" do

before do
@association = Mongoloid::Associations::BelongsToAssociation.new(@document)
@association = Mongoid::Associations::BelongsToAssociation.new(@document)
end

context "when getting values" do
Expand Down
Loading

0 comments on commit 0d36672

Please sign in to comment.