/lib/rails/generators/mongo_mapper/config/config_generator.rb

http://github.com/jnunemaker/mongomapper · Ruby · 36 lines · 26 code · 9 blank · 1 comment · 2 complexity · d9300eb80c0d1151d229cc1e9b0163e8 MD5 · raw file

  1. # encoding: utf-8
  2. module MongoMapper
  3. module Generators
  4. class ConfigGenerator < Rails::Generators::Base
  5. desc 'creates the MongoMapper configuration at config/mongo.yml'
  6. argument :database_name, :type => :string, :optional => true
  7. def self.source_root
  8. @source_root ||= File.expand_path('../templates', __FILE__)
  9. end
  10. def create_config_file
  11. template 'mongo.yml', File.join('config', 'mongo.yml')
  12. end
  13. protected
  14. def app_name
  15. @app_name ||= defined_app_const_base? ? defined_app_name : File.basename(destination_root)
  16. end
  17. def defined_app_name
  18. defined_app_const_base.underscore
  19. end
  20. def defined_app_const_base
  21. Rails.respond_to?(:application) && defined?(Rails::Application) &&
  22. Rails.application.is_a?(Rails::Application) && Rails.application.class.name.sub(/::Application$/, '')
  23. end
  24. alias :defined_app_const_base? :defined_app_const_base
  25. end
  26. end
  27. end