Module: Wash
- Defined in:
- lib/wash.rb,
lib/wash/entry.rb,
lib/wash/method.rb,
lib/wash/streamer.rb
Defined Under Namespace
Modules: Method Classes: Entry, Streamer
Class Method Summary collapse
-
.enable_entry_schemas ⇒ Object
enable_entry_schemas enables Entry schema support.
-
.on_sigterm(&block) ⇒ Object
on_sigterm will execute the provided block when the plugin script receives a SIGTERM/SIGINT signal.
-
.prefetch_entry_schemas ⇒ Object
prefetch_entry_schemas enables schema-prefetching.
-
.pretty_print ⇒ Object
pretty_print enables pretty printing of methods that produce JSON output.
-
.run(root_klass, argv) ⇒ Object
run is the plugin script’s run function.
Class Method Details
.enable_entry_schemas ⇒ Object
enable_entry_schemas enables Entry schema support. See Entry‘s documentation for more details on the available Entry schema helpers.
15 16 17 |
# File 'lib/wash.rb', line 15 def self.enable_entry_schemas @entry_schemas_enabled = true end |
.on_sigterm(&block) ⇒ Object
on_sigterm will execute the provided block when the plugin script receives a SIGTERM/SIGINT signal. It is useful for handling plugin-specific cleanup like dangling processes, files, etc.
42 43 44 |
# File 'lib/wash.rb', line 42 def self.on_sigterm(&block) sigterm_handlers << block end |
.prefetch_entry_schemas ⇒ Object
prefetch_entry_schemas enables schema-prefetching. This option should be enabled once external plugin development’s finished. If the external plugin is not using Entry schemas, then this option can be ignored.
23 24 25 |
# File 'lib/wash.rb', line 23 def self.prefetch_entry_schemas @prefetch_entry_schemas = true end |
.pretty_print ⇒ Object
pretty_print enables pretty printing of methods that produce JSON output. It is a useful debugging tool.
8 9 10 |
# File 'lib/wash.rb', line 8 def self.pretty_print @pretty_print = true end |
.run(root_klass, argv) ⇒ Object
run is the plugin script’s run function. All plugin scripts using this gem should invoke this function once they’ve specified the desired configuration options (e.g. like pretty_print).
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/wash.rb', line 53 def self.run(root_klass, argv) Signal.trap('INT') do handle_sigterm exit 130 end Signal.trap('TERM') do handle_sigterm exit 143 end method, argv = next_arg(argv) if method == "init" config, argv = next_arg(argv) root = root_klass.new unless root.respond_to?(:init) raise "Plugin root #{root.type_id} does not implement init." end config = parse_json(config) root.init(config) if @prefetch_entry_schemas root.prefetch :schema end print_json(root) return end _, argv = next_arg(argv) state, argv = next_arg(argv) state = parse_json(state) klass = const_get(state.delete(:klass)) # Use klass#allocate instead of klass#new to give plugin authors # more freedom in how they decide to setup their constructors entry = klass.allocate entry.send(:restore_state, state) Method.send(:invoke, method, entry, *argv) end |