datashift 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.markdown +91 -55
- data/VERSION +1 -1
- data/datashift.gemspec +8 -23
- data/lib/applications/jexcel_file.rb +1 -2
- data/lib/datashift.rb +34 -15
- data/lib/datashift/column_packer.rb +98 -34
- data/lib/datashift/data_transforms.rb +83 -0
- data/lib/datashift/delimiters.rb +58 -10
- data/lib/datashift/excel_base.rb +123 -0
- data/lib/datashift/exceptions.rb +45 -7
- data/lib/datashift/load_object.rb +25 -0
- data/lib/datashift/mapping_service.rb +91 -0
- data/lib/datashift/method_detail.rb +40 -62
- data/lib/datashift/method_details_manager.rb +18 -2
- data/lib/datashift/method_dictionary.rb +27 -10
- data/lib/datashift/method_mapper.rb +49 -41
- data/lib/datashift/model_mapper.rb +42 -22
- data/lib/datashift/populator.rb +258 -143
- data/lib/datashift/thor_base.rb +38 -0
- data/lib/exporters/csv_exporter.rb +57 -145
- data/lib/exporters/excel_exporter.rb +73 -60
- data/lib/generators/csv_generator.rb +65 -5
- data/lib/generators/generator_base.rb +69 -3
- data/lib/generators/mapping_generator.rb +112 -0
- data/lib/helpers/core_ext/csv_file.rb +33 -0
- data/lib/loaders/csv_loader.rb +41 -39
- data/lib/loaders/excel_loader.rb +130 -116
- data/lib/loaders/loader_base.rb +190 -146
- data/lib/loaders/paperclip/attachment_loader.rb +4 -4
- data/lib/loaders/paperclip/datashift_paperclip.rb +5 -3
- data/lib/loaders/paperclip/image_loading.rb +9 -7
- data/lib/loaders/reporter.rb +17 -8
- data/lib/thor/export.thor +12 -13
- data/lib/thor/generate.thor +1 -9
- data/lib/thor/import.thor +13 -24
- data/lib/thor/mapping.thor +65 -0
- data/spec/Gemfile +13 -11
- data/spec/Gemfile.lock +98 -93
- data/spec/csv_exporter_spec.rb +104 -99
- data/spec/csv_generator_spec.rb +159 -0
- data/spec/csv_loader_spec.rb +197 -16
- data/spec/datashift_spec.rb +9 -0
- data/spec/excel_exporter_spec.rb +149 -58
- data/spec/excel_generator_spec.rb +35 -44
- data/spec/excel_loader_spec.rb +196 -178
- data/spec/excel_spec.rb +8 -5
- data/spec/loader_base_spec.rb +47 -7
- data/spec/mapping_spec.rb +117 -0
- data/spec/method_dictionary_spec.rb +24 -11
- data/spec/method_mapper_spec.rb +5 -7
- data/spec/model_mapper_spec.rb +41 -0
- data/spec/paperclip_loader_spec.rb +3 -6
- data/spec/populator_spec.rb +48 -14
- data/spec/spec_helper.rb +85 -73
- data/spec/thor_spec.rb +40 -5
- metadata +93 -86
- 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
|