class MultiBitShiftGenerator < Rails::Generator::NamedBase include ActiveSupport::CoreExtensions::String::Inflections attr_reader :controller_name, :controller_class_path, :controller_file_path, :controller_class_nesting, :controller_class_nesting_depth, :controller_class_name, :controller_singular_name, :controller_plural_name, :controller_human_name alias_method :controller_file_name, :controller_singular_name alias_method :controller_table_name, :controller_plural_name def initialize(runtime_args, runtime_options = {}) super # Take controller name from the next argument. Default to the pluralized model name. @controller_name = nil @controller_name ||= ActiveRecord::Base.pluralize_table_names ? @name.pluralize : @name base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name) @controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name) if @controller_class_nesting.empty? @controller_class_name = @controller_class_name_without_nesting else @controller_class_name = "#{@controller_class_nesting}::#{@controller_class_name_without_nesting}" end @controller_human_name = singular_name.humanize end def manifest record do |m| if args.include?("generate_model") or args.include?("all") m.dependency 'model', [singular_name], :collision => :skip, :skip_migration => true end if args.include?("generate_migration") or args.include?("all") m.migration_template 'migrate/file_table_migration.rb', 'db/migrate', {:migration_file_name => "#{singular_name}_migration"} end if args.include?("generate_validation_object") or args.include?("all") m.template 'models/mbs_validation_settings.rb', File.join("app/models/validate_mbs_file.rb") end end end protected def banner "Usage: #{$0} multi_bit_shift ModelName [generate_model] [generate_migration] [generate_validation_object] [all]" end end