ydd 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -1
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/ydd.rb +18 -17
- data/lib/ydd/schema_manager.rb +3 -3
- data/lib/ydd/serialization_helper.rb +22 -13
- data/ydd.gemspec +5 -2
- metadata +20 -6
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm --create use "@ydd"
|
1
|
+
rvm --create use "ree@ydd"
|
data/Rakefile
CHANGED
@@ -15,6 +15,7 @@ and the like.
|
|
15
15
|
gem.authors = ["Adam Wiggins","Orion Henry", "Darcy Laycock"]
|
16
16
|
gem.add_dependency 'thor', '~> 0.14'
|
17
17
|
gem.add_dependency 'activesupport'
|
18
|
+
gem.add_dependency 'rchardet'
|
18
19
|
# We want it to work with Rails 3 etc, older versions of AR will fail though.
|
19
20
|
gem.add_dependency 'activerecord', '>= 2.3'
|
20
21
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/ydd.rb
CHANGED
@@ -3,11 +3,12 @@ require 'active_support'
|
|
3
3
|
require 'active_support/all'
|
4
4
|
require 'active_record'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'iconv'
|
6
7
|
require 'rchardet'
|
7
8
|
|
8
9
|
module YDD
|
9
10
|
class Error < StandardError; end
|
10
|
-
|
11
|
+
|
11
12
|
autoload :SchemaManager, 'ydd/schema_manager'
|
12
13
|
autoload :DataManager, 'ydd/data_manager'
|
13
14
|
autoload :YamlDB, 'ydd/yaml_db'
|
@@ -15,15 +16,15 @@ module YDD
|
|
15
16
|
autoload :Application, 'ydd/application'
|
16
17
|
|
17
18
|
mattr_accessor :skip_schema, :skip_data
|
18
|
-
|
19
|
+
|
19
20
|
def self.skip_schema?
|
20
21
|
!!skip_schema
|
21
22
|
end
|
22
|
-
|
23
|
+
|
23
24
|
def self.schema_tables
|
24
25
|
[ 'schema_info', 'schema_migrations' ]
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
def self.skip_data?
|
28
29
|
!!skip_data
|
29
30
|
end
|
@@ -31,7 +32,7 @@ module YDD
|
|
31
32
|
def self.tables=(value)
|
32
33
|
@@tables = value.blank? ? nil : Array(value).join(",").split(",")
|
33
34
|
end
|
34
|
-
|
35
|
+
|
35
36
|
def self.tables
|
36
37
|
@@tables ||= nil
|
37
38
|
end
|
@@ -43,57 +44,57 @@ module YDD
|
|
43
44
|
@@env = value
|
44
45
|
end
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
def self.env
|
48
49
|
@@env ||= (ENV['YDD_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development')
|
49
50
|
end
|
50
|
-
|
51
|
+
|
51
52
|
def self.connection
|
52
53
|
ActiveRecord::Base.connection
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
def self.configuration_from(file)
|
56
57
|
require 'erb'
|
57
58
|
parsed = ERB.new(File.read(file)).result
|
58
59
|
YAML.load(parsed)[env]
|
59
60
|
end
|
60
|
-
|
61
|
+
|
61
62
|
def self.connect_from(path)
|
62
63
|
raise Error, "Invalid database config at #{path}" if !File.exists?(path)
|
63
64
|
connect configuration_from(path)
|
64
65
|
end
|
65
|
-
|
66
|
+
|
66
67
|
def self.connect(specification)
|
67
68
|
ActiveRecord::Base.establish_connection(specification)
|
68
69
|
end
|
69
|
-
|
70
|
+
|
70
71
|
def self.dump(directory)
|
71
72
|
FileUtils.mkdir_p directory
|
72
73
|
SchemaManager.dump File.join(directory, "schema.rb") unless skip_schema?
|
73
74
|
DataManager.dump File.join(directory, "data.yml") unless skip_data?
|
74
75
|
end
|
75
|
-
|
76
|
+
|
76
77
|
def self.load(directory)
|
77
78
|
if !File.directory?(directory)
|
78
79
|
raise Error, "Please provide a valid directory - #{directory} doesn't exist."
|
79
80
|
end
|
80
|
-
|
81
|
+
|
81
82
|
unless skip_schema?
|
82
83
|
check_files! directory, "schema.rb"
|
83
|
-
SchemaManager.load File.join(directory, "schema.rb")
|
84
|
+
SchemaManager.load File.join(directory, "schema.rb")
|
84
85
|
end
|
85
|
-
|
86
|
+
|
86
87
|
unless skip_data?
|
87
88
|
check_files! directory, "data.yml"
|
88
89
|
DataManager.load File.join(directory, "data.yml")
|
89
90
|
end
|
90
91
|
end
|
91
|
-
|
92
|
+
|
92
93
|
def self.check_files!(dir, *files)
|
93
94
|
files.each do |file|
|
94
95
|
path = File.join(dir, file)
|
95
96
|
raise Error, "#{file} doesn't exist in #{dir}" if !File.readable?(path)
|
96
97
|
end
|
97
98
|
end
|
98
|
-
|
99
|
+
|
99
100
|
end
|
data/lib/ydd/schema_manager.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module YDD
|
2
2
|
class SchemaManager
|
3
|
-
|
3
|
+
|
4
4
|
def self.dump(path)
|
5
5
|
File.open(path, "w") do |file|
|
6
6
|
ActiveRecord::SchemaDumper.dump(YDD.connection, file)
|
7
7
|
end
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
def self.load(path)
|
11
11
|
Kernel.load path if File.exists?(path)
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
end
|
15
15
|
end
|
@@ -31,19 +31,28 @@ module YDD
|
|
31
31
|
ActiveRecord::Base.logger = @@old_logger
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
|
+
class IdentityConvertor
|
36
|
+
def self.iconv(string)
|
37
|
+
string.to_s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
35
42
|
class Load
|
36
43
|
def self.convert_from(char_enc)
|
37
44
|
@converter ||= {}
|
38
|
-
|
45
|
+
|
39
46
|
return @converter[char_enc] if @converter[char_enc].present?
|
40
|
-
|
47
|
+
|
41
48
|
if YDD.connection.encoding.eql? "UTF8"
|
42
49
|
puts "Creating a string converter from #{char_enc} that will ignore non-UTF8 characters."
|
43
50
|
@converter[char_enc] = Iconv.new('UTF-8//TRANSLIT//IGNORE', char_enc)
|
44
51
|
end
|
52
|
+
|
53
|
+
@converter.fetch(char_enc, IdentityConvertor)
|
45
54
|
end
|
46
|
-
|
55
|
+
|
47
56
|
def self.load(io, truncate = true)
|
48
57
|
YDD.connection.transaction do
|
49
58
|
load_documents(io, truncate)
|
@@ -71,21 +80,21 @@ module YDD
|
|
71
80
|
quoted_column_names = column_names.map { |column| YDD.connection.quote_column_name(column) }.join(',')
|
72
81
|
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
73
82
|
#records.sort_by! { |r| r['id'].to_i } if column_names.include? 'id'
|
74
|
-
#
|
83
|
+
#
|
75
84
|
records.each do |record|
|
76
85
|
quoted_values = record.zip(columns).map { |value_column| clean_column_value(value_column) }.join(",")
|
77
|
-
|
86
|
+
|
78
87
|
YDD.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
|
79
88
|
end
|
80
|
-
|
89
|
+
|
81
90
|
end
|
82
91
|
|
83
92
|
def self.reset_pk_sequence!(table_name)
|
84
93
|
if YDD.connection.respond_to?(:reset_pk_sequence!)
|
85
94
|
YDD.connection.reset_pk_sequence!(table_name)
|
86
95
|
end
|
87
|
-
end
|
88
|
-
|
96
|
+
end
|
97
|
+
|
89
98
|
def self.clean_column_value(value_column)
|
90
99
|
value, column = value_column[0], value_column[1]
|
91
100
|
|
@@ -98,9 +107,9 @@ module YDD
|
|
98
107
|
value
|
99
108
|
end
|
100
109
|
end
|
101
|
-
|
110
|
+
|
102
111
|
YDD.connection.quote(value, column)
|
103
|
-
end
|
112
|
+
end
|
104
113
|
|
105
114
|
end
|
106
115
|
|
@@ -163,7 +172,7 @@ module YDD
|
|
163
172
|
base_tables = YDD.connection.tables
|
164
173
|
base_tables &= YDD.tables if YDD.tables.present?
|
165
174
|
base_tables.reject! { |table| YDD.schema_tables.include?(table) } if YDD.skip_schema?
|
166
|
-
base_tables
|
175
|
+
base_tables
|
167
176
|
end
|
168
177
|
|
169
178
|
def self.dump_table(io, table)
|
@@ -183,7 +192,7 @@ module YDD
|
|
183
192
|
pages = (total_count.to_f / records_per_page).ceil - 1
|
184
193
|
id = table_column_names(table).first
|
185
194
|
boolean_columns = SerializationHelper::Utils.boolean_columns(table)
|
186
|
-
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
195
|
+
quoted_table_name = SerializationHelper::Utils.quote_table(table)
|
187
196
|
base_query = "SELECT * FROM #{quoted_table_name} ORDER BY #{id}"
|
188
197
|
0.upto(pages) do |page|
|
189
198
|
sql = YDD.connection.add_limit_offset! base_query.dup,
|
data/ydd.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ydd}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.1"
|
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-05-
|
12
|
+
s.date = %q{2011-05-31}
|
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
|
@@ -47,15 +47,18 @@ and the like.
|
|
47
47
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
48
48
|
s.add_runtime_dependency(%q<thor>, ["~> 0.14"])
|
49
49
|
s.add_runtime_dependency(%q<activesupport>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<rchardet>, [">= 0"])
|
50
51
|
s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
|
51
52
|
else
|
52
53
|
s.add_dependency(%q<thor>, ["~> 0.14"])
|
53
54
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
55
|
+
s.add_dependency(%q<rchardet>, [">= 0"])
|
54
56
|
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
55
57
|
end
|
56
58
|
else
|
57
59
|
s.add_dependency(%q<thor>, ["~> 0.14"])
|
58
60
|
s.add_dependency(%q<activesupport>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rchardet>, [">= 0"])
|
59
62
|
s.add_dependency(%q<activerecord>, [">= 2.3"])
|
60
63
|
end
|
61
64
|
end
|
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:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
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-05-
|
20
|
+
date: 2011-05-31 00:00:00 +08:00
|
21
21
|
default_executable: ydd
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -50,9 +50,23 @@ dependencies:
|
|
50
50
|
type: :runtime
|
51
51
|
version_requirements: *id002
|
52
52
|
- !ruby/object:Gem::Dependency
|
53
|
-
name:
|
53
|
+
name: rchardet
|
54
54
|
prerelease: false
|
55
55
|
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: activerecord
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
56
70
|
none: false
|
57
71
|
requirements:
|
58
72
|
- - ">="
|
@@ -63,7 +77,7 @@ dependencies:
|
|
63
77
|
- 3
|
64
78
|
version: "2.3"
|
65
79
|
type: :runtime
|
66
|
-
version_requirements: *
|
80
|
+
version_requirements: *id004
|
67
81
|
description: |
|
68
82
|
|
69
83
|
YDD is a tool (a fork of yaml_db really) to make it generally easy
|