table_print icon indicating copy to clipboard operation
table_print copied to clipboard

Assumes all data has all columns found through `handleable_columns`

Open haf opened this issue 12 years ago • 2 comments

In this code in fingerprinter.rb:

 35       handleable_columns(hash).each do |method|
 36         display_method = (prefix == "" ? method : "#{prefix}.#{method}")
 37         if method.is_a? Proc
 38           cell_value = method.call(target)
 39         elsif target.is_a? Hash and target.keys.include? method.to_sym
 40           cell_value = target[method.to_sym]
 41         elsif target.is_a? Hash and target.keys.include? method
 42           cell_value = target[method]
 43         else
 44           cell_value ||= target.send(method)
 45         end
 46         cells[@column_names_by_display_method[display_method]] = cell_value
 47       end

Replace line 43 for:

elsif target.respond_to? method

And you don't get crashes like this, anymore:

/Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:44:in `block in populate_row': undefined method `PrivateIpAddress' for #<Hash:0x007fe92a89d6e8> (NoMethodError)
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:35:in `each'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:35:in `populate_row'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:19:in `block in hash_to_rows'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:18:in `each'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:18:in `hash_to_rows'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print/fingerprinter.rb:9:in `lift'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:36:in `block in table_print'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:35:in `each'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:35:in `table_print'
  from /Users/xyz/.rvm/gems/ruby-1.9.3-p374/gems/table_print-1.1.5/lib/table_print.rb:66:in `tp'
  from ./to-table.rb:14:in `<main>'

haf avatar Aug 26 '13 20:08 haf

cool, thanks! I do get those all the time and just never bothered to look into it :)

arches avatar Aug 26 '13 21:08 arches

need a similar fix on line 58 to handle missing associations

arches avatar Sep 01 '13 00:09 arches