Adding model generator
This commit is contained in:
parent
089dd7497a
commit
bb667459a8
|
@ -31,7 +31,12 @@ but no guarantees!
|
||||||
|
|
||||||
gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
|
gem 'couchrest_model', :git => 'git://github.com/couchrest/couchrest_model.git'
|
||||||
|
|
||||||
|
## Generators
|
||||||
|
|
||||||
|
### Model
|
||||||
|
|
||||||
|
$ rails generate model person --orm=couchrest_model
|
||||||
|
|
||||||
## General Usage
|
## General Usage
|
||||||
|
|
||||||
require 'couchrest_model'
|
require 'couchrest_model'
|
||||||
|
|
1
Rakefile
1
Rakefile
|
@ -31,6 +31,7 @@ begin
|
||||||
gemspec.add_dependency("activesupport", "~> 2.3.5")
|
gemspec.add_dependency("activesupport", "~> 2.3.5")
|
||||||
gemspec.add_dependency("activemodel", "~> 3.0.0.beta4")
|
gemspec.add_dependency("activemodel", "~> 3.0.0.beta4")
|
||||||
gemspec.add_dependency("tzinfo", "~> 0.3.22")
|
gemspec.add_dependency("tzinfo", "~> 0.3.22")
|
||||||
|
gemspec.add_dependency('railties', ">= 3.0.0.rc")
|
||||||
gemspec.version = CouchRest::Model::VERSION
|
gemspec.version = CouchRest::Model::VERSION
|
||||||
gemspec.date = Time.now.strftime("%Y-%m-%d")
|
gemspec.date = Time.now.strftime("%Y-%m-%d")
|
||||||
gemspec.require_path = "lib"
|
gemspec.require_path = "lib"
|
||||||
|
|
|
@ -5,11 +5,11 @@
|
||||||
|
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = %q{couchrest_model}
|
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.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.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.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.email = %q{jchris@apache.org}
|
||||||
s.extra_rdoc_files = [
|
s.extra_rdoc_files = [
|
||||||
|
@ -48,7 +48,11 @@ Gem::Specification.new do |s|
|
||||||
"lib/couchrest/model/validations/locale/en.yml",
|
"lib/couchrest/model/validations/locale/en.yml",
|
||||||
"lib/couchrest/model/validations/uniqueness.rb",
|
"lib/couchrest/model/validations/uniqueness.rb",
|
||||||
"lib/couchrest/model/views.rb",
|
"lib/couchrest/model/views.rb",
|
||||||
|
"lib/couchrest/railtie.rb",
|
||||||
"lib/couchrest_model.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/assocations_spec.rb",
|
||||||
"spec/couchrest/attachment_spec.rb",
|
"spec/couchrest/attachment_spec.rb",
|
||||||
"spec/couchrest/attribute_protection_spec.rb",
|
"spec/couchrest/attribute_protection_spec.rb",
|
||||||
|
@ -133,12 +137,14 @@ Gem::Specification.new do |s|
|
||||||
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
|
s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.5"])
|
||||||
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
s.add_runtime_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
||||||
s.add_runtime_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
s.add_runtime_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
||||||
|
s.add_runtime_dependency(%q<railties>, [">= 3.0.0.rc"])
|
||||||
else
|
else
|
||||||
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
|
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
|
||||||
s.add_dependency(%q<mime-types>, ["~> 1.15"])
|
s.add_dependency(%q<mime-types>, ["~> 1.15"])
|
||||||
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
||||||
s.add_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
s.add_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
||||||
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
||||||
|
s.add_dependency(%q<railties>, [">= 3.0.0.rc"])
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
|
s.add_dependency(%q<couchrest>, ["~> 1.0.0"])
|
||||||
|
@ -146,6 +152,7 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
s.add_dependency(%q<activesupport>, ["~> 2.3.5"])
|
||||||
s.add_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
s.add_dependency(%q<activemodel>, ["~> 3.0.0.beta4"])
|
||||||
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
s.add_dependency(%q<tzinfo>, ["~> 0.3.22"])
|
||||||
|
s.add_dependency(%q<railties>, [">= 3.0.0.rc"])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
== Next Version
|
== CouchRest Model 1.0.0.beta8
|
||||||
|
|
||||||
* Major enhancements
|
* Major enhancements
|
||||||
|
* * Added model generator
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
* Raise error on adding objects to "collection_of" without an id
|
* Raise error on adding objects to "collection_of" without an id
|
||||||
|
|
|
@ -3,7 +3,7 @@ module CouchRest
|
||||||
|
|
||||||
module Model
|
module Model
|
||||||
|
|
||||||
VERSION = "1.0.0.beta7"
|
VERSION = "1.0.0.beta8"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
12
lib/couchrest/railtie.rb
Normal file
12
lib/couchrest/railtie.rb
Normal file
|
@ -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
|
||||||
|
|
|
@ -3,6 +3,8 @@ require 'couchrest'
|
||||||
|
|
||||||
gem "tzinfo", ">= 0.3.22"
|
gem "tzinfo", ">= 0.3.22"
|
||||||
|
|
||||||
|
gem 'railties', ">= 3.0.0.rc"
|
||||||
|
|
||||||
gem "activesupport", ">= 2.3.5"
|
gem "activesupport", ">= 2.3.5"
|
||||||
require 'active_support/core_ext'
|
require 'active_support/core_ext'
|
||||||
require 'active_support/json'
|
require 'active_support/json'
|
||||||
|
@ -57,3 +59,4 @@ require "couchrest/model/base"
|
||||||
|
|
||||||
# Add rails support *after* everything has loaded
|
# Add rails support *after* everything has loaded
|
||||||
|
|
||||||
|
require "couchrest/railtie"
|
||||||
|
|
16
lib/rails/generators/couchrest_model.rb
Normal file
16
lib/rails/generators/couchrest_model.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
||||||
|
class <%= class_name %> < <%= parent_class_name.classify %>
|
||||||
|
end
|
Loading…
Reference in a new issue