Module: Legion::Extensions::Helpers::Lex

Includes:
Core, Logger
Included in:
Actors::Base, Core
Defined in:
lib/legion/extensions/helpers/lex.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#handle_exception, #log

Methods included from Core

#find_setting, #settings

Methods included from Base

#actor_class, #actor_const, #actor_name, #calling_class, #calling_class_array, #from_json, #full_path, #lex_class, #lex_const, #lex_name, #normalize, #runner_class, #runner_const, #runner_name, #to_dotted_hash

Class Method Details

.included(base) ⇒ Object



36
37
38
39
40
# File 'lib/legion/extensions/helpers/lex.rb', line 36

def self.included(base)
  base.send :extend, Legion::Extensions::Helpers::Core if base.instance_of?(Class)
  base.send :extend, Legion::Extensions::Helpers::Logger if base.instance_of?(Class)
  base.extend base if base.instance_of?(Module)
end

Instance Method Details

#default_settingsObject



42
43
44
# File 'lib/legion/extensions/helpers/lex.rb', line 42

def default_settings
  { logger: { level: 'info' }, workers: 1, runners: {}, functions: {} }
end

#function_desc(function, desc) ⇒ Object



16
17
18
# File 'lib/legion/extensions/helpers/lex.rb', line 16

def function_desc(function, desc)
  function_set(function, :desc, desc)
end

#function_example(function, example) ⇒ Object



8
9
10
# File 'lib/legion/extensions/helpers/lex.rb', line 8

def function_example(function, example)
  function_set(function, :example, example)
end

#function_options(function, options) ⇒ Object



12
13
14
# File 'lib/legion/extensions/helpers/lex.rb', line 12

def function_options(function, options)
  function_set(function, :options, options)
end

#function_set(function, key, value) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/helpers/lex.rb', line 20

def function_set(function, key, value)
  unless respond_to? function
    log.debug "function_#{key} called but function doesn't exist, f: #{function}"
    return nil
  end
  settings[:functions] = {} if settings[:functions].nil?
  settings[:functions][function] = {} if settings[:functions][function].nil?
  settings[:functions][function][key] = value
end

#runner_desc(desc) ⇒ Object



30
31
32
33
34
# File 'lib/legion/extensions/helpers/lex.rb', line 30

def runner_desc(desc)
  settings[:runners] = {} if settings[:runners].nil?
  settings[:runners][actor_name.to_sym] = {} if settings[:runners][actor_name.to_sym].nil?
  settings[:runners][actor_name.to_sym][:desc] = desc
end