lib/comma.rb in crafterm-comma-0.1.6 vs lib/comma.rb in crafterm-comma-0.1.7

- old
+ new

@@ -3,10 +3,11 @@ require 'comma/extractors' class Array def to_comma(style = :default) FasterCSV.generate do |csv| + return "" if empty? csv << first.to_comma_headers(style) each do |object| csv << object.to_comma(style) end end @@ -39,14 +40,16 @@ base.alias_method_chain :render, :csv end module InstanceMethods def render_with_csv(options = nil, extra_options = {}, &block) - return render_without_csv(options, extra_options, &block) unless options and options[:csv] - send_data Array(options[:csv]).to_comma(options[:style] ||= :default) + return render_without_csv(options, extra_options, &block) unless (options.respond_to? '[]') and options[:csv] + data = options.delete(:csv) + style = options.delete(:style) || :default + send_data Array(data).to_comma(style), options.merge(:type => :csv) end end end ActionController::Base.send :include, RenderAsCSV -end \ No newline at end of file +end