[DRE-commits] [ruby-aruba] 15/74: Added null process to make duck typing for nil values easier

Hideki Yamane henrich at moszumanska.debian.org
Sat Nov 28 01:16:30 UTC 2015


This is an automated email from the git hooks/post-receive script.

henrich pushed a commit to branch debian/sid
in repository ruby-aruba.

commit d8c513379e70632d8a8101a6a8c1369887a7233e
Author: Max Meyer <dev at fedux.org>
Date:   Tue Nov 24 10:11:29 2015 +0100

    Added null process to make duck typing for nil values easier
---
 lib/aruba/command.rb                |  1 +
 lib/aruba/process_monitor.rb        | 23 +++++++++++++++++++++++
 lib/aruba/processes/null_process.rb | 22 ++++++++++++++++++++++
 3 files changed, 46 insertions(+)

diff --git a/lib/aruba/command.rb b/lib/aruba/command.rb
index 99fcb64..13b360c 100644
--- a/lib/aruba/command.rb
+++ b/lib/aruba/command.rb
@@ -8,6 +8,7 @@ module Aruba
       launchers = []
       launchers << Processes::DebugProcess
       launchers << Processes::InProcess
+      launchers << Processes::NullProcess
       launchers << Processes::SpawnProcess
 
       launcher = launchers.find { |l| l.match? opts[:mode] }
diff --git a/lib/aruba/process_monitor.rb b/lib/aruba/process_monitor.rb
index 58d792d..91f0af8 100644
--- a/lib/aruba/process_monitor.rb
+++ b/lib/aruba/process_monitor.rb
@@ -1,3 +1,5 @@
+require 'aruba/processes/null_process'
+
 module Aruba
   class ProcessMonitor
     private
@@ -21,6 +23,16 @@ module Aruba
 
     def last_command_stopped
       return @last_command_stopped if @last_command_stopped
+      return Command.new('false',
+        :mode              => :null,
+        :exit_timeout      => 0,
+        :io_wait_timeout   => 0,
+        :working_directory => '/tmp',
+        :environment       => {},
+        :main_class        => nil,
+        :stop_signal       => nil,
+        :startup_wait_time => nil
+      ) if all_commands.empty?
 
       all_commands.each { |c| stop_process(c) }
 
@@ -28,6 +40,17 @@ module Aruba
     end
 
     def last_command_started
+      return Command.new('false',
+        :mode              => :null,
+        :exit_timeout      => 0,
+        :io_wait_timeout   => 0,
+        :working_directory => '/tmp',
+        :environment       => {},
+        :main_class        => nil,
+        :stop_signal       => nil,
+        :startup_wait_time => nil
+      ) unless processes.last.is_a? Array
+
       processes.last[1]
     end
 
diff --git a/lib/aruba/processes/null_process.rb b/lib/aruba/processes/null_process.rb
new file mode 100644
index 0000000..557cc5a
--- /dev/null
+++ b/lib/aruba/processes/null_process.rb
@@ -0,0 +1,22 @@
+require 'aruba/processes/basic_process'
+
+module Aruba
+  module Processes
+    # Null Process
+    class NullProcess < BasicProcess
+      def self.match?(mode)
+        mode == :null
+      end
+
+      # Pid
+      def pid
+        0
+      end
+
+      # String representation
+      def to_s
+        ''
+      end
+    end
+  end
+end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-aruba.git



More information about the Pkg-ruby-extras-commits mailing list