fruit_to_lime 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/bin/fruit_to_lime +24 -24
  2. data/lib/fruit_to_lime/address_helper.rb +17 -17
  3. data/lib/fruit_to_lime/csv_helper.rb +32 -32
  4. data/lib/fruit_to_lime/model/address.rb +37 -37
  5. data/lib/fruit_to_lime/model/coworker.rb +44 -44
  6. data/lib/fruit_to_lime/model/coworker_reference.rb +17 -17
  7. data/lib/fruit_to_lime/model/customfield.rb +30 -30
  8. data/lib/fruit_to_lime/model/note.rb +38 -38
  9. data/lib/fruit_to_lime/model/organization.rb +140 -140
  10. data/lib/fruit_to_lime/model/person.rb +115 -115
  11. data/lib/fruit_to_lime/model/referencetosource.rb +42 -42
  12. data/lib/fruit_to_lime/model/rootmodel.rb +142 -142
  13. data/lib/fruit_to_lime/model/tag.rb +33 -33
  14. data/lib/fruit_to_lime/model_helpers.rb +19 -19
  15. data/lib/fruit_to_lime/roo_helper.rb +59 -59
  16. data/lib/fruit_to_lime/serialize_helper.rb +139 -139
  17. data/lib/fruit_to_lime/templating.rb +51 -51
  18. data/lib/fruit_to_lime.rb +13 -13
  19. data/spec/helpers/address_helper_spec.rb +48 -48
  20. data/spec/helpers/csv_helper_spec.rb +15 -15
  21. data/spec/helpers/roo_helper_spec.rb +10 -10
  22. data/spec/helpers/serialize_helper_spec.rb +211 -211
  23. data/spec/person_spec.rb +44 -44
  24. data/spec/spec_helper.rb +24 -24
  25. data/templates/csv/Gemfile +5 -5
  26. data/templates/csv/Rakefile.rb +7 -7
  27. data/templates/csv/convert.rb +2 -2
  28. data/templates/csv/lib/tomodel.rb +56 -56
  29. data/templates/csv/spec/sample_data/organizations.csv +2 -2
  30. data/templates/csv/spec/spec_helper.rb +24 -24
  31. data/templates/csv/spec/tomodel_spec.rb +14 -14
  32. data/templates/excel/Gemfile +6 -6
  33. data/templates/excel/Rakefile.rb +7 -7
  34. data/templates/excel/convert.rb +2 -2
  35. data/templates/excel/lib/tomodel.rb +53 -53
  36. data/templates/excel/spec/spec_helper.rb +20 -20
  37. data/templates/excel/spec/tomodel_spec.rb +18 -18
  38. data/templates/sqlserver/Gemfile +6 -6
  39. data/templates/sqlserver/Rakefile.rb +7 -7
  40. data/templates/sqlserver/convert.rb +2 -2
  41. data/templates/sqlserver/lib/tomodel.rb +67 -67
  42. data/templates/sqlserver/spec/spec_helper.rb +20 -20
  43. data/templates/sqlserver/spec/tomodel_spec.rb +9 -9
  44. metadata +2 -2
