Sha256: cf0bdec27cc8957d57e076bb9b9fcd53036f17ce4a542a443cc992104496b4d2

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

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

module MongoMapper
  module Generators
    class Base < Rails::Generators::NamedBase #:nodoc:

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

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

      def self.find(klass, params=nil)
        "#{klass}.find(#{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

6 entries across 6 versions & 1 rubygems

Version Path
rails3-generators-0.17.6 lib/generators/mongo_mapper.rb
rails3-generators-0.17.5 lib/generators/mongo_mapper.rb
rails3-generators-0.17.4 lib/generators/mongo_mapper.rb
rails3-generators-0.17.3 lib/generators/mongo_mapper.rb
rails3-generators-0.17.2 lib/generators/mongo_mapper.rb
rails3-generators-0.17.1 lib/generators/mongo_mapper.rb