123456789_123456789_123456789_123456789_123456789_

Class: Mongoid::Generators::ConfigGenerator

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Rails::Generators::Base
Instance Chain:
self, Rails::Generators::Base
Inherits: Rails::Generators::Base
  • Object
Defined in: lib/rails/generators/mongoid/config/config_generator.rb

Overview

Generator class for ::Mongoid configuration files.

Class Method Summary

Instance Method Summary

Class Method Details

.source_rootString

Returns the path to the templates directory.

Returns:

[ GitHub ]

  
# File 'lib/rails/generators/mongoid/config/config_generator.rb', line 18

def self.source_root
  @_mongoid_source_root ||= File.expand_path("../templates", __FILE__)
end

Instance Method Details

#app_nameString

Returns the underscored name of the ::Rails application.

Returns:

[ GitHub ]

  
# 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

Creates a mongoid.yml config file from a template.

[ GitHub ]

  
# 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

Creates a mongoid.rb initializer file from a template.

[ GitHub ]

  
# 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