Methods
Included Modules
- Comparable
Attributes
[RW] | cache_key | |
[RW] | collection | |
[RW] | element | |
[RW] | i18n_key | |
[RW] | name | |
[RW] | param_key | |
[RW] | plural | |
[RW] | route_key | |
[RW] | singular | |
[RW] | singular_route_key |
Class Public methods
new(klass, namespace = nil, name = nil, locale = :en) Link
Returns a new ActiveModel::Name
instance. By default, the namespace
and name
option will take the namespace and name of the given class respectively. Use locale
argument for singularize and pluralize model name.
module Foo
class Bar
end
end
ActiveModel::Name.new(Foo::Bar).to_s
# => "Foo::Bar"
# File activemodel/lib/active_model/naming.rb, line 166 def initialize(klass, namespace = nil, name = nil, locale = :en) @name = name || klass.name raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if @name.blank? @unnamespaced = @name.delete_prefix("#{namespace.name}::") if namespace @klass = klass @singular = _singularize(@name) @plural = ActiveSupport::Inflector.pluralize(@singular, locale) @uncountable = @plural == @singular @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(@name)) @human = ActiveSupport::Inflector.humanize(@element) @collection = ActiveSupport::Inflector.tableize(@name) @param_key = (namespace ? _singularize(@unnamespaced) : @singular) @i18n_key = @name.underscore.to_sym @route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key, locale) : @plural.dup) @singular_route_key = ActiveSupport::Inflector.singularize(@route_key, locale) @route_key << "_index" if @uncountable end