### Home Classes Methods

### In Files

- lib/padrino-gen/generators/model.rb

### Parent

Thor::Group

### Methods

- ::banner
- ::source_root
- #create_model

### Included Modules

- Thor::Actions
- Padrino::Generators::Actions
- Padrino::Generators::Components::Actions

### Files

- README.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Generators
- Padrino::Generators::Actions
- Padrino::Generators::Actions::ClassMethods
- Padrino::Generators::App
- Padrino::Generators::AppRootNotFound
- Padrino::Generators::Cli
- Padrino::Generators::Component
- Padrino::Generators::Components
- Padrino::Generators::Components::Actions
- Padrino::Generators::Controller
- Padrino::Generators::Mailer
- Padrino::Generators::Migration
- Padrino::Generators::Model
- Padrino::Generators::Plugin
- Padrino::Generators::Project
- Padrino::Generators::Runner
- Padrino::Generators::SqlHelpers
- Padrino::Generators::Task
- ActiveRecord
- ActiveRecord::Schema
- Object

No matching classes.

# Padrino::Generators::Model

Responsible for generating new models for the specified ORM component.

### Public Class Methods

banner() click to toggle source

    # File lib/padrino-gen/generators/model.rb, line 10
    def self.banner; "padrino-gen model [name] [fields]"; end

source_root() click to toggle source

    # File lib/padrino-gen/generators/model.rb, line 9
    def self.source_root; File.expand_path(File.dirname(__FILE__)); end

### Public Instance Methods

create_model() click to toggle source

Execute the model generation.

    # File lib/padrino-gen/generators/model.rb, line 30
    def create_model
      self.destination_root = options[:root]
      if in_app_root?
        app = options[:app]
        check_app_existence(app)
        camel_name = name.to_s.underscore.camelize
        @project_name = ""
        @project_name = fetch_project_name
        if already_exists?(camel_name, @project_name)
          say "#{camel_name} already exists."
          say "Please, change the name."
          return
        else
          self.behavior = :revoke if options[:destroy]
          if invalids = invalid_fields(fields)
            say 'Invalid field name:', :red
            say " #{invalids.join(", ")}"
            return
          end
          unless include_component_module_for(:orm)
            say "<= You need an ORM adapter for run this generator. Sorry!"
            raise SystemExit
          end
          include_component_module_for(:test)
          migration_name = "create_#{name.pluralize.underscore}"
          apply_default_fields fields
          create_model_file(name, :fields => fields, :app => app)
          generate_model_test(name) if test?
          create_model_migration(migration_name, name, fields) unless options[:skip_migration]
        end
      else
        say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.