Skip to content
Browse files

Skeleton for the tenacity gem

  • Loading branch information...
1 parent ef5b389 commit 5948beb8937e593ce5bc472e004ee3387af4a852 @jwood committed
Showing with 148 additions and 0 deletions.
  1. +25 −0 .gemspec
  2. +3 −0 .gitignore
  3. +4 −0 Gemfile
  4. +10 −0 Gemfile.lock
  5. +63 −0 README.rdoc
  6. +24 −0 Rakefile
  7. +4 −0 lib/tenacity.rb
  8. +10 −0 test/relationships_test.rb
  9. +5 −0 test/test_helper.rb
View
25 .gemspec
@@ -0,0 +1,25 @@
+# coding: utf-8
+lib = File.expand_path('../lib/', __FILE__)
+$:.unshift lib unless $:.include?(lib)
+
+require 'tenacity'
+
+spec = Gem::Specification.new do |s|
+ s.name = s.rubyforge_project = 'tenacity'
+ s.version = Tenacity::VERSION
+
+ s.author = 'John Wood'
+ s.description = 'A ORM independent way of specifying simple relationships between models.'
+ s.email = 'john@johnpwood.net'
+ s.homepage = 'http://github.com/jwood/tenacity'
+ s.summary = 'Tenacity provides an ORM independent way of specifying simple relationships between models backed by different databases.'
+
+ s.has_rdoc = true
+ s.rdoc_options = ['-a', '--inline-source', '--charset=UTF-8']
+
+ s.files = Dir.glob('lib/*.rb') + %w(README.rdoc)
+ s.test_files = Dir.glob('test/test_*.rb')
+
+ s.executables = Dir.glob('lib/*')
+end
+
View
3 .gitignore
@@ -0,0 +1,3 @@
+*.swp
+.bundle
+html/
View
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gem "shoulda"
+
View
10 Gemfile.lock
@@ -0,0 +1,10 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ shoulda (2.11.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ shoulda
View
63 README.rdoc
@@ -0,0 +1,63 @@
+= Tenacity
+
+A ORM independent way of specifying simple relationships between models.
+
+It is sometimes necessary, or advantageous, to use more than one database in a
+given application. However, most ORMs do not support inter-database
+relationships. While supporting such relationships isn't difficult, it can
+add quite a bit of boilerplate code to your project.
+
+Tenacity aims to address this by providing an ORM independent way of specifying
+simple relationships between models backed by different databases.
+
+
+== Example
+
+ class User
+ include MongoMapper::Document
+ include Tenacity
+
+ t_has_many :entries
+ end
+
+ class Entry < ActiveRecord::Base
+ include Tenacity
+
+ t_belongs_to :user
+ end
+
+
+ # Fetch related object from the respective database
+ entry.user
+
+ # Set the related object
+ entry.user = some_user
+ entry.save
+
+ # Fetch related objects from the respective database
+ user.entries
+
+ # Add a related object to the collection
+ user.entries << some_entry
+ user.save
+
+
+== Details
+
+Defining a relationship will create a property on the object to store the id(s)
+of the related objects.
+
+* For one-to-one relationships, the property will store the id of the related object (user_id).
+* For one-to-many relationships, the property will store an array of ids of the related objects (entry_ids).
+
+
+== TODO
+* Start with support for ActiveRecord, MongoMapper, and CouchRest
+* Define a standard interface for the ORM adapters
+** get(id)
+** set(object)
+** add(object)
+** remove(object)
+** etc
+* Create adaptors to implement interface for different ORMs
+
View
24 Rakefile
@@ -0,0 +1,24 @@
+require 'rake/testtask'
+require 'rake/rdoctask'
+require 'rake/gempackagetask'
+
+spec = eval(File.new(".gemspec").readlines.join("\n"))
+
+task :default => :test
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.need_zip = true
+ pkg.need_tar = true
+end
+
+Rake::RDocTask.new(:rdoc) do |rd|
+ rd.rdoc_files.include("lib/**/*.rb", "README.rdoc")
+ rd.options + ['-a', '--inline-source', '--charset=UTF-8']
+end
+
+Rake::TestTask.new(:test) do |t|
+ t.pattern = 'test/*_test.rb'
+ t.verbose = true
+ t.libs << 'test'
+end
+
View
4 lib/tenacity.rb
@@ -0,0 +1,4 @@
+class Tenacity
+ VERSION = '0.0.1'
+end
+
View
10 test/relationships_test.rb
@@ -0,0 +1,10 @@
+require 'test_helper'
+
+class RelationshipsTest < Test::Unit::TestCase
+
+ should "test foo" do
+ assert true
+ end
+
+end
+
View
5 test/test_helper.rb
@@ -0,0 +1,5 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require 'test/unit'
+require 'shoulda'

0 comments on commit 5948beb

Please sign in to comment.
Something went wrong with that request. Please try again.