@@ -1,59 +1,59 @@
1
- require "csv"
2
- module FruitToLime
3
- class RooHelper
4
- def initialize(data)
5
- @data = data
6
- @default_sheet = data.sheets.first
7
- end
8
-
9
- def rows
10
- return rows_for_sheet(@default_sheet)
11
- end
12
-
13
- def rows_for_sheet(sheet)
14
- column_headers = {}
15
- 1.upto(@data.last_column(sheet)) do |col|
16
- column_headers[col] = @data.cell(1, col, sheet).encode('UTF-8')
17
- end
18
-
19
- rs = []
20
- 2.upto(@data.last_row(sheet)) do |row|
21
- r = {}
22
- 1.upto(@data.last_column(sheet)) do |col|
23
- val = cell_to_csv(row, col, sheet)
24
- r[column_headers[col]] = val
25
- end
26
- rs.push(r)
27
- end
28
- return rs
29
- end
30
-
31
- def cell_to_csv(row, col, sheet)
32
- if @data.empty?(row,col,sheet)
33
- ''
34
- else
35
- onecell = @data.cell(row,col,sheet)
36
- case @data.celltype(row,col,sheet)
37
- when :string
38
- unless onecell.empty?
39
- onecell.encode('UTF-8').strip
40
- end
41
- when :float, :percentage
42
- if onecell == onecell.to_i
43
- onecell.to_i.to_s
44
- else
45
- onecell.to_s
46
- end
47
- when :date, :datetime
48
- onecell.to_s
49
- when :time
50
- Roo::Base.integer_to_timestring(onecell)
51
- when :formula
52
- onecell.to_s
53
- else
54
- raise "unhandled celltype #{@data.celltype(row,col,sheet)} for cell at row: #{row}, col: #{col} in sheet #{sheet}"
55
- end || ""
56
- end
57
- end
58
- end
59
- end
1
+ require "csv"
2
+ module FruitToLime
3
+ class RooHelper
4
+ def initialize(data)
5
+ @data = data
6
+ @default_sheet = data.sheets.first
7
+ end
8
+
9
+ def rows
10
+ return rows_for_sheet(@default_sheet)
11
+ end
12
+
13
+ def rows_for_sheet(sheet)
14
+ column_headers = {}
15
+ 1.upto(@data.last_column(sheet)) do |col|
16
+ column_headers[col] = @data.cell(1, col, sheet).encode('UTF-8')
17
+ end
18
+
19
+ rs = []
20
+ 2.upto(@data.last_row(sheet)) do |row|
21
+ r = {}
22
+ 1.upto(@data.last_column(sheet)) do |col|
23
+ val = cell_to_csv(row, col, sheet)
24
+ r[column_headers[col]] = val
25
+ end
26
+ rs.push(r)
27
+ end
28
+ return rs
29
+ end
30
+
31
+ def cell_to_csv(row, col, sheet)
32
+ if @data.empty?(row,col,sheet)
33
+ ''
34
+ else
35
+ onecell = @data.cell(row,col,sheet)
36
+ case @data.celltype(row,col,sheet)
37
+ when :string
38
+ unless onecell.empty?
39
+ onecell.encode('UTF-8').strip
40
+ end
41
+ when :float, :percentage
42
+ if onecell == onecell.to_i
43
+ onecell.to_i.to_s
44
+ else
45
+ onecell.to_s
46
+ end
47
+ when :date, :datetime
48
+ onecell.to_s
49
+ when :time
50
+ Roo::Base.integer_to_timestring(onecell)
51
+ when :formula
52
+ onecell.to_s
53
+ else
54
+ raise "unhandled celltype #{@data.celltype(row,col,sheet)} for cell at row: #{row}, col: #{col} in sheet #{sheet}"
55
+ end || ""
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,139 +1,139 @@
1
- # encoding: utf-8
2
- module FruitToLime
3
- module SerializeHelper
4
- def serialize()
5
- SerializeHelper::serialize(self)
6
- end
7
-
8
- def serialize_to_file(file)
9
- SerializeHelper::serialize_to_file(file, self)
10
- end
11
-
12
- def self.serialize_variables(obj)
13
- if (obj.respond_to?(:serialize_variables))
14
- return obj.serialize_variables.map do |ivar|
15
- varn = ivar[:id].to_s.gsub(/^\@/,'').split('_').map do |m|
16
- m.capitalize
17
- end.join('')
18
-
19
- varv = obj.instance_variable_get("@#{ivar[:id].to_s}")
20
- if (varv.respond_to?(:serialize_variables))
21
- varv = serialize_variables(varv)
22
- elsif (varv.is_a?(Array))
23
- varv = varv.map { |elem| SerializeHelper::serialize(elem) }.join("\n")
24
- elsif (varv == nil)
25
- varv = nil
26
- else
27
- varv = varv.to_s.encode('UTF-8').encode(:xml => :text)
28
- end
29
- if varv != nil then "<#{varn}>#{ varv }</#{varn}>" else "" end
30
- if varv != nil then "<#{varn}>#{ varv }</#{varn}>" end
31
- end.join("\n")
32
- end
33
- raise "!!#{obj.class}"
34
- end
35
-
36
- def self.serialize(obj)
37
- if (obj.respond_to?(:serialize_variables))
38
- varn = obj.serialize_name
39
- "<#{varn}>#{ SerializeHelper::serialize_variables(obj) }</#{varn}>"
40
- elsif obj.respond_to?(:to_xml)
41
- obj.to_xml
42
- else
43
- obj.to_s.encode(:xml => :text)
44
- end
45
- end
46
-
47
- def self.serialize_to_file(file, obj)
48
- File.open(file, 'w') do |f|
49
- f.write(SerializeHelper::serialize(obj))
50
- end
51
- end
52
-
53
- def symbol_to_name(symbol)
54
- symbol.to_s.split('_').join(' ').capitalize
55
- end
56
-
57
- def map_symbol_to_row(symbol,type)
58
- {
59
- :id => symbol.to_s,
60
- :name => symbol == :id ? 'Go id' : symbol_to_name(symbol),
61
- :type =>type
62
- }
63
- end
64
-
65
- def map_to_row(p)
66
- case p[:type]
67
- when :string then
68
- map_symbol_to_row(p[:id],p[:type])
69
- when :bool then
70
- map_symbol_to_row(p[:id],p[:type])
71
- when :date then
72
- map_symbol_to_row(p[:id],p[:type])
73
- when :notes then
74
- {
75
- :id => p[:id].to_s,
76
- :name => symbol_to_name(p[:id]),
77
- :type => p[:type],
78
- :models => SerializeHelper.get_import_rows(:note)
79
- }
80
- when :tags then
81
- {
82
- :id => p[:id].to_s,
83
- :type => p[:type],
84
- :name => symbol_to_name(p[:id]),
85
- }
86
- when :persons then
87
- {
88
- :id => p[:id].to_s,
89
- :type => p[:type],
90
- :name => symbol_to_name(p[:id]),
91
- :models => SerializeHelper.get_import_rows(:person)
92
- }
93
- when :custom_fields then
94
- {
95
- :id => p[:id].to_s,
96
- :type => p[:type],
97
- :name => symbol_to_name(p[:id]),
98
- :models => SerializeHelper.get_import_rows(:custom_field)
99
- }
100
- else
101
- {
102
- :id => p[:id].to_s,
103
- :name => symbol_to_name(p[:id]),
104
- :type => p[:type],
105
- :model => SerializeHelper.get_import_rows(p[:type])
106
- }
107
- end
108
- end
109
-
110
- def get_import_rows
111
- serialize_variables.map do |p|
112
- map_to_row p
113
- end
114
- end
115
-
116
- def self.get_import_rows(type)
117
- case type
118
- when :person then
119
- Person.new
120
- when :source_ref then
121
- ReferenceToSource.new
122
- when :note then
123
- Note.new
124
- when :address then
125
- Address.new
126
- when :organization then
127
- Organization.new
128
- when :coworker_reference then
129
- CoworkerReference.new
130
- when :organization_reference then
131
- OrganizationReference.new
132
- when :custom_field then
133
- CustomField.new
134
- else
135
- raise "Unknown type: #{type}"
136
- end.get_import_rows
137
- end
138
- end
139
- end
1
+ # encoding: utf-8
2
+ module FruitToLime
3
+ module SerializeHelper
4
+ def serialize()
5
+ SerializeHelper::serialize(self)
6
+ end
7
+
8
+ def serialize_to_file(file)
9
+ SerializeHelper::serialize_to_file(file, self)
10
+ end
11
+
12
+ def self.serialize_variables(obj)
13
+ if (obj.respond_to?(:serialize_variables))
14
+ return obj.serialize_variables.map do |ivar|
15
+ varn = ivar[:id].to_s.gsub(/^\@/,'').split('_').map do |m|
16
+ m.capitalize
17
+ end.join('')
18
+
19
+ varv = obj.instance_variable_get("@#{ivar[:id].to_s}")
20
+ if (varv.respond_to?(:serialize_variables))
21
+ varv = serialize_variables(varv)
22
+ elsif (varv.is_a?(Array))
23
+ varv = varv.map { |elem| SerializeHelper::serialize(elem) }.join("\n")
24
+ elsif (varv == nil)
25
+ varv = nil
26
+ else
27
+ varv = varv.to_s.encode('UTF-8').encode(:xml => :text)
28
+ end
29
+ if varv != nil then "<#{varn}>#{ varv }</#{varn}>" else "" end
30
+ if varv != nil then "<#{varn}>#{ varv }</#{varn}>" end
31
+ end.join("\n")
32
+ end
33
+ raise "!!#{obj.class}"
34
+ end
35
+
36
+ def self.serialize(obj)
37
+ if (obj.respond_to?(:serialize_variables))
38
+ varn = obj.serialize_name
39
+ "<#{varn}>#{ SerializeHelper::serialize_variables(obj) }</#{varn}>"
40
+ elsif obj.respond_to?(:to_xml)
41
+ obj.to_xml
42
+ else
43
+ obj.to_s.encode(:xml => :text)
44
+ end
45
+ end
46
+
47
+ def self.serialize_to_file(file, obj)
48
+ File.open(file, 'w') do |f|
49
+ f.write(SerializeHelper::serialize(obj))
50
+ end
51
+ end
52
+
53
+ def symbol_to_name(symbol)
54
+ symbol.to_s.split('_').join(' ').capitalize
55
+ end
56
+
57
+ def map_symbol_to_row(symbol,type)
58
+ {
59
+ :id => symbol.to_s,
60
+ :name => symbol == :id ? 'Go id' : symbol_to_name(symbol),
61
+ :type =>type
62
+ }
63
+ end
64
+
65
+ def map_to_row(p)
66
+ case p[:type]
67
+ when :string then
68
+ map_symbol_to_row(p[:id],p[:type])
69
+ when :bool then
70
+ map_symbol_to_row(p[:id],p[:type])
71
+ when :date then
72
+ map_symbol_to_row(p[:id],p[:type])
73
+ when :notes then
74
+ {
75
+ :id => p[:id].to_s,
76
+ :name => symbol_to_name(p[:id]),
77
+ :type => p[:type],
78
+ :models => SerializeHelper.get_import_rows(:note)
79
+ }
80
+ when :tags then
81
+ {
82
+ :id => p[:id].to_s,
83
+ :type => p[:type],
84
+ :name => symbol_to_name(p[:id]),
85
+ }
86
+ when :persons then
87
+ {
88
+ :id => p[:id].to_s,
89
+ :type => p[:type],
90
+ :name => symbol_to_name(p[:id]),
91
+ :models => SerializeHelper.get_import_rows(:person)
92
+ }
93
+ when :custom_fields then
94
+ {
95
+ :id => p[:id].to_s,
96
+ :type => p[:type],
97
+ :name => symbol_to_name(p[:id]),
98
+ :models => SerializeHelper.get_import_rows(:custom_field)
99
+ }
100
+ else
101
+ {
102
+ :id => p[:id].to_s,
103
+ :name => symbol_to_name(p[:id]),
104
+ :type => p[:type],
105
+ :model => SerializeHelper.get_import_rows(p[:type])
106
+ }
107
+ end
108
+ end
109
+
110
+ def get_import_rows
111
+ serialize_variables.map do |p|
112
+ map_to_row p
113
+ end
114
+ end
115
+
116
+ def self.get_import_rows(type)
117
+ case type
118
+ when :person then
119
+ Person.new
120
+ when :source_ref then
121
+ ReferenceToSource.new
122
+ when :note then
123
+ Note.new
124
+ when :address then
125
+ Address.new
126
+ when :organization then
127
+ Organization.new
128
+ when :coworker_reference then
129
+ CoworkerReference.new
130
+ when :organization_reference then
131
+ OrganizationReference.new
132
+ when :custom_field then
133
+ CustomField.new
134
+ else
135
+ raise "Unknown type: #{type}"
136
+ end.get_import_rows
137
+ end
138
+ end
139
+ end
@@ -1,51 +1,51 @@
1
- require "fileutils"
2
- require 'open3'
3
- module FruitToLime
4
- class Templating
5
- def initialize(path)
6
- @path = path
7
- end
8
-
9
- def list()
10
- Dir.entries(@path).select { |d| d != '.' && d != '..' }
11
- end
12
-
13
- def exec_but_dont_show_unless_error(cmd)
14
- std_out_value = []
15
- Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
16
- while std_line = stdout.gets
17
- std_out_value << std_line
18
- end
19
-
20
- exit_status = wait_thr.value
21
- if !exit_status.success?
22
- puts "Failed with #{exit_status}"
23
- puts "std_out_value"
24
- puts std_out_value
25
-
26
- raise "failed exec #{cmd}"
27
- end
28
- end
29
- end
30
-
31
- def unpack(name, path)
32
- template = list.find { |t| t == name }
33
- if template
34
- unpackedname = name
35
-
36
- puts "Unpacking template #{name} to #{path}"
37
- FileUtils.cp_r File.expand_path(name, @path), path
38
-
39
- # Now make sure all gems in template are installed
40
- puts "Making sure all needed gems are present"
41
- Dir.chdir(File.expand_path(unpackedname, path)) do
42
- exec_but_dont_show_unless_error('bundle install --verbose')
43
- end
44
- true
45
- else
46
- puts "Unable to find template #{name}"
47
- false
48
- end
49
- end
50
- end
51
- end
1
+ require "fileutils"
2
+ require 'open3'
3
+ module FruitToLime
4
+ class Templating
5
+ def initialize(path)
6
+ @path = path
7
+ end
8
+
9
+ def list()
10
+ Dir.entries(@path).select { |d| d != '.' && d != '..' }
11
+ end
12
+
13
+ def exec_but_dont_show_unless_error(cmd)
14
+ std_out_value = []
15
+ Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
16
+ while std_line = stdout.gets
17
+ std_out_value << std_line
18
+ end
19
+
20
+ exit_status = wait_thr.value
21
+ if !exit_status.success?
22
+ puts "Failed with #{exit_status}"
23
+ puts "std_out_value"
24
+ puts std_out_value
25
+
26
+ raise "failed exec #{cmd}"
27
+ end
28
+ end
29
+ end
30
+
31
+ def unpack(name, path)
32
+ template = list.find { |t| t == name }
33
+ if template
34
+ unpackedname = name
35
+
36
+ puts "Unpacking template #{name} to #{path}"
37
+ FileUtils.cp_r File.expand_path(name, @path), path
38
+
39
+ # Now make sure all gems in template are installed
40
+ puts "Making sure all needed gems are present"
41
+ Dir.chdir(File.expand_path(unpackedname, path)) do
42
+ exec_but_dont_show_unless_error('bundle install --verbose')
43
+ end
44
+ true
45
+ else
46
+ puts "Unable to find template #{name}"
47
+ false
48
+ end
49
+ end
50
+ end
51
+ end