Class: Nodo::Core
Constant Summary collapse
- SOCKET_NAME =
'nodo.sock'- DEFINE_METHOD =
'__nodo_define_class__'.freeze
- EVALUATE_METHOD =
'__nodo_evaluate__'.freeze
- GC_METHOD =
'__nodo_gc__'.freeze
- INTERNAL_METHODS =
[DEFINE_METHOD, EVALUATE_METHOD, GC_METHOD].freeze
- LAUNCH_TIMEOUT =
5- ARRAY_CLASS_ATTRIBUTES =
%i[dependencies constants scripts].freeze
- HASH_CLASS_ATTRIBUTES =
%i[functions].freeze
- CLASS_ATTRIBUTES =
(ARRAY_CLASS_ATTRIBUTES + HASH_CLASS_ATTRIBUTES).freeze
- @@node_pid =
nil- @@tmpdir =
nil- @@mutex =
Mutex.new
- @@exiting =
nil
Class Attribute Summary collapse
-
.class_defined ⇒ Object
Returns the value of attribute class_defined.
Class Method Summary collapse
- .class_defined? ⇒ Boolean
- .clsid ⇒ Object
- .generate_class_code ⇒ Object
- .generate_core_code ⇒ Object
- .inherited(subclass) ⇒ Object
- .instance ⇒ Object
Instance Method Summary collapse
- #evaluate(code) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
Constructor Details
#initialize ⇒ Core
Returns a new instance of Core.
144 145 146 147 148 149 150 151 |
# File 'lib/nodo/core.rb', line 144 def initialize raise ClassError, :new if self.class == Nodo::Core @@mutex.synchronize do ensure_process_is_spawned wait_for_socket ensure_class_is_defined end end |
Class Attribute Details
.class_defined ⇒ Object
Returns the value of attribute class_defined.
21 22 23 |
# File 'lib/nodo/core.rb', line 21 def class_defined @class_defined end |
Class Method Details
.class_defined? ⇒ Boolean
33 34 35 |
# File 'lib/nodo/core.rb', line 33 def class_defined? !!class_defined end |
.clsid ⇒ Object
37 38 39 |
# File 'lib/nodo/core.rb', line 37 def clsid name || "Class:0x#{object_id.to_s(0x10)}" end |
.generate_class_code ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/nodo/core.rb', line 83 def generate_class_code <<~JS (() => { const __nodo_klass__ = { nodo: global.nodo }; #{dependencies.map(&:to_js).join} #{constants.map(&:to_js).join} #{functions.values.map(&:to_js).join} #{scripts.map(&:to_js).join} return __nodo_klass__; })() JS end |
.generate_core_code ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/nodo/core.rb', line 60 def generate_core_code <<~JS global.nodo = require(#{nodo_js}); const socket = process.argv[1]; if (!socket) { process.stderr.write('Socket path is required\\n'); process.exit(1); } process.title = `nodo-core ${socket}`; const shutdown = () => { nodo.core.close(() => { process.exit(0) }); }; // process.on('SIGINT', shutdown); process.on('SIGTERM', shutdown); nodo.core.run(socket); JS end |
.inherited(subclass) ⇒ Object
23 24 25 26 27 |
# File 'lib/nodo/core.rb', line 23 def inherited(subclass) CLASS_ATTRIBUTES.each do |attr| subclass.send "#{attr}=", send(attr).dup end end |
.instance ⇒ Object
29 30 31 |
# File 'lib/nodo/core.rb', line 29 def instance @instance ||= new end |
Instance Method Details
#evaluate(code) ⇒ Object
153 154 155 156 |
# File 'lib/nodo/core.rb', line 153 def evaluate(code) ensure_context_is_defined call_js_method(EVALUATE_METHOD, code) end |