Class: Mongoid::Generators::ConfigGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/mongoid/config/config_generator.rb

Overview

Generator class for Mongoid configuration files.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootString

Returns the path to the templates directory.

Returns:

  • (String)

    The path.



18
19
20
# 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:

  • (String)

    The app name.



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_fileObject

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_fileObject

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