Sha256: d03e52e3ea52c5347ee128e171e7425effa1c88e7f725e090263deeb4b155e29
Contents?: true
Size: 1.59 KB
Versions: 46
Compression:
Stored size: 1.59 KB
Contents
module ActiveAdmin class Resource module Naming def resource_name @resource_name ||= begin as = @options[:as].gsub /\s/, '' if @options[:as] if as || !resource_class.respond_to?(:model_name) Name.new resource_class, as else Name.new resource_class end end end # Returns the name to call this resource such as "Bank Account" def resource_label resource_name.translate count: 1, default: resource_name.to_s.gsub('::', ' ').titleize end # Returns the plural version of this resource such as "Bank Accounts" def plural_resource_label(options = {}) defaults = {count: Helpers::I18n::PLURAL_MANY_COUNT, default: resource_label.pluralize.titleize} resource_name.translate defaults.merge options end # Forms use the model's original `param_key`, so we can't use our # custom `resource_name` when the model's been renamed in ActiveAdmin. def param_key if resource_class.respond_to? :model_name resource_class.model_name.param_key else resource_name.param_key end end end class Name < ActiveModel::Name delegate :hash, to: :to_str def initialize(klass, name = nil) super(klass, nil, name) end def translate(options = {}) I18n.t i18n_key, {scope: [:activerecord, :models]}.merge(options) end def route_key plural end def eql?(other) to_str.eql?(other.to_str) end end end end
Version data entries
46 entries across 46 versions & 5 rubygems