Sha256: 095f4a98b8ed5a67b831f6a4e2bebfff1bd67be106060712021169bdb1d4e84c

Contents?: true

Size: 1.3 KB

Versions: 8

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Esse
  class Index
    module ClassMethods
      TEMPLATE_DIRS = [
        '%<dirname>s/templates',
        '%<dirname>s'
      ].freeze

      def index_name=(value)
        @index_name = index_prefixed_name(value)
      end

      def index_name
        @index_name || index_prefixed_name(normalized_name)
      end

      def index_name?
        !index_name.nil?
      end

      def index_version=(value)
        @index_version = Hstring.new(value.to_s).underscore.presence
      end

      def index_version
        @index_version
      end

      def uname
        Hstring.new(name).underscore.presence
      end

      def index_directory
        return unless uname
        return if uname == 'Esse::Index'

        Esse.config.indices_directory.join(uname).to_s
      end

      def template_dirs
        return [] unless index_directory

        TEMPLATE_DIRS.map { |term| format(term, dirname: index_directory) }
      end

      protected

      def index_prefixed_name(value)
        return if value == '' || value.nil?
        return value.to_s unless cluster.index_prefix

        [cluster.index_prefix, value].join('_')
      end

      def normalized_name
        Hstring.new(name).demodulize.underscore.sub(/_(index)$/, '')
      end
    end

    extend ClassMethods
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
esse-0.2.0 lib/esse/index/naming.rb
esse-0.1.3 lib/esse/index/naming.rb
esse-0.1.2 lib/esse/index/naming.rb
esse-0.1.1 lib/esse/index/naming.rb
esse-0.0.5 lib/esse/index/naming.rb
esse-0.0.4 lib/esse/index/naming.rb
esse-0.0.3 lib/esse/index/naming.rb
esse-0.0.2 lib/esse/index/naming.rb