Sha256: b54d0e895603716209367b162e69641aafd2337c7113946f55ecf8c4197f1e99
Contents?: true
Size: 1.2 KB
Versions: 1
Compression:
Stored size: 1.2 KB
Contents
require 'rubygems' require 'active_record' class ModelGenerator < RubiGen::Base attr_reader :name,:class_name,:file_name,:class_path,:table_name,:attributes def initialize(runtime_args, runtime_options = {}) super usage if args.empty? @destination_root = File.expand_path('.') @name = args.shift @attributes = [] args.map do |x| @attributes << {:type => x.split(/:/)[1],:name => x.split(/:/)[0]} end @file_name = @name.singularize.underscore @class_name = @name.singularize.classify @class_path = File.dirname(file_name) @table_name = @name.pluralize.underscore.gsub(/\//, '_').pluralize end def manifest record do |m| m.directory File.join("test/app_root/app/models",class_path) m.template 'model.rb',File.join("test/app_root", 'app/models',"#{file_name}.rb") # Migration m.migration_template 'migration.rb', "test/app_root/db/migrate", :assigns => { :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}" }, :migration_file_name => "create_#{@table_name}" end end protected def banner <<-EOS USAGE: #{File.basename($0)} #{spec.name} ModelName [field:type, field:type] EOS end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
newplugin-0.0.4 | newplugin_generators/model/model_generator.rb |