Sha256: 48ddd6bbbb31a7fe88338746029e7b3527de6d9b8e07d0024eb22f17ae652ac6

Contents?: true

Size: 707 Bytes

Versions: 8

Compression:

Stored size: 707 Bytes

Contents

# frozen_string_literal: true

module Esse
  class Index
    module ClassMethods
      attr_writer :type_hash

      def type_hash
        @type_hash ||= {}
      end

      def define_type(type_name, &block)
        type_class = Class.new(Esse::IndexType)

        const_set(Hstring.new(type_name).camelize.demodulize.to_s, type_class)

        index = self

        type_class.send(:define_singleton_method, :index) { index }
        type_class.send(:define_singleton_method, :type_name) { type_name.to_s }

        type_class.class_eval(&block) if block

        self.type_hash = type_hash.merge(type_class.type_name => type_class)
        type_class
      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/type.rb
esse-0.1.3 lib/esse/index/type.rb
esse-0.1.2 lib/esse/index/type.rb
esse-0.1.1 lib/esse/index/type.rb
esse-0.0.5 lib/esse/index/type.rb
esse-0.0.4 lib/esse/index/type.rb
esse-0.0.3 lib/esse/index/type.rb
esse-0.0.2 lib/esse/index/type.rb