Sha256: a0fdededfc0e6db99b8027964b1e7ef28e2c4f11ce7dce7c6cccb43eb1046682
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '') unless defined?(COUCHREST) case Padrino.env when :development then COUCHDB_NAME = '!NAME!_development' when :production then COUCHDB_NAME = '!NAME!_production' when :test then COUCHDB_NAME = '!NAME!_test' end COUCHDB = CouchRest.database!(COUCHDB_NAME) COUCHREST def setup_orm require_dependencies 'couchrest' require_dependencies 'json_pure' create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, name.underscore)) empty_directory('app/models') end CR_MODEL = (<<-MODEL).gsub(/^ {10}/, '') unless defined?(CR_MODEL) class !NAME! < CouchRest::ExtendedDocument include CouchRest::Validation use_database COUCHDB unique_id :id # property <name> !FIELDS! end MODEL def create_model_file(name, fields) model_path = destination_root('app/models/', "#{name.to_s.underscore}.rb") field_tuples = fields.collect { |value| value.split(":") } column_declarations = field_tuples.collect { |field, kind| "property :#{field}" }.join("\n ") model_contents = CR_MODEL.gsub(/!NAME!/, name.to_s.camelize) model_contents.gsub!(/!FIELDS!/, column_declarations) create_file(model_path, model_contents) end def create_model_migration(filename, name, fields) # NO MIGRATION NEEDED end def create_migration_file(migration_name, name, columns) # NO MIGRATION NEEDED end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
padrino-gen-0.9.10 | lib/padrino-gen/generators/components/orms/couchrest.rb |