Sha256: a8520f02468dbb26c0fca3a02e7c472ac386536245fb42b54427003f6f403244

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

module ActiveAdmin
  class Resource
    module Naming

      # An underscored safe representation internally for this resource
      def underscored_resource_name
        @underscored_resource_name ||= if @options[:as]
          @options[:as].gsub(' ', '').underscore.singularize
        else
          resource.name.gsub('::','').underscore
        end
      end

      # A camelized safe representation for this resource
      def camelized_resource_name
        underscored_resource_name.camelize
      end

      # Returns the name to call this resource.
      # By default will use resource.model_name.human
      def resource_name
        @resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)
          underscored_resource_name.titleize
        else
          resource.model_name.human.titleize
        end
      end

      # Returns the plural version of this resource
      def plural_resource_name
        @plural_resource_name ||= if @options[:as] || !resource.respond_to?(:model_name)
          resource_name.pluralize
        else
          # Check if we have a translation available otherwise pluralize
          begin
            I18n.translate!("activerecord.models.#{resource.model_name.downcase}")
            resource.model_name.human(:count => 3)
          rescue I18n::MissingTranslationData
            resource_name.pluralize
          end
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activeadmin-0.3.1 lib/active_admin/resource/naming.rb
activeadmin-0.3.0 lib/active_admin/resource/naming.rb