Sha256: 4acf073a47a98082adb0e672aae532f73b463d0a1e889b0078b90d873a766706

Contents?: true

Size: 735 Bytes

Versions: 3

Compression:

Stored size: 735 Bytes

Contents

module Hanami
  module Model
    # Conventional name for entities.
    #
    # Given a repository named <tt>SourceFileRepository</tt>, the associated
    # entity will be <tt>SourceFile</tt>.
    #
    # @since 0.7.0
    # @api private
    class EntityName
      # @since 0.7.0
      # @api private
      SUFFIX = /Repository\z/

      # @param name [Class,String] the class or its name
      # @return [String] the entity name
      #
      # @since 0.7.0
      # @api private
      def initialize(name)
        @name = name.sub(SUFFIX, '')
      end

      # @since 0.7.0
      # @api private
      def underscore
        Utils::String.new(@name).underscore.to_sym
      end

      def to_s
        @name
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-model-1.0.0.beta2 lib/hanami/model/entity_name.rb
hanami-model-1.0.0.beta1 lib/hanami/model/entity_name.rb
hanami-model-0.7.0 lib/hanami/model/entity_name.rb