Module: Sneaql::Core

Defined in:
lib/sneaql_lib/base.rb,
lib/sneaql_lib/core.rb,
lib/sneaql_lib/parser.rb,
lib/sneaql_lib/recordset.rb,
lib/sneaql_lib/tokenizer.rb,
lib/sneaql_lib/expressions.rb

Overview

contains the base classes for the extendable parts of sneaql:

commands (the actual commands specified in sneaql tags)
repo_managers (used to pull the sql files from a remote or local source)
metadata managers (to get information about each step)

in addition to the base classes, the mapped class/class_map utilities are used to provide a dynamic class system this class system allows you to register a class under a type you can later look up the class by type and a text identifier then instantiate a new instance from there

Defined Under Namespace

Modules: Commands Classes: ExpressionHandler, RecordsetManager, RegisterMappedClass, RepoDownloadManager, SneaqlCommand, StepMetadataManager, StepParser, Tokenizer

Constant Summary collapse

@@class_map =

global map of all classes

{}
@@valid_tokenizer_states =
[
  :outside_word,
  :in_word,
  :in_string_literal,
  :in_string_literal_escape
]
@@tokenizer_state_map =
{
  whitespace: {
    outside_word: [:no_action],
    in_word: [:outside_word],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat]
  },
  escape: {
    outside_word: [:error],
    in_word: [:error],
    in_string_literal: [:in_string_literal_escape],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  word: {
    outside_word: [:new_token, :concat, :in_word],
    in_word: [:concat],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  colon: {
    outside_word: [:new_token, :concat, :in_word],
    in_word: [:concat],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  singlequote: {
    outside_word: [:new_token, :concat, :in_string_literal],
    in_word: [:error],
    in_string_literal: [:concat, :outside_word],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  openbrace: {
    outside_word: [:new_token, :concat, :in_word],
    in_word: [:error],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  closebrace: {
    outside_word: [:error],
    in_word: [:concat],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  operator: {
    outside_word: [:new_token, :concat, :in_word],
    in_word: [:concat],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
  nonword: {
    outside_word: [:new_token, :concat, :in_word],
    in_word: [:concat],
    in_string_literal: [:concat],
    in_string_literal_escape: [:concat, :in_string_literal]
  },
}

Class Method Summary collapse

Class Method Details

.add_mapped_class(type, mapped_class_hash) ⇒ Object

adds a new class to the map

Parameters:

  • type (Symbol)

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

  • mapped_class_hash (Hash)

    in the format { text: text, mapped_class: mapped_class }



28
29
30
31
# File 'lib/sneaql_lib/base.rb', line 28

def self.add_mapped_class(type, mapped_class_hash)
  @@class_map[type] == [] unless @@class_map.keys.include?(type)
  @@class_map[type] << mapped_class_hash
end

.class_mapObject

allows external access to class_map for testing purposes



21
22
23
# File 'lib/sneaql_lib/base.rb', line 21

def self.class_map
  @@class_map
end

.find_class(type, text) ⇒ Class

returns the class referenced by the type/text combination

Parameters:

  • type (Symbol)

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

  • text (String)

    to when searching within this type

Returns:

  • (Class)

    returns the class you are searching for



43
44
45
46
47
# File 'lib/sneaql_lib/base.rb', line 43

def self.find_class(type, text)
  @@class_map[type].each do |t|
    return t[:mapped_class] if t[:text] == text
  end
end

.insure_type_exists(type) ⇒ Object

makes sure that the type exists before appending the class information

Parameters:

  • type (Symbol)

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



35
36
37
# File 'lib/sneaql_lib/base.rb', line 35

def self.insure_type_exists(type)
  @@class_map[type] = [] unless @@class_map.key?(type)
end

.tokenizer_state_mapHash

state machine for use when iterating through the character classifications of a given command. pass in the character c classification and current state and you will receive an array of actions to execute in sequence. these actions include the ability to change state.

Returns:

  • (Hash)


79
80
81
# File 'lib/sneaql_lib/tokenizer.rb', line 79

def self.tokenizer_state_map
  @@tokenizer_state_map
end

.valid_tokenizer_statesArray<Symbol>

these are the states that can be jumped between during tokenization.

Returns:

  • (Array<Symbol>)


12
13
14
# File 'lib/sneaql_lib/tokenizer.rb', line 12

def self.valid_tokenizer_states
  @@valid_tokenizer_states
end