[DRE-commits] [ruby-aruba] 38/98: Remove default announcer since it's more complicated than it needs to be. Instead support blocks to make lazy evaluating of big data structures possible

Hideki Yamane henrich at moszumanska.debian.org
Tue Mar 22 12:20:37 UTC 2016


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 a83ca17f20f1fca42de9f2520edbb94dfd88ea3f
Author: Dennis Günnewig <dg1 at ratiodata.de>
Date:   Mon Jan 4 10:20:55 2016 +0100

    Remove default announcer since it's more complicated than it needs to be. Instead support blocks to make lazy evaluating of big data structures possible
---
 lib/aruba/platforms/announcer.rb | 34 +++++++++++++++-------------------
 lib/aruba/setup.rb               |  6 ++++--
 2 files changed, 19 insertions(+), 21 deletions(-)

diff --git a/lib/aruba/platforms/announcer.rb b/lib/aruba/platforms/announcer.rb
index 1c0105f..31ac2be 100644
--- a/lib/aruba/platforms/announcer.rb
+++ b/lib/aruba/platforms/announcer.rb
@@ -24,17 +24,6 @@ module Aruba
     #   Aruba.announcer.announce(:my_channel, 'my message')
     #
     class Announcer
-      # Dev null
-      class NullAnnouncer
-        def announce(*)
-          nil
-        end
-
-        def mode?(*)
-          true
-        end
-      end
-
       # Announcer using Kernel.puts
       class KernelPutsAnnouncer
         def announce(message)
@@ -59,7 +48,7 @@ module Aruba
 
       private
 
-      attr_reader :announcers, :default_announcer, :announcer, :channels, :output_formats
+      attr_reader :announcers, :announcer, :channels, :output_formats
 
       public
 
@@ -67,9 +56,7 @@ module Aruba
         @announcers = []
         @announcers << PutsAnnouncer.new
         @announcers << KernelPutsAnnouncer.new
-        @announcers << NullAnnouncer.new
 
-        @default_announcer = @announcers.last
         @announcer         = @announcers.first
         @channels          = {}
         @output_formats    = {}
@@ -135,7 +122,6 @@ module Aruba
 
       # Reset announcer
       def reset
-        @default_announcer = @announcers.last
         @announcer         = @announcers.first
       end
 
@@ -174,7 +160,11 @@ module Aruba
       #
       # @param [Array] args
       #   Arguments
-      def announce(channel, *args)
+      #
+      # @yield
+      #   If block is given, that one is called and the return value is used as
+      #   message to be announced.
+      def announce(channel, *args, &block)
         channel = channel.to_sym
 
         the_output_format = if output_formats.key? channel
@@ -183,11 +173,17 @@ module Aruba
                               proc { |v| format('%s', v) }
                             end
 
-        message = the_output_format.call(*args)
+        return unless activated?(channel)
+
+        message = if block_given?
+                    the_output_format.call(block.call)
+                  else
+                    the_output_format.call(*args)
+                  end
 
-        announcer.announce(message) if channels[channel]
+        announcer.announce(message)
 
-        default_announcer.announce message
+        nil
       end
 
       # @deprecated
diff --git a/lib/aruba/setup.rb b/lib/aruba/setup.rb
index c646ae6..00bfac3 100644
--- a/lib/aruba/setup.rb
+++ b/lib/aruba/setup.rb
@@ -52,8 +52,10 @@ module Aruba
       runtime.event_bus.register(
         :command_stopped,
         proc do |event|
-          runtime.announcer.announce :stdout, event.entity.stdout
-          runtime.announcer.announce :stderr, event.entity.stderr
+          runtime.announcer.announce(:stdout) { event.entity.stdout }
+          runtime.announcer.announce(:stderr) { event.entity.stderr }
+          runtime.announcer.announce(:command_content) { event.entity.content }
+          runtime.announcer.announce(:command_filesystem_status) { event.entity.filesystem_status }
         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