Module: Low::ExpressionHelpers

Included in:
Evaluator
Defined in:
lib/expressions/expression_helpers.rb

Instance Method Summary collapse

Instance Method Details

#type(type_expression) ⇒ Object Also known as: low_type



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/expressions/expression_helpers.rb', line 9

def type(type_expression)
  value = type_expression.default_value

  last_caller = caller_locations(1, 1).first
  file_path = last_caller.path
  start_line = last_caller.lineno
  proxy = LocalProxy.new(type_expression:, name: self, file_path:, start_line:, scope: 'local type')

  type_expression.validate!(value:, proxy:)

  return value.value if value.is_a?(ValueExpression)

  value
rescue NoMethodError
  raise ConfigError, "Invalid type expression. Did you add 'using LowType::Syntax'?"
end

#value(type) ⇒ Object Also known as: low_value



27
28
29
# File 'lib/expressions/expression_helpers.rb', line 27

def value(type)
  TypeExpression.new(default_value: ValueExpression.new(value: type))
end