Skip to content

Commit

Permalink
update readme and gemspec
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehodgkiss committed Apr 10, 2010
1 parent 56226dd commit ea0f7f6
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 3 deletions.
56 changes: 55 additions & 1 deletion README.rdoc
@@ -1,6 +1,60 @@
= ConventionalModels

Generate ActiveRecord models with basic relationships based on conventions.
Generate ActiveRecord models automatically with basic relationships based on conventions.

== Install

gem install conventional_models

== Example

We have a table called Page and another called ContentItems (not following ActiveRecord conventions).

# point active_record to a database
require 'rubygems'
require 'active_record'
ActiveRecord::Base.establish_connection(:database => 'db.sqlite', :adapter => 'sqlite3')

# set your conventions
require 'conventional_models'
ConventionalModels.configure do
primary_key_name "Id"
table_name do |table|
table
end
end

# use the models
page = Page.create :Name => 'test'
page.content_items.create :Name => 'content1'

# have a look at the generated code
puts Page.model_code
puts ContentItem.model_code

Output:

class ::Page < ::ActiveRecord::Base
set_primary_key "Id"
set_table_name "Page"
has_many :content_items, :class_name => 'ContentItem', :primary_key => 'Id', :foreign_key => 'Page_id'
end
class ::ContentItem < ::ActiveRecord::Base
set_primary_key "Id"
set_table_name "ContentItem"
belongs_to :page, :class_name => 'Page'
end

== Default conventions

ConventionalModels.configure do
belongs_to_matcher {|column| column.name.end_with? "_id"}
belongs_to_name {|column| column.name.gsub(/_id$/, "")}
primary_key_name "id"
table_name {|table_name| table_name.pluralize}
class_name {|table_name| table_name.singularize.camelize}
ignore_tables "schema_migrations", "sqlite_sequence", "sysdiagrams"
end

== Note on Patches/Pull Requests

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -6,7 +6,7 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "conventional_models"
gem.name = "Conventional Models"
gem.description = %Q{Generate ActiveRecord models automatically with basic relationships based on conventions.}
gem.summary = %Q{Generate ActiveRecord models. For lazy people.}
gem.email = "steve@hodgkiss.me.uk"
Expand Down
2 changes: 1 addition & 1 deletion conventional_models.gemspec
Expand Up @@ -49,7 +49,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.6}
s.summary = nil
s.summary = %q{Generate ActiveRecord models. For lazy people.}
s.test_files = [
"spec/conventional_models/conventions_spec.rb",
"spec/conventional_models/database_spec.rb",
Expand Down

0 comments on commit ea0f7f6

Please sign in to comment.