Class: Spade::Runtime::MainContext
- Defined in:
- lib/spade/runtime/context.rb
Overview
The primary context created when running spade exec or spade console. This context will also automatically start a reactor loop.
Instance Attribute Summary collapse
-
#caller_id ⇒ Object
Returns the value of attribute caller_id.
-
#rootdir ⇒ Object
Returns the value of attribute rootdir.
Attributes inherited from Context
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ MainContext
constructor
Load the spade and racer-loader.
Methods inherited from Context
Constructor Details
#initialize(opts = {}) ⇒ MainContext
Load the spade and racer-loader.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/spade/runtime/context.rb', line 70 def initialize(opts={}) env = opts[:env] || ENV @rootdir = opts[:rootdir] || opts['rootdir'] @caller_id = opts[:caller_id] || opts['caller_id'] @reactor = opts[:reactor] ||= Reactor.new(self) lang = opts[:language] ||= (env['LANG']||'en_US').gsub(/\..*/, '') lang = lang.gsub '_', '-' super(opts) do |ctx| ctx['ENV'] = env.to_hash ctx['ENV']['SPADE_PLATFORM'] = { 'ENGINE' => 'spade' } ctx['ENV']['LANG'] = lang ctx['ARGV'] = opts[:argv] || ARGV # Load spade and patch in compiler and loader plugins ctx.load(Spade::JSPATH) ctx['rubyLoader'] = Loader.new(self) ctx['rubyCompiler'] = Compiler.new(self) ctx.eval %[ spade.loader = rubyLoader; spade.compiler = rubyCompiler; spade.defaultSandbox.rootdir = #{@rootdir.to_json}; spade.globalize(); ] ctx.eval("spade.defaultSandbox.callerId = #{@caller_id.to_json};") if @caller_id ctx['rubyLoader'] = ctx['rubyCompiler'] = nil @reactor.start do yield(self) if block_given? end end end |
Instance Attribute Details
#caller_id ⇒ Object
Returns the value of attribute caller_id.
67 68 69 |
# File 'lib/spade/runtime/context.rb', line 67 def caller_id @caller_id end |
#rootdir ⇒ Object
Returns the value of attribute rootdir.
66 67 68 |
# File 'lib/spade/runtime/context.rb', line 66 def rootdir @rootdir end |