Sha256: 2a0cbccbe71acad672188ca86e8032caafb0e2c2ac42dca57d53ab956130ce74
Contents?: true
Size: 985 Bytes
Versions: 28
Compression:
Stored size: 985 Bytes
Contents
module Lolita class ModelName def initialize(given_class) @klass = given_class @class_name = @klass.to_s end def human(options={}) name = if defined?(ActiveRecord::Base) && @klass.ancestors.include?(ActiveRecord::Base) "activerecord.models.#{@class_name.underscore}" else "lolita.models.#{@class_name.underscore.gsub("/",".")}" end ::I18n.t("#{name}.#{prefix(options)}", default: default_human_name(options)) end private def default_human_name options = {} if prefix(options) == 'one' @class_name.humanize else ActiveModel::Naming.plural(@klass).humanize end end def prefix options if options[:count] if options[:count] == 1 "one" else "other" end else "one" end end end end Object.class_eval do def lolita_model_name @lolita_model_name ||= Lolita::ModelName.new(self) end end
Version data entries
28 entries across 28 versions & 1 rubygems