From f0dd77c6be6a86fe384bb0015151e0a497973d39 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 24 Sep 2009 14:01:31 -0700 Subject: Move railties/lib/* into railties/lib/* --- railties/lib/rails/generators/active_record.rb | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 railties/lib/rails/generators/active_record.rb (limited to 'railties/lib/rails/generators/active_record.rb') diff --git a/railties/lib/rails/generators/active_record.rb b/railties/lib/rails/generators/active_record.rb new file mode 100644 index 0000000000..c03ea59c1b --- /dev/null +++ b/railties/lib/rails/generators/active_record.rb @@ -0,0 +1,56 @@ +require 'rails/generators/named_base' +require 'rails/generators/migration' +require 'rails/generators/active_model' + +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 -- cgit v1.2.3