Method: Rails::Generators::ModelHelpers#initialize

Defined in:
railties/lib/rails/generators/model_helpers.rb

#initialize(args, *_options) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'railties/lib/rails/generators/model_helpers.rb', line 26

def initialize(args, *_options)
  super
  if plural_model_name?(name) && !options[:force_plural]
    singular = name.singularize
    unless ModelHelpers.skip_warn
      say PLURAL_MODEL_NAME_WARN_MESSAGE % [name, singular]
    end
    name.replace singular
    assign_names!(name)
  end
  if inflection_impossible?(name)
    option1 = name.singularize.underscore
    option2 = name.pluralize.underscore.singularize
    raise Error, INFLECTION_IMPOSSIBLE_ERROR_MESSAGE % [name, option1, option2]
  end
  if irregular_model_name?(name) && ! ModelHelpers.skip_warn
    say IRREGULAR_MODEL_NAME_WARN_MESSAGE % [name.pluralize]
  end
  ModelHelpers.skip_warn = true
end