Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 390
- Log:
Initial import of Canvass, a donations-based poll application.
- Author:
- rool
- Date:
- Mon Mar 21 14:58:04 +0000 2011
- Size:
- 1712 Bytes
1 | #require 'FasterCSV' |
2 | module CsvDb |
3 | module Helper |
4 | def self.loader |
5 | Load |
6 | end |
7 | |
8 | def self.dumper |
9 | Dump |
10 | end |
11 | |
12 | def self.extension |
13 | "csv" |
14 | end |
15 | end |
16 | |
17 | class Load < SerializationHelper::Load |
18 | def self.load_documents(io, truncate = true) |
19 | tables = {} |
20 | curr_table = nil |
21 | io.each do |line| |
22 | if /BEGIN_CSV_TABLE_DECLARATION(.+)END_CSV_TABLE_DECLARATION/ =~ line |
23 | curr_table = $1 |
24 | tables[curr_table] = {} |
25 | else |
26 | if tables[curr_table]["columns"] |
27 | tables[curr_table]["records"] << FasterCSV.parse(line)[0] |
28 | else |
29 | tables[curr_table]["columns"] = FasterCSV.parse(line)[0] |
30 | tables[curr_table]["records"] = [] |
31 | end |
32 | end |
33 | end |
34 | |
35 | tables.each_pair do |table_name, contents| |
36 | load_table(table_name, contents, truncate) |
37 | end |
38 | end |
39 | end |
40 | |
41 | class Dump < SerializationHelper::Dump |
42 | |
43 | def self.before_table(io,table) |
44 | io.write "BEGIN_CSV_TABLE_DECLARATION#{table}END_CSV_TABLE_DECLARATION\n" |
45 | end |
46 | |
47 | def self.dump(io) |
48 | tables.each do |table| |
49 | before_table(io, table) |
50 | dump_table(io, table) |
51 | after_table(io, table) |
52 | end |
53 | end |
54 | |
55 | def self.after_table(io,table) |
56 | io.write "" |
57 | end |
58 | |
59 | def self.dump_table_columns(io, table) |
60 | io.write(table_column_names(table).to_csv) |
61 | end |
62 | |
63 | def self.dump_table_records(io, table) |
64 | |
65 | column_names = table_column_names(table) |
66 | |
67 | each_table_page(table) do |records| |
68 | rows = SerializationHelper::Utils.unhash_records(records, column_names) |
69 | records.each do |record| |
70 | io.write(record.to_csv) |
71 | end |
72 | end |
73 | end |
74 | |
75 | end |
76 | |
77 | |
78 | end |