Sha256: 2b67cd9d110b35c50b65c3778c0e76f3ec6cf103aced2c726793ce2677a7c4c3

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'thor'

module Padrino
  module Generators

    class Model < Thor::Group
      # Define the source template root
      def self.source_root; File.expand_path(File.dirname(__FILE__)); end
      def self.banner; "padrino-gen model [name] [fields]"; end

      # Include related modules
      include Thor::Actions
      include Padrino::Generators::Actions
      include Padrino::Generators::Components::Actions

      desc "Description:\n\n\tpadrino-gen model generates a new model and migration files"

      argument :name, :desc => "The name of your padrino model"
      argument :fields, :desc => "The fields for the model", :type => :array, :default => []
      class_option :root, :aliases => '-r', :default => nil, :type => :string

      # Copies over the base sinatra starting project
      def create_model
        if in_app_root?(options[:root])
          say "Name: #{name}, Fields: #{fields.inspect}"
          include_component_module_for(:orm, options[:root])
          include_component_module_for(:test, options[:root])
          migration_name = "create_#{name.pluralize.underscore}"
          model_success = create_model_file(name, fields)
          generate_model_test(name) if model_success
          model_success ? create_migration_file(migration_name, name, fields) : 
                          say("'#{name}' model has already been generated!")
        else
          say "You are not at the root of a Padrino application! (config/boot.rb not found)" and return unless in_app_root?
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
padrino-gen-0.1.3 lib/generators/model.rb