Parent

Padrino::Generators::Model

Responsible for generating new models for the specified ORM component within a project or application.

Public Class Methods

source_root() click to toggle source

Define the source template root

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

Public Instance Methods

create_model() click to toggle source

Execute the model generation

@api private

# File lib/padrino-gen/generators/model.rb, line 36
def create_model
  self.destination_root = options[:root]
  if in_app_root?
    app = options[:app]
    check_app_existence(app)
    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}"
    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]
  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.