Sha256: 8fe752c7f54857c994d4658c40d40543061f13a58473cddc62f98b886a992872

Contents?: true

Size: 1.11 KB

Versions: 5

Compression:

Stored size: 1.11 KB

Contents

require 'rails/generators/active_record'

module ActiveRecord
  module Generators
    class ModelGenerator < Base
      include ::Ixtlan::Core::Singleton

      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"

      check_class_collision

      class_option :migration,  :type => :boolean
      class_option :timestamps, :type => :boolean
      class_option :parent,     :type => :string, :desc => "The parent class for the generated model"

      def create_migration_file
        return unless options[:migration] && options[:parent].nil?
        migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
      end

      def create_model_file
        template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
      end

      def create_module_file
        return if class_path.empty?
        template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
      end

      hook_for :test_framework

      protected

        def parent_class_name
          options[:parent] || "ActiveRecord::Base"
        end

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
ixtlan-core-0.6.0 lib/generators/rails/active_record/active_record_generator.rb
ixtlan-generators-0.1.0 lib/generators/rails/active_record/active_record_generator.rb
ixtlan-core-0.5.0 lib/generators/rails/active_record/active_record_generator.rb
ixtlan-core-0.4.1 lib/generators/rails/active_record/active_record_generator.rb
ixtlan-core-0.4.0 lib/generators/rails/active_record/active_record_generator.rb