Sha256: a85fcf4692a1a255f07818914bbb428c0526240c2fdfc22be9e133b22f139ca4

Contents?: true

Size: 1.68 KB

Versions: 19

Compression:

Stored size: 1.68 KB

Contents

module Padrino
  module Generators
    module Components
      module Orms

        module CouchrestGen

          COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
          case Padrino.env
            when :development then COUCHDB = "your_db_name_development"
            when :production  then COUCHDB = "your_db_name_production"
            when :test        then COUCHDB = "your_db_name_test"
          end
          CouchRest.database!(COUCHDB)
          COUCHREST

          def setup_orm
            require_dependencies 'couchrest'
            create_file("config/database.rb", COUCHREST)
            empty_directory('app/models')
          end

          CR_MODEL = (<<-MODEL).gsub(/^ {10}/, '')
          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
        end

      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
padrino-gen-0.9.1 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.9.0 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.5 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.4 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.3 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.2 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.1 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.8.0 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.9 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.8 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.7 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.6 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.5 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.4 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.3 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.2 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.1 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.7.0 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.6.7 lib/padrino-gen/generators/components/orms/couchrest_gen.rb