Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ar_dumper_controller.rb

Constant Summary collapse

@@dumper_target =
:tmp_file

Instance Method Summary collapse

Instance Method Details

#send_file_dump(format, klass, send_options = {}, dump_options = {}) ⇒ Object

send a dumped file Options are:

  • klass - the active record to use. Animal or Contact or Author or Tumama

  • send_options send_options include send_file options such as :type and :disposition

  • dump_options options to send to the dumper. These options are in ArDumper.dump_to_csv

  • :find - a map of the finder options passed to find. For example, + => [‘features.hair = ?’, ‘blonde’], :include => :features +

  • :header - when a hash is specified, maps the field name to the header name. For example => ‘COL A’, :b => ‘COL B’ would print ‘COL A’, ‘COL B’

    when an array is specified uses this instead of the fields
    when true or by default prints the fields
    when false does not include a header
    
  • :csv - any options to pass to csv parser. Example + :csv => => “t” +

  • :page_size - the page size to use. Defaults to dumper_page_size or 50



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ar_dumper_controller.rb', line 20

def send_file_dump(format, klass, send_options={}, dump_options={})

  #use the base name of the dump file name if specified
  send_options[:filename] ||= File.basename(dump_options[:filename]) if dump_options[:filename]
  
  #never delete the file
  dump_options[:delete_file] = false
  
  #use temporary files unless otherwise specified
  dump_options[:target_type]||= @@dumper_target
      
  #send_options[:type] = 'application/xml; charset=utf-8;'
  if send_options[:type].nil? && send_options[:disposition] == 'inline'
    send_options[:type] =
      case format.to_sym
        when :xml then 'application/xml; charset=utf-8;'
        when :csv then 'application/csv; charset=utf-8;'
        when :yml then 'text/html; charset=utf-8;'
      end

  end

  target = klass.dumper(format, dump_options)
  
  if dump_options[:target_type] == :string
    send_data(target, send_options)
  else
    send_file(target, send_options)
  end
end