mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
57 lines
1.2 KiB
Ruby
57 lines
1.2 KiB
Ruby
require 'generators/named_base'
|
|
require 'generators/migration'
|
|
require 'generators/active_model'
|
|
require 'active_record'
|
|
|
|
module ActiveRecord
|
|
module Generators
|
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
|
include Rails::Generators::Migration
|
|
|
|
protected
|
|
# Implement the required interface for Rails::Generators::Migration.
|
|
#
|
|
def next_migration_number(dirname) #:nodoc:
|
|
if ActiveRecord::Base.timestamped_migrations
|
|
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
|
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}.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_attributes(#{params})"
|
|
end
|
|
|
|
def errors
|
|
"#{name}.errors"
|
|
end
|
|
|
|
def destroy
|
|
"#{name}.destroy"
|
|
end
|
|
end
|
|
end
|
|
end
|