require 'generator_spec/rails_helpers/rails_model' module RSpec::Rails module Orm module Base include RSpec::Rails::Model protected def orm_marker_name type = :document document_name type end def document_name type type_content = type == :document ? "#{orm_name}::Document" : "#{orm_name}::EmbeddedDocument" end def clazz name "class #{name.to_s.camelize}" end def file name, include_stmt, &block %Q{#{clazz name} #{include_stmt} #{yield if block} end} end def file_w_include name, module_name, &block file name, "include #{module_name}", &block end def file_w_inherit name, module_name, &block %Q{#{clazz name} < #{module_name} #{yield if block} end} end def field name, type = nil return "#{field_name} :#{name}, #{type}" if type "#{field_name} :#{name}" end end module ActiveRecord include RSpec::Rails::Orm::Base def orm_marker_name type=nil 'ActiveRecord::Base' end def new_model_content name, type=nil, content file_w_inherit(name, orm_marker_name(type)) { content } end end module MongoMapper include RSpec::Rails::Orm::Base def orm_name 'MongoMapper' end def new_model_content name, type = :document file_w_include(name, orm_marker_name(type)) { content } end def field_name 'key' end end module Mongoid include RSpec::Rails::Orm::Base def orm_name 'Mongoid' end def field_name 'field' end def new_model_content name, type = :document file_w_include(name, orm_marker_name(type)) { content } end def field name, type = nil return "#{field_name} :#{name}, :type => #{type}" if type "#{field_name} :#{name}" end end module DataMapper include RSpec::Rails::Orm::Base def orm_name 'DataMapper' end def orm_marker_name type=nil "#{orm_name}::Resource" end def new_model_content name file_w_include(name, orm_marker_name(type)) { content } end def field_name 'property' end end end end