Class: Misc::Script

Inherits:
Object
  • Object
show all
Includes:
AttributesReader
Defined in:
lib/misc/script.rb

Overview

Script represents used-defined input that can be used to compile and execute a script from the ScriptService based on the ScriptType.

Instance Method Summary collapse

Methods included from AttributesReader

#attributes

Constructor Details

#initialize(id_or_code:, params: {}, type: Enums::ScriptTypes.inline, lang: 'painless', options: {}) ⇒ Script

Returns a new instance of Script.

Parameters:

  • id_or_code (String)
  • params (Hash) (defaults to: {})
  • type (Enums::ScriptTypes) (defaults to: Enums::ScriptTypes.inline)

    : Enums::ScriptTypes.(inline|stored), defaults to Enums::ScriptTypes.inline

  • lang (String) (defaults to: 'painless')
  • options (Hash) (defaults to: {})


15
16
17
18
19
20
21
# File 'lib/misc/script.rb', line 15

def initialize(id_or_code:, params: {}, type: Enums::ScriptTypes.inline, lang: 'painless', options: {})
  @id_or_code = id_or_code
  @params = params
  @type = type
  @lang = lang
  @options = options
end

Instance Method Details

#id_or_code_exprString

Returns:

  • (String)


38
39
40
# File 'lib/misc/script.rb', line 38

def id_or_code_expr
  @id_or_code
end

#lang_exprString

Returns:

  • (String)


53
54
55
# File 'lib/misc/script.rb', line 53

def lang_expr
  @lang
end

#options_exprHash

Returns:

  • (Hash)


58
59
60
# File 'lib/misc/script.rb', line 58

def options_expr
  @options
end

#params_exprHash

Returns:

  • (Hash)


43
44
45
# File 'lib/misc/script.rb', line 43

def params_expr
  @params
end

#settingsObject

return [Hash]



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/misc/script.rb', line 24

def settings
  settings = {}
  if @type.script_type == Enums::ScriptTypes.inline.script_type
    settings[:source] = @id_or_code
  else
    settings[:id] = @id_or_code
  end
  settings[:lang] = @lang if @lang.present?
  settings[:params] = @params if @params.present?
  settings[:options] = @options if @options.present?
  settings
end

#type_exprEnums::ScriptTypes

Returns:



48
49
50
# File 'lib/misc/script.rb', line 48

def type_expr
  @type
end