Sha256: b306a501baf0ef60e221d745b4aa49f133d03ad482241943da75df7ad48d7a88
Contents?: true
Size: 1.34 KB
Versions: 3
Compression:
Stored size: 1.34 KB
Contents
module FireAndForget module Command SEPARATOR = "||".freeze def self.load(command) Marshal.load(command) end def self.allowed?(cmd) allowed_commands.include?(cmd.class) end def self.allowed_commands @allowed_commands ||= self.constants.map { |c| self.const_get(c) }.select do |k| k.respond_to?(:ancestors) && k.ancestors.include?(CommandBase) end end class CommandBase attr_reader :tag, :cmd, :params, :task def initialize(task, params={}) @task, @params = task, merge_params(task.params, params) end def dump Marshal.dump(self) end def run # overridden in subclasses end def merge_params(task_params, call_params) params = task_params.to_a.inject({}) do |hash, (key, value)| hash[key.to_s] = value; hash end call_params.each do |key, value| params[key.to_s] = value end if call_params params end end autoload :Fire, "fire_and_forget/command/fire" autoload :Kill, "fire_and_forget/command/kill" autoload :SetStatus, "fire_and_forget/command/set_status" autoload :GetStatus, "fire_and_forget/command/get_status" autoload :SetPid, "fire_and_forget/command/set_pid" autoload :GetPid, "fire_and_forget/command/get_pid" end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
fire_and_forget-0.3.1 | lib/fire_and_forget/command.rb |
fire_and_forget-0.3.0 | lib/fire_and_forget/command.rb |
fire_and_forget-0.2.0 | lib/fire_and_forget/command.rb |