Class: Mongoid::Generators::ConfigGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Mongoid::Generators::ConfigGenerator
- Defined in:
- lib/rails/generators/mongoid/config/config_generator.rb
Overview
Generator class for Mongoid configuration files.
Class Method Summary collapse
-
.source_root ⇒ String
Returns the path to the templates directory.
Instance Method Summary collapse
-
#app_name ⇒ String
Returns the underscored name of the Rails application.
-
#create_config_file ⇒ Object
Creates a
mongoid.yml
config file from a template. -
#create_initializer_file ⇒ Object
Creates a
mongoid.rb
initializer file from a template.
Class Method Details
.source_root ⇒ String
Returns the path to the templates directory.
18 19 20 |
# File 'lib/rails/generators/mongoid/config/config_generator.rb', line 18 def self.source_root @_mongoid_source_root ||= File.("../templates", __FILE__) end |
Instance Method Details
#app_name ⇒ String
Returns the underscored name of the Rails application.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rails/generators/mongoid/config/config_generator.rb', line 25 def app_name # :nodoc: app_cls = Rails.application.class parent = begin # Rails 6.1+ app_cls.module_parent_name rescue NoMethodError app_cls.parent.to_s end parent.underscore end |
#create_config_file ⇒ Object
Creates a mongoid.yml
config file from a template.
37 38 39 |
# File 'lib/rails/generators/mongoid/config/config_generator.rb', line 37 def create_config_file template 'mongoid.yml', File.join('config', 'mongoid.yml') end |
#create_initializer_file ⇒ Object
Creates a mongoid.rb
initializer file from a template.
42 43 44 |
# File 'lib/rails/generators/mongoid/config/config_generator.rb', line 42 def create_initializer_file template 'mongoid.rb', File.join('config', 'initializers', 'mongoid.rb') end |