Sha256: 48f8aabe96b19f0fd7e817e77c1382a6c1490b35ac987e5cb03f358c48f473f8

Contents?: true

Size: 1.81 KB

Versions: 26

Compression:

Stored size: 1.81 KB

Contents

require 'rails/generators/named_base'
require 'rails/generators/migration'
require 'rails/generators/active_model'

module Datamapper
  module Generators
    class Base < Rails::Generators::NamedBase #:nodoc:
      include Rails::Generators::Migration

      def self.source_root
        @_datamapper_source_root ||= File.expand_path(File.join(File.dirname(__FILE__),
                                                      'datamapper', generator_name, 'templates'))
      end

      protected

        # Datamapper does not care if migrations have the same name as long as
        # they have different ids. 
        #
        def migration_exists?(dirname, file_name) #:nodoc:
          false
        end

        # Implement the required interface for Rails::Generators::Migration.
        #
        def next_migration_number(dirname) #:nodoc:
          if options[:id]
            "%.3d" % options[:id]
          else
            "%.3d" % (current_migration_number(dirname) + 1)
          end
        end
    end

    class ActiveModel < Rails::Generators::ActiveModel #:nodoc:
      def self.all(klass)
        "#{klass}.all"
      end

      def self.find(klass, params=nil)
        "#{klass}.get(#{params})"
      end

      def self.build(klass, params=nil)
        if params
          "#{klass}.new(#{params})"
        else
          "#{klass}.new"
        end
      end

      def save
        "#{name}.save"
      end

      def update_attributes(params=nil)
        "#{name}.update(#{params})"
      end

      def errors
        "#{name}.errors"
      end

      def destroy
        "#{name}.destroy"
      end
    end
  end
end

module Rails
  module Generators
    class GeneratedAttribute #:nodoc:
      def type_class
        return 'DateTime' if type.to_s == 'datetime'
        return type.to_s.camelcase
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
rails3-generators-0.10.3 lib/generators/datamapper.rb
rails3-generators-0.10.2 lib/generators/datamapper.rb
rails3-generators-0.10.1 lib/generators/datamapper.rb
rails3-generators-0.10.0 lib/generators/datamapper.rb
rails3-generators-0.9.2 lib/generators/datamapper.rb
rails3-generators-0.9.1 lib/generators/datamapper.rb
rails3-generators-0.9.0 lib/generators/datamapper.rb
rails3-generators-0.8.2 lib/generators/datamapper.rb
jumpstart-0.1.0 jumpstart_templates/i0n_rails_3/lib/generators/datamapper.rb
rails3-generators-0.8.1 lib/generators/datamapper.rb
rails3-generators-0.8.0 lib/generators/datamapper.rb
rails3-generators-0.7.1 lib/generators/datamapper.rb
rails3-generators-0.7.0 lib/generators/datamapper.rb
rails3-generators-0.6.0 lib/generators/datamapper.rb
rails3-generators-0.5.4 lib/generators/datamapper.rb
rails3-generators-0.5.3 lib/generators/datamapper.rb
rails3-generators-0.5.2 lib/generators/datamapper.rb
rails3-generators-0.5.1 lib/generators/datamapper.rb
rails3-generators-0.5.0 lib/generators/datamapper.rb
rails3-generators-0.4.0 lib/generators/datamapper.rb