Sha256: 4f1a54192cd82bd24f7e342bb31816a37d9a8db25dc0a4b35a169e040ad6745b

Contents?: true

Size: 1.31 KB

Versions: 16

Compression:

Stored size: 1.31 KB

Contents

require 'generators/data_mapper'

module DataMapper
  module Generators
    class ModelGenerator < Base
      argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
      class_option :id, :type => :numeric, :desc => "The id to be used in the migration"

      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
        if migration? && parent?
          file_name = "create_#{file_path.gsub(/\//, '_').pluralize}"
          migration_template "migration.rb", "db/migrate/#{file_name}.rb"
        end
      end

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

      protected

      def migration?
        options[:migration]
      end        
      
      def timestamps?
        options[:timestamps]
      end

      def parent?
        options[:parent]
      end
      
      def timestamp_statements
        %q{
  property :created_at, DateTime
  # property :created_on, Date
 
  property :updated_at, DateTime
  # property :updated_on, Date
}            
      end
      
      hook_for :test_framework
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
rails3-generators-1.0.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.6 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.5 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.4 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.3 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.2 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.1 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.17.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.16.1 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.16.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.15.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.14.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.13.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.12.1 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.12.0 lib/generators/data_mapper/model/model_generator.rb
rails3-generators-0.11.0 lib/generators/data_mapper/model/model_generator.rb