Class: Rails::Configuration::Generators

Inherits:
Object
  • Object
show all
Defined in:
railties/lib/rails/configuration.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerators

Returns a new instance of Generators.



108
109
110
111
112
113
114
115
116
117
# File 'railties/lib/rails/configuration.rb', line 108

def initialize
  @aliases = Hash.new { |h, k| h[k] = {} }
  @options = Hash.new { |h, k| h[k] = {} }
  @fallbacks = {}
  @templates = []
  @colorize_logging = true
  @api_only = false
  @hidden_namespaces = []
  @after_generate_callbacks = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'railties/lib/rails/configuration.rb', line 143

def method_missing(method, *args)
  method = method.name.delete_suffix("=").to_sym

  if args.empty?
    if method == :rails
      return @options[method]
    else
      return @options[:rails][method]
    end
  end

  if method == :rails || args.first.is_a?(Hash)
    namespace, configuration = method, args.shift
  else
    namespace, configuration = args.shift, args.shift
    namespace = namespace.to_sym if namespace.respond_to?(:to_sym)
    @options[:rails][method] = namespace
  end

  if configuration
    aliases = configuration.delete(:aliases)
    @aliases[namespace].merge!(aliases) if aliases
    @options[namespace].merge!(configuration)
  end
end

Instance Attribute Details

#after_generate_callbacksObject (readonly)

Returns the value of attribute after_generate_callbacks.



106
107
108
# File 'railties/lib/rails/configuration.rb', line 106

def after_generate_callbacks
  @after_generate_callbacks
end

#aliasesObject

Returns the value of attribute aliases.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def aliases
  @aliases
end

#api_onlyObject

Returns the value of attribute api_only.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def api_only
  @api_only
end

#colorize_loggingObject

Returns the value of attribute colorize_logging.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def colorize_logging
  @colorize_logging
end

#fallbacksObject

Returns the value of attribute fallbacks.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def fallbacks
  @fallbacks
end

#hidden_namespacesObject (readonly)

Returns the value of attribute hidden_namespaces.



106
107
108
# File 'railties/lib/rails/configuration.rb', line 106

def hidden_namespaces
  @hidden_namespaces
end

#optionsObject

Returns the value of attribute options.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def options
  @options
end

#templatesObject

Returns the value of attribute templates.



105
106
107
# File 'railties/lib/rails/configuration.rb', line 105

def templates
  @templates
end

Instance Method Details

#after_generate(&block) ⇒ Object



130
131
132
# File 'railties/lib/rails/configuration.rb', line 130

def after_generate(&block)
  @after_generate_callbacks << block
end

#apply_rubocop_autocorrect_after_generate!Object



134
135
136
137
138
139
140
141
# File 'railties/lib/rails/configuration.rb', line 134

def apply_rubocop_autocorrect_after_generate!
  after_generate do |files|
    parsable_files = files.filter { |file| File.exist?(file) && file.end_with?(".rb") }
    unless parsable_files.empty?
      system(RbConfig.ruby, "bin/rubocop", "-A", "--fail-level=E", "--format=quiet", *parsable_files, exception: true)
    end
  end
end

#hide_namespace(namespace) ⇒ Object



126
127
128
# File 'railties/lib/rails/configuration.rb', line 126

def hide_namespace(namespace)
  @hidden_namespaces << namespace
end

#initialize_copy(source) ⇒ Object



119
120
121
122
123
124
# File 'railties/lib/rails/configuration.rb', line 119

def initialize_copy(source)
  @aliases = @aliases.deep_dup
  @options = @options.deep_dup
  @fallbacks = @fallbacks.deep_dup
  @templates = @templates.dup
end