Sha256: 0b1bbd8803ecdf08ad6b39c04bb67a91d8e4e5dd3bd692b1368b0e0d2857e867

Contents?: true

Size: 1.65 KB

Versions: 22

Compression:

Stored size: 1.65 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("../#{base_name}/#{generator_name}/templates", __FILE__)
      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 self.next_migration_number(dirname) #:nodoc:
        "%.3d" % (current_migration_number(dirname) + 1)
      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

22 entries across 22 versions & 3 rubygems

Version Path
ardm-rails-1.3.1 lib/generators/data_mapper.rb
ardm-rails-1.3.0 lib/generators/data_mapper.rb
ardm-rails-1.2.1 lib/generators/data_mapper.rb
tpitale-dm-rails-1.3.0 lib/generators/data_mapper.rb
tpitale-dm-rails-1.2.2 lib/generators/data_mapper.rb
dm-rails-1.2.1 lib/generators/data_mapper.rb
tpitale-dm-rails-1.2.1 lib/generators/data_mapper.rb
dm-rails-1.2.0 lib/generators/data_mapper.rb
dm-rails-1.2.0.rc2 lib/generators/data_mapper.rb
dm-rails-1.2.0.rc1 lib/generators/data_mapper.rb
dm-rails-1.1.0 lib/generators/data_mapper.rb
dm-rails-1.1.0.rc3 lib/generators/data_mapper.rb
dm-rails-1.1.0.rc2 lib/generators/data_mapper.rb
dm-rails-1.1.0.rc1 lib/generators/data_mapper.rb
dm-rails-1.0.4 lib/generators/data_mapper.rb
dm-rails-1.0.3 lib/generators/data_mapper.rb
dm-rails-1.0.2 lib/generators/data_mapper.rb
dm-rails-1.0.1 lib/generators/data_mapper.rb
dm-rails-1.0.0 lib/generators/data_mapper.rb
dm-rails-1.0.0.rc3 lib/generators/data_mapper.rb