# 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: @i18n_key = ActiveSupport::Inflector.underscore(self).tr('/', '.').to_sym
18: 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 26
26: def human(options={})
27: return @human unless @klass.respond_to?(:lookup_ancestors) &&
28: @klass.respond_to?(:i18n_scope)
29:
30: defaults = @klass.lookup_ancestors.map do |klass|
31: klass.model_name.i18n_key
32: end
33:
34: defaults << options.delete(:default) if options[:default]
35: defaults << @human
36:
37: options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
38: I18n.translate(defaults.shift, options)
39: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.