diff --git a/README.md b/README.md index c701026..a4669b5 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,12 @@ but no guarantees! gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git' - +## Generators + +### Model + + $ rails generate model person --orm=couchrest_model + ## General Usage require 'couchrest_model' diff --git a/Rakefile b/Rakefile index d637e82..01204d8 100644 --- a/Rakefile +++ b/Rakefile @@ -31,6 +31,7 @@ begin gemspec.add_dependency("activesupport", "~> 2.3.5") gemspec.add_dependency("activemodel", "~> 3.0.0.beta4") gemspec.add_dependency("tzinfo", "~> 0.3.22") + gemspec.add_dependency('railties', ">= 3.0.0.rc") gemspec.version = CouchRest::Model::VERSION gemspec.date = Time.now.strftime("%Y-%m-%d") gemspec.require_path = "lib" diff --git a/couchrest_model.gemspec b/couchrest_model.gemspec index b8285f3..a661263 100644 --- a/couchrest_model.gemspec +++ b/couchrest_model.gemspec @@ -5,11 +5,11 @@ Gem::Specification.new do |s| s.name = %q{couchrest_model} - s.version = "1.0.0.beta7" + s.version = "1.0.0.beta8" s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version= s.authors = ["J. Chris Anderson", "Matt Aimonetti", "Marcos Tapajos", "Will Leinweber", "Sam Lown"] - s.date = %q{2010-08-11} + s.date = %q{2010-08-23} s.description = %q{CouchRest Model provides aditional features to the standard CouchRest Document class such as properties, view designs, associations, callbacks, typecasting and validations.} s.email = %q{jchris@apache.org} s.extra_rdoc_files = [ @@ -48,7 +48,11 @@ Gem::Specification.new do |s| "lib/couchrest/model/validations/locale/en.yml", "lib/couchrest/model/validations/uniqueness.rb", "lib/couchrest/model/views.rb", + "lib/couchrest/railtie.rb", "lib/couchrest_model.rb", + "lib/rails/generators/couchrest_model.rb", + "lib/rails/generators/couchrest_model/model/model_generator.rb", + "lib/rails/generators/couchrest_model/model/templates/model.rb", "spec/couchrest/assocations_spec.rb", "spec/couchrest/attachment_spec.rb", "spec/couchrest/attribute_protection_spec.rb", @@ -133,12 +137,14 @@ Gem::Specification.new do |s| s.add_runtime_dependency(%q, ["~> 2.3.5"]) s.add_runtime_dependency(%q, ["~> 3.0.0.beta4"]) s.add_runtime_dependency(%q, ["~> 0.3.22"]) + s.add_runtime_dependency(%q, [">= 3.0.0.rc"]) else s.add_dependency(%q, ["~> 1.0.0"]) s.add_dependency(%q, ["~> 1.15"]) s.add_dependency(%q, ["~> 2.3.5"]) s.add_dependency(%q, ["~> 3.0.0.beta4"]) s.add_dependency(%q, ["~> 0.3.22"]) + s.add_dependency(%q, [">= 3.0.0.rc"]) end else s.add_dependency(%q, ["~> 1.0.0"]) @@ -146,6 +152,7 @@ Gem::Specification.new do |s| s.add_dependency(%q, ["~> 2.3.5"]) s.add_dependency(%q, ["~> 3.0.0.beta4"]) s.add_dependency(%q, ["~> 0.3.22"]) + s.add_dependency(%q, [">= 3.0.0.rc"]) end end diff --git a/history.txt b/history.txt index bdc5b89..b2c3477 100644 --- a/history.txt +++ b/history.txt @@ -1,6 +1,7 @@ -== Next Version +== CouchRest Model 1.0.0.beta8 * Major enhancements + * * Added model generator * Minor enhancements * Raise error on adding objects to "collection_of" without an id diff --git a/lib/couchrest/model.rb b/lib/couchrest/model.rb index 77eb586..b81387d 100644 --- a/lib/couchrest/model.rb +++ b/lib/couchrest/model.rb @@ -3,7 +3,7 @@ module CouchRest module Model - VERSION = "1.0.0.beta7" + VERSION = "1.0.0.beta8" end diff --git a/lib/couchrest/railtie.rb b/lib/couchrest/railtie.rb new file mode 100644 index 0000000..e167785 --- /dev/null +++ b/lib/couchrest/railtie.rb @@ -0,0 +1,12 @@ +require "rails" +require "active_model/railtie" + +module CouchrestModel + # = Active Record Railtie + class Railtie < Rails::Railtie + config.generators.orm :couchrest + config.generators.test_framework :test_unit, :fixture => false + end + +end + \ No newline at end of file diff --git a/lib/couchrest_model.rb b/lib/couchrest_model.rb index a2c2fd3..2a141be 100644 --- a/lib/couchrest_model.rb +++ b/lib/couchrest_model.rb @@ -3,6 +3,8 @@ require 'couchrest' gem "tzinfo", ">= 0.3.22" +gem 'railties', ">= 3.0.0.rc" + gem "activesupport", ">= 2.3.5" require 'active_support/core_ext' require 'active_support/json' @@ -57,3 +59,4 @@ require "couchrest/model/base" # Add rails support *after* everything has loaded +require "couchrest/railtie" diff --git a/lib/rails/generators/couchrest_model.rb b/lib/rails/generators/couchrest_model.rb new file mode 100644 index 0000000..c523992 --- /dev/null +++ b/lib/rails/generators/couchrest_model.rb @@ -0,0 +1,16 @@ +require 'rails/generators/named_base' +require 'rails/generators/active_model' +require 'couchrest_model' + +module CouchrestModel + module Generators + class Base < Rails::Generators::NamedBase #:nodoc: + + # Set the current directory as base for the inherited generators. + def self.base_root + File.dirname(__FILE__) + end + + end + end +end diff --git a/lib/rails/generators/couchrest_model/model/model_generator.rb b/lib/rails/generators/couchrest_model/model/model_generator.rb new file mode 100644 index 0000000..7b1a72f --- /dev/null +++ b/lib/rails/generators/couchrest_model/model/model_generator.rb @@ -0,0 +1,27 @@ +require 'rails/generators/couchrest_model' + +module CouchrestModel + module Generators + class ModelGenerator < Base + check_class_collision + + def create_model_file + template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb") + end + + def create_module_file + return if class_path.empty? + template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke + end + + hook_for :test_framework + + protected + + def parent_class_name + "CouchRest::Model::Base" + end + + end + end +end diff --git a/lib/rails/generators/couchrest_model/model/templates/model.rb b/lib/rails/generators/couchrest_model/model/templates/model.rb new file mode 100644 index 0000000..9fe368b --- /dev/null +++ b/lib/rails/generators/couchrest_model/model/templates/model.rb @@ -0,0 +1,2 @@ +class <%= class_name %> < <%= parent_class_name.classify %> +end