# File lib/active_model/naming.rb, line 8 8: def initialize(klass) 9: super(klass.name) 10: @klass = klass 11: @singular = ActiveSupport::Inflector.underscore(self).tr('/', '_').freeze 12: @plural = ActiveSupport::Inflector.pluralize(@singular).freeze 13: @element = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(self)).freeze 14: @human = ActiveSupport::Inflector.humanize(@element).freeze 15: @collection = ActiveSupport::Inflector.tableize(self).freeze 16: @partial_path = "#{@collection}/#{@element}".freeze 17: end
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 25 25: def human(options={}) 26: return @human unless @klass.respond_to?(:lookup_ancestors) && 27: @klass.respond_to?(:i18n_scope) 28: 29: defaults = @klass.lookup_ancestors.map do |klass| 30: klass.model_name.underscore.to_sym 31: end 32: 33: defaults << options.delete(:default) if options[:default] 34: defaults << @human 35: 36: options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults 37: I18n.translate(defaults.shift, options) 38: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.