Class: ActiveModel::Name

### Home Classes Methods

### In Files

- lib/active_model/naming.rb

### Parent

String

### Methods

- ::new
- #human

### Class/Module Index

Quicksearch

- ActiveModel
- ActiveModel::AttributeMethods
- ActiveModel::AttributeMethods::ClassMethods
- ActiveModel::AttributeMethods::ClassMethods::AttributeMethodMatcher
- ActiveModel::BlockValidator
- ActiveModel::Callbacks
- ActiveModel::Conversion
- ActiveModel::Dirty
- ActiveModel::EachValidator
- ActiveModel::Errors
- ActiveModel::Lint
- ActiveModel::Lint::Tests
- ActiveModel::MassAssignmentSecurity
- ActiveModel::MassAssignmentSecurity::BlackList
- ActiveModel::MassAssignmentSecurity::ClassMethods
- ActiveModel::MassAssignmentSecurity::Error
- ActiveModel::MassAssignmentSecurity::LoggerSanitizer
- ActiveModel::MassAssignmentSecurity::PermissionSet
- ActiveModel::MassAssignmentSecurity::Sanitizer
- ActiveModel::MassAssignmentSecurity::StrictSanitizer
- ActiveModel::MassAssignmentSecurity::WhiteList
- ActiveModel::MissingAttributeError
- ActiveModel::Name
- ActiveModel::Naming
- ActiveModel::Observer
- ActiveModel::ObserverArray
- ActiveModel::Observing
- ActiveModel::Observing::ClassMethods
- ActiveModel::SecurePassword
- ActiveModel::SecurePassword::ClassMethods
- ActiveModel::SecurePassword::InstanceMethodsOnActivation
- ActiveModel::Serialization
- ActiveModel::Serializers
- ActiveModel::Serializers::JSON
- ActiveModel::Serializers::Xml
- ActiveModel::StrictValidationFailed
- ActiveModel::Translation
- ActiveModel::Validations
- ActiveModel::Validations::AcceptanceValidator
- ActiveModel::Validations::Callbacks
- ActiveModel::Validations::Callbacks::ClassMethods
- ActiveModel::Validations::ClassMethods
- ActiveModel::Validations::ConfirmationValidator
- ActiveModel::Validations::ExclusionValidator
- ActiveModel::Validations::FormatValidator
- ActiveModel::Validations::HelperMethods
- ActiveModel::Validations::InclusionValidator
- ActiveModel::Validations::LengthValidator
- ActiveModel::Validations::NumericalityValidator
- ActiveModel::Validations::PresenceValidator
- ActiveModel::Validations::WithValidator
- ActiveModel::Validator

No matching classes.

# ActiveModel::Name

### Attributes

cache_key[R]
collection[R]
element[R]
i18n_key[R]
param_key[R]
partial_path[R]
plural[R]
route_key[R]
singular[R]
singular_route_key[R]

### Public Class Methods

new(klass, namespace = nil, name = nil) click to toggle source

    # File 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

### Public Instance Methods

human(options={}) click to toggle source

Transform the model name into a more humane format, using I18n. By default, it will underscore then humanize the class name

    BlogPost.model_name.human # => "Blog post"

Specify `options` with additional translating options.

    # File lib/active_model/naming.rb, line 45
    def human(options={})
      return @human unless @klass.respond_to?(:lookup_ancestors) &&
                           @klass.respond_to?(:i18n_scope)

      defaults = @klass.lookup_ancestors.map do |klass|
        klass.model_name.i18n_key
      end

      defaults << options[:default] if options[:default]
      defaults << @human

      options = {:scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults}.merge(options.except(:default))
      I18n.translate(defaults.shift, options)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.