Class: Sneaql::Core::RegisterMappedClass

Inherits:
Object
  • Object
show all
Defined in:
lib/sneaql_lib/base.rb

Overview

Handles registration of a class to the class_map Ignores duplicate definitions if they occur

Instance Method Summary collapse

Constructor Details

#initialize(type, text, mapped_class) ⇒ RegisterMappedClass

Registers the class into the class_map.

Parameters:

  • type (Symbol)

    class type (user settable, can be :command, :repo_manager, etc)

  • text (String)

    to when searching within this type

  • mapped_class (Class)

    class to be returned when search matches type and text



56
57
58
59
60
61
62
63
64
65
# File 'lib/sneaql_lib/base.rb', line 56

def initialize(type, text, mapped_class)
  Sneaql::Core.insure_type_exists(type)
  # check to see if the reference text is already being used by this type
  unless Sneaql::Core.class_map[type].map { |c| c[:text] }.include?(text)
    Sneaql::Core.add_mapped_class(
      type,
      { text: text, mapped_class: mapped_class }
    )
  end
end