[DRE-commits] [ruby-aruba] 42/98: Unsorted simple table by request

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

    Unsorted simple table by request
---
 lib/aruba/platforms/simple_table.rb  | 23 ++++++++++++++++++-----
 lib/aruba/platforms/unix_platform.rb |  4 ++--
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/lib/aruba/platforms/simple_table.rb b/lib/aruba/platforms/simple_table.rb
index 5168cc9..69f06c5 100644
--- a/lib/aruba/platforms/simple_table.rb
+++ b/lib/aruba/platforms/simple_table.rb
@@ -6,7 +6,7 @@ module Aruba
     class SimpleTable
       private
 
-      attr_reader :hash
+      attr_reader :hash, :opts
 
       public
 
@@ -14,8 +14,11 @@ module Aruba
       #
       # @param [Hash] hash
       #   Input
-      def initialize(hash)
+      def initialize(hash, opts)
         @hash = hash
+        @opts = {
+          :sort => true
+        }.merge opts
       end
 
       # Generate table
@@ -35,11 +38,21 @@ module Aruba
             rows << format("# %-#{name_size}s => %s", k, v)
           end
 
-          rows.sort
+          if opts[:sort] == true
+            rows.sort
+          else
+            rows
+          end
         else
-          hash.each_with_object([]) do |(k,v), a|
+          result = hash.each_with_object([]) do |(k,v), a|
             a << format("# %-#{name_size}s => %s", k, v)
-          end.sort
+          end
+
+          if opts[:sort] == true
+            result.sort
+          else
+            result
+          end
         end
       end
     end
diff --git a/lib/aruba/platforms/unix_platform.rb b/lib/aruba/platforms/unix_platform.rb
index 6c218e3..8b6b12a 100644
--- a/lib/aruba/platforms/unix_platform.rb
+++ b/lib/aruba/platforms/unix_platform.rb
@@ -250,8 +250,8 @@ module Aruba
       end
 
       # Transform hash to a string table which can be output on stderr/stdout
-      def simple_table(hash)
-        SimpleTable.new(hash).to_s
+      def simple_table(hash, opts = {})
+        SimpleTable.new(hash, opts).to_s
       end
 
       # Resolve path for command using the PATH-environment variable

-- 
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