Module: Humpyard::ActiveModel::Name

Defined in:
lib/humpyard/active_model/naming.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/humpyard/active_model/naming.rb', line 4

def self.included(base)
  base.alias_method_chain :human, :namespaces
end

Instance Method Details

#human_with_namespaces(options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/humpyard/active_model/naming.rb', line 8

def human_with_namespaces(options={})
  # Rails orig
  return @human unless @klass.respond_to?(:lookup_ancestors) &&
                       @klass.respond_to?(:i18n_scope)

  # Namespace patch
  defaults = @klass.lookup_ancestors.map do |klass|
    klass.model_name.underscore.gsub('/','.').to_sym
  end
  
  # Rails orig
  defaults << options.delete(:default) if options[:default]
  defaults << @human

  options.reverse_merge! :scope => [@klass.i18n_scope, :models], :count => 1, :default => defaults
  I18n.translate(defaults.shift, options)
end