ydd 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/ydd.rb CHANGED
@@ -3,6 +3,7 @@ require 'active_support'
3
3
  require 'active_support/all'
4
4
  require 'active_record'
5
5
  require 'fileutils'
6
+ require 'rchardet'
6
7
 
7
8
  module YDD
8
9
  class Error < StandardError; end
@@ -33,6 +33,17 @@ module YDD
33
33
  end
34
34
 
35
35
  class Load
36
+ def self.convert_from(char_enc)
37
+ @converter ||= {}
38
+
39
+ return @converter[char_enc] if @converter[char_enc].present?
40
+
41
+ if YDD.connection.encoding.eql? "UTF8"
42
+ puts "Creating a string converter from #{char_enc} that will ignore non-UTF8 characters."
43
+ @converter[char_enc] = Iconv.new('UTF-8//TRANSLIT//IGNORE', char_enc)
44
+ end
45
+ end
46
+
36
47
  def self.load(io, truncate = true)
37
48
  YDD.connection.transaction do
38
49
  load_documents(io, truncate)
@@ -60,17 +71,36 @@ module YDD
60
71
  quoted_column_names = column_names.map { |column| YDD.connection.quote_column_name(column) }.join(',')
61
72
  quoted_table_name = SerializationHelper::Utils.quote_table(table)
62
73
  #records.sort_by! { |r| r['id'].to_i } if column_names.include? 'id'
74
+ #
63
75
  records.each do |record|
64
- quoted_values = record.zip(columns).map{|c| YDD.connection.quote(c.first, c.last)}.join(',')
76
+ quoted_values = record.zip(columns).map { |value_column| clean_column_value(value_column) }.join(",")
77
+
65
78
  YDD.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
66
79
  end
80
+
67
81
  end
68
82
 
69
83
  def self.reset_pk_sequence!(table_name)
70
84
  if YDD.connection.respond_to?(:reset_pk_sequence!)
71
85
  YDD.connection.reset_pk_sequence!(table_name)
72
86
  end
73
- end
87
+ end
88
+
89
+ def self.clean_column_value(value_column)
90
+ value, column = value_column[0], value_column[1]
91
+
92
+ if value.present?
93
+ value = case column.type
94
+ when :string, :text
95
+ character_encoding = CharDet.detect(value)["encoding"]
96
+ convert_from(character_encoding).iconv(value + ' ')[0..-2]
97
+ else
98
+ value
99
+ end
100
+ end
101
+
102
+ YDD.connection.quote(value, column)
103
+ end
74
104
 
75
105
  end
76
106
 
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ydd}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Wiggins", "Orion Henry", "Darcy Laycock"]
12
- s.date = %q{2011-01-16}
12
+ s.date = %q{2011-05-25}
13
13
  s.default_executable = %q{ydd}
14
14
  s.description = %q{
15
15
  YDD is a tool (a fork of yaml_db really) to make it generally easy
@@ -23,27 +23,25 @@ and the like.
23
23
  ]
24
24
  s.files = [
25
25
  ".rvmrc",
26
- "README.markdown",
27
- "Rakefile",
28
- "VERSION",
29
- "bin/ydd",
30
- "lib/ydd.rb",
31
- "lib/ydd/application.rb",
32
- "lib/ydd/data_manager.rb",
33
- "lib/ydd/schema_manager.rb",
34
- "lib/ydd/serialization_helper.rb",
35
- "lib/ydd/yaml_db.rb",
36
- "tasks/yaml_db_tasks.rake",
37
- "ydd.gemspec"
26
+ "README.markdown",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/ydd",
30
+ "lib/ydd.rb",
31
+ "lib/ydd/application.rb",
32
+ "lib/ydd/data_manager.rb",
33
+ "lib/ydd/schema_manager.rb",
34
+ "lib/ydd/serialization_helper.rb",
35
+ "lib/ydd/yaml_db.rb",
36
+ "tasks/yaml_db_tasks.rake",
37
+ "ydd.gemspec"
38
38
  ]
39
39
  s.homepage = %q{http://github.com/YouthTree/ydd}
40
- s.rdoc_options = ["--charset=UTF-8"]
41
40
  s.require_paths = ["lib"]
42
- s.rubygems_version = %q{1.3.7}
41
+ s.rubygems_version = %q{1.6.2}
43
42
  s.summary = %q{ydd dumps / loads rails app databases for backup purposes.}
44
43
 
45
44
  if s.respond_to? :specification_version then
46
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
45
  s.specification_version = 3
48
46
 
49
47
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ydd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Wiggins
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-01-16 00:00:00 +08:00
20
+ date: 2011-05-25 00:00:00 +08:00
21
21
  default_executable: ydd
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -96,8 +96,8 @@ homepage: http://github.com/YouthTree/ydd
96
96
  licenses: []
97
97
 
98
98
  post_install_message:
99
- rdoc_options:
100
- - --charset=UTF-8
99
+ rdoc_options: []
100
+
101
101
  require_paths:
102
102
  - lib
103
103
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements: []
122
122
 
123
123
  rubyforge_project:
124
- rubygems_version: 1.3.7
124
+ rubygems_version: 1.6.2
125
125
  signing_key:
126
126
  specification_version: 3
127
127
  summary: ydd dumps / loads rails app databases for backup purposes.