class method
self.new
Ruby on Rails 3.2.22.5
Since v3.0.20Signature
self.new(klass, namespace = nil, name = nil)
No documentation comment.
Parameters
-
klassreq -
namespaceopt = nil -
nameopt = nil
Source
# File activemodel/lib/active_model/naming.rb, line 15
def initialize(klass, namespace = nil, name = nil)
name ||= klass.name
raise ArgumentError, "Class name cannot be blank. You need to supply a name argument when anonymous class given" if name.blank?
super(name)
@unnamespaced = self.sub(/^#{namespace.name}::/, '') if namespace
@klass = klass
@singular = _singularize(self).freeze
@plural = ActiveSupport::Inflector.pluralize(@singular).freeze
@element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
@human = ActiveSupport::Inflector.humanize(@element).freeze
@collection = ActiveSupport::Inflector.tableize(self).freeze
@partial_path = "#{@collection}/#{@element}".freeze
@param_key = (namespace ? _singularize(@unnamespaced) : @singular).freeze
@i18n_key = self.underscore.to_sym
@route_key = (namespace ? ActiveSupport::Inflector.pluralize(@param_key) : @plural.dup)
@singular_route_key = ActiveSupport::Inflector.singularize(@route_key).freeze
@route_key << "_index" if @plural == @singular
@route_key.freeze
end
Defined in activemodel/lib/active_model/naming.rb line 15
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveModel::Name