Module: Philiprehberger::SafeExec
- Defined in:
- lib/philiprehberger/safe_exec.rb,
lib/philiprehberger/safe_exec/parser.rb,
lib/philiprehberger/safe_exec/version.rb,
lib/philiprehberger/safe_exec/compiled.rb,
lib/philiprehberger/safe_exec/evaluator.rb,
lib/philiprehberger/safe_exec/tokenizer.rb
Defined Under Namespace
Modules: Tokenizer Classes: Compiled, Error, Evaluator, Parser, TimeoutError
Constant Summary collapse
- DEFAULT_TIMEOUT =
5- BUILTIN_FUNCTIONS =
%w[min max abs length round sqrt ceil floor pow upcase downcase trim].freeze
- VERSION =
'0.4.0'
Class Method Summary collapse
-
.compile(expr) ⇒ Compiled
Pre-parse an expression so it can be evaluated repeatedly against different contexts without re-tokenizing or re-parsing.
-
.evaluate(expr, context = {}, timeout: DEFAULT_TIMEOUT) ⇒ Object
Evaluate a sandboxed expression with an optional context.
Class Method Details
.compile(expr) ⇒ Compiled
Pre-parse an expression so it can be evaluated repeatedly against different contexts without re-tokenizing or re-parsing.
37 38 39 |
# File 'lib/philiprehberger/safe_exec.rb', line 37 def self.compile(expr) Compiled.new(expr) end |
.evaluate(expr, context = {}, timeout: DEFAULT_TIMEOUT) ⇒ Object
Evaluate a sandboxed expression with an optional context
27 28 29 |
# File 'lib/philiprehberger/safe_exec.rb', line 27 def self.evaluate(expr, context = {}, timeout: DEFAULT_TIMEOUT) compile(expr).evaluate(context, timeout: timeout) end |