Class: ActionController::Base
Instance Method Summary collapse
-
#amber_execute(code, options = {}) ⇒ Object
The amber_execute executes a string of code with a certein behavior and returns not the result but what was written in the special :render variable of the environment.
-
#amber_reder(code, options = {}) ⇒ Object
This function allows to render code that gets compiled by amber.
Instance Method Details
#amber_execute(code, options = {}) ⇒ Object
The amber_execute executes a string of code with a certein behavior and returns not the result but what was written in the special :render variable of the environment.
The folowing options can be passed to it to influence it’s behaviro.
- :language
-
The language that should be used to compile the code, be adwised that it is nessessary to load this prior to executing it.
- :environment
-
This allows to pass a own environment, for example to publish
variables or to maintain state between executions.
- :object
-
If this is set the code will be executed in the context of the object passed, this using it’s local variable storage and it’s functions. Be aware that when using :object and :environment togehter, variables set in the code will NOT go in the environment as they are local in the object.
- :timeout
-
This is used to limit the execution time of the code, it can be used to prevent runaway processes beeing executed. Very helpfull when the code executed isn’t 100% trunstworty.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/amber/rails.rb', line 68 def amber_execute code, = {} = { :language => :ecma, :environment => AmberVM::Interpreter.env }.merge() compiler = AmberVM::Languages[[:language]].new code = compiler.compile(code) code = AmberVM::Interpreter::ObjectContext.new(AmberVM::Interpreter::Constant.new([:object]), code) if [:object] if [:environment][:render].is_a? AmberVM::Classes::Error or [:environment][:render].nil? [:environment][:render] = "" end puts [:environment][:render].inspect if [:timeout] s = AmberVM::Safety.new :timeout => [:timeout] s.execute(code, [:environment]) else code.execute([:environment]) end [:environment][:render].val end |
#amber_reder(code, options = {}) ⇒ Object
This function allows to render code that gets compiled by amber. The first parameter passed is the code to compile, a string most likely, the second is a hash that is passed to the render function, see the Rails API doc for details on what to put there.
In addition to those rails specifc parameters amber_render accepts 4 additioal parameters.They are the same as used in amber_execute
.
42 43 44 |
# File 'lib/amber/rails.rb', line 42 def amber_reder code, = {} render .merge({:text => amber_execute(code, )}) end |