datashift 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/README.markdown +91 -55
  3. data/VERSION +1 -1
  4. data/datashift.gemspec +8 -23
  5. data/lib/applications/jexcel_file.rb +1 -2
  6. data/lib/datashift.rb +34 -15
  7. data/lib/datashift/column_packer.rb +98 -34
  8. data/lib/datashift/data_transforms.rb +83 -0
  9. data/lib/datashift/delimiters.rb +58 -10
  10. data/lib/datashift/excel_base.rb +123 -0
  11. data/lib/datashift/exceptions.rb +45 -7
  12. data/lib/datashift/load_object.rb +25 -0
  13. data/lib/datashift/mapping_service.rb +91 -0
  14. data/lib/datashift/method_detail.rb +40 -62
  15. data/lib/datashift/method_details_manager.rb +18 -2
  16. data/lib/datashift/method_dictionary.rb +27 -10
  17. data/lib/datashift/method_mapper.rb +49 -41
  18. data/lib/datashift/model_mapper.rb +42 -22
  19. data/lib/datashift/populator.rb +258 -143
  20. data/lib/datashift/thor_base.rb +38 -0
  21. data/lib/exporters/csv_exporter.rb +57 -145
  22. data/lib/exporters/excel_exporter.rb +73 -60
  23. data/lib/generators/csv_generator.rb +65 -5
  24. data/lib/generators/generator_base.rb +69 -3
  25. data/lib/generators/mapping_generator.rb +112 -0
  26. data/lib/helpers/core_ext/csv_file.rb +33 -0
  27. data/lib/loaders/csv_loader.rb +41 -39
  28. data/lib/loaders/excel_loader.rb +130 -116
  29. data/lib/loaders/loader_base.rb +190 -146
  30. data/lib/loaders/paperclip/attachment_loader.rb +4 -4
  31. data/lib/loaders/paperclip/datashift_paperclip.rb +5 -3
  32. data/lib/loaders/paperclip/image_loading.rb +9 -7
  33. data/lib/loaders/reporter.rb +17 -8
  34. data/lib/thor/export.thor +12 -13
  35. data/lib/thor/generate.thor +1 -9
  36. data/lib/thor/import.thor +13 -24
  37. data/lib/thor/mapping.thor +65 -0
  38. data/spec/Gemfile +13 -11
  39. data/spec/Gemfile.lock +98 -93
  40. data/spec/csv_exporter_spec.rb +104 -99
  41. data/spec/csv_generator_spec.rb +159 -0
  42. data/spec/csv_loader_spec.rb +197 -16
  43. data/spec/datashift_spec.rb +9 -0
  44. data/spec/excel_exporter_spec.rb +149 -58
  45. data/spec/excel_generator_spec.rb +35 -44
  46. data/spec/excel_loader_spec.rb +196 -178
  47. data/spec/excel_spec.rb +8 -5
  48. data/spec/loader_base_spec.rb +47 -7
  49. data/spec/mapping_spec.rb +117 -0
  50. data/spec/method_dictionary_spec.rb +24 -11
  51. data/spec/method_mapper_spec.rb +5 -7
  52. data/spec/model_mapper_spec.rb +41 -0
  53. data/spec/paperclip_loader_spec.rb +3 -6
  54. data/spec/populator_spec.rb +48 -14
  55. data/spec/spec_helper.rb +85 -73
  56. data/spec/thor_spec.rb +40 -5
  57. metadata +93 -86
  58. data/lib/applications/excel_base.rb +0 -63
@@ -1,63 +0,0 @@
1
- # To change this template, choose Tools | Templates
2
- # and open the template in the editor.
3
-
4
- module ExcelBase
5
-
6
- def sanitize_sheet_name( name )
7
- name.gsub(/[\[\]:\*\/\\\?]/, '')
8
- end
9
-
10
- # Helpers for dealing with Active Record models and collections
11
-
12
- def ar_to_headers( records )
13
- return if( !records.first.is_a?(ActiveRecord::Base) || records.empty?)
14
-
15
- headers = records.first.class.columns.collect( &:name )
16
- set_headers( headers )
17
- end
18
-
19
-
20
- # Pass a set of AR records
21
- def ar_to_xls(records, options = {})
22
- return if( ! records.first.is_a?(ActiveRecord::Base) || records.empty?)
23
-
24
- row_index =
25
- if(options[:no_headers])
26
- 0
27
- else
28
- ar_to_headers( records )
29
- 1
30
- end
31
-
32
- records.each do |record|
33
- ar_to_xls_row(row_index, 0, record)
34
-
35
- row_index += 1
36
- end
37
- end
38
-
39
-
40
- # Save data from an AR record to the current row, based on the record's columns [c1,c2,c3]
41
- # Returns the number of the final column written to
42
- def ar_to_xls_row(row, start_column, record)
43
- return unless( record.is_a?(ActiveRecord::Base))
44
-
45
- column = start_column
46
- record.class.columns.each do |connection_column|
47
- ar_to_xls_cell(row, column, record, connection_column)
48
- column += 1
49
- end
50
- column
51
- end
52
-
53
- def ar_to_xls_cell(row, column, record, connection_column)
54
- begin
55
- datum = record.send(connection_column.name)
56
-
57
- self[row, column] = datum
58
- rescue => e
59
- puts "Failed to export #{datum} from #{connection_column.inspect} to column #{column}"
60
- puts e, e.backtrace
61
- end
62
- end
63
- end