Sha256: 81aa985944530e6639d756a533f0b9f03e7835558c62e12588ba929c37fe03c8

Contents?: true

Size: 1.86 KB

Versions: 11

Compression:

Stored size: 1.86 KB

Contents

module Padrino
  module Generators
    module Components
      module Orms

        module CouchrestGen

          COUCHREST = (<<-COUCHREST).gsub(/^ {10}/, '')
          module DatabaseSetup
            def self.registered(app)
              app.configure(:development) { set :couchdb, CouchRest.database!("your_dev_db_here") }
              app.configure(:production)  { set :couchdb, CouchRest.database!("your_production_db_here") }
              app.configure(:test)        { set :couchdb, CouchRest.database!("your_test_db_here") }
            end
          end
          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 app { couchdb }

            unique_id :id
            # property <name>
            !FIELDS!
          end
          MODEL

          def create_model_file(name, fields)
            model_path = app_root_path('app/models/', "#{name.to_s.underscore}.rb")
            return false if File.exist?(model_path)
            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

11 entries across 11 versions & 1 rubygems

Version Path
padrino-gen-0.6.3 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.6.2 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.6.1 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.5.0 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.4.6 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.4.5 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.2.9 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.2.6 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.2.5 lib/padrino-gen/generators/components/orms/couchrest_gen.rb
padrino-gen-0.2.2 lib/generators/components/orms/couchrest_gen.rb
padrino-gen-0.2.1 lib/generators/components/orms/couchrest_gen.rb