hirb 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ == 0.4.2
2
+ * Fix bug with Tempfile and to_a_exceptions
3
+
1
4
  == 0.4.1
2
5
  * Fix bug with rendering empty hash
3
6
  * Add missing yaml require
@@ -3,6 +3,7 @@ module Hirb
3
3
  # for its class and/or ancestry.
4
4
  class Formatter
5
5
  TO_A_EXCEPTIONS = [Hash, IO]
6
+ POSSIBLE_TO_A_EXCEPTIONS = %w{Tempfile}
6
7
 
7
8
  class<<self
8
9
  # This config is used by Formatter.format_output to lazily load dynamic views defined with Hirb::DynamicView.
@@ -53,6 +54,12 @@ module Hirb
53
54
  _format_output(output, options, &block)
54
55
  end
55
56
 
57
+ # Array of classes whose objects respond to :to_a and are exceptions to the Formatter's array algorithm.
58
+ def to_a_exceptions
59
+ @to_a_exceptions ||= TO_A_EXCEPTIONS + POSSIBLE_TO_A_EXCEPTIONS.select {|e|
60
+ Object.const_defined?(e) }.map {|e| Object.const_get(e) }
61
+ end
62
+
56
63
  #:stopdoc:
57
64
  def _format_output(output, options, &block)
58
65
  output = options[:output_method] ? (output.is_a?(Array) ?
@@ -77,7 +84,7 @@ module Hirb
77
84
  end
78
85
 
79
86
  def determine_output_class(output)
80
- output.respond_to?(:to_a) && !TO_A_EXCEPTIONS.any? {|e| output.is_a?(e) } ?
87
+ output.respond_to?(:to_a) && !to_a_exceptions.any? {|e| output.is_a?(e) } ?
81
88
  Array(output)[0].class : output.class
82
89
  end
83
90
 
@@ -1,3 +1,3 @@
1
1
  module Hirb
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
@@ -12,4 +12,4 @@ module Ripl::Hirb
12
12
  end
13
13
  end
14
14
 
15
- Ripl::Shell.send :include, Ripl::Hirb
15
+ Ripl::Shell.include Ripl::Hirb
@@ -72,6 +72,11 @@ describe "Formatter" do
72
72
  @formatter.parse_console_options(options).should == expected_options
73
73
  end
74
74
 
75
+ it "#determine output_class bypasses optional exceptions for to_a" do
76
+ require 'tempfile'
77
+ @formatter.determine_output_class(Tempfile.new('')).should == Tempfile
78
+ end
79
+
75
80
  it "#determine_output_class bypasses exceptions for to_a" do
76
81
  @formatter.determine_output_class(STDOUT).should == IO
77
82
  @formatter.determine_output_class({:a=>1}).should == Hash
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hirb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 1
10
- version: 0.4.1
9
+ - 2
10
+ version: 0.4.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gabriel Horner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-26 00:00:00 -04:00
18
+ date: 2011-03-27 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency