File: active_support/core_ext/module/model_naming.rb

Overview
Module Structure
Class Hierarchy
Code

Overview

Module Structure

  module: <Toplevel Module>
  module: ActiveSupport#1
  module: CoreExtensions#16
  module: Module#17
has properties
method: model_name #20
  class: ModelName#2
inherits from
  String ( Builtin-Module )
has properties
attribute: singular [R] #3
attribute: plural [R] #3
attribute: element [R] #3
attribute: collection [R] #3
attribute: partial_path [R] #3
method: initialize / 1 #6

Class Hierarchy

Code

   1  module ActiveSupport
   2    class ModelName < String
   3      attr_reader :singular, :plural, :element, :collection, :partial_path
   4      alias_method :cache_key, :collection
   5 
   6      def initialize(name)
   7        super
   8        @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze
   9        @plural = ActiveSupport::Inflector.pluralize(@singular).freeze
  10        @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze
  11        @collection = ActiveSupport::Inflector.tableize(self).freeze
  12        @partial_path = "#{@collection}/#{@element}".freeze
  13      end
  14    end
  15 
  16    module CoreExtensions
  17      module Module
  18        # Returns an ActiveSupport::ModelName object for module. It can be
  19        # used to retrieve all kinds of naming-related information.
  20        def model_name
  21          @model_name ||= ::ActiveSupport::ModelName.new(name)
  22        end
  23      end
  24    end
  25  end