yaml_db 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +1 -1
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/lib/serialization_helper.rb +6 -2
- data/lib/tasks/yaml_db_tasks.rake +37 -37
- data/lib/yaml_db.rb +1 -0
- data/spec/base.rb +1 -6
- data/spec/serialization_helper_base_spec.rb +7 -4
- data/spec/serialization_helper_dump_spec.rb +2 -2
- data/spec/serialization_helper_load_spec.rb +1 -1
- data/spec/serialization_utils_spec.rb +21 -1
- data/spec/yaml_dump_spec.rb +2 -2
- data/spec/yaml_load_spec.rb +1 -1
- data/yaml_db.gemspec +27 -28
- metadata +9 -14
data/README.markdown
CHANGED
@@ -4,7 +4,7 @@ YamlDb is a database-independent format for dumping and restoring data. It comp
|
|
4
4
|
|
5
5
|
This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
|
6
6
|
|
7
|
-
Any database that has an ActiveRecord adapter should work.
|
7
|
+
Any database that has an ActiveRecord adapter should work. This gem is now Rails 3 only. For Rails 2, clone and checkout the Rails2 branch.
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
data/Rakefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require
|
2
|
+
require "rspec/core/rake_task"
|
3
3
|
|
4
4
|
begin
|
5
5
|
require 'jeweler'
|
@@ -20,10 +20,10 @@ rescue LoadError
|
|
20
20
|
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
spec.
|
26
|
-
spec.
|
23
|
+
|
24
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
25
|
+
spec.pattern = 'spec/*_spec.rb'
|
26
|
+
spec.rspec_opts = ['--backtrace']
|
27
27
|
end
|
28
28
|
|
29
29
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.1
|
data/lib/serialization_helper.rb
CHANGED
@@ -115,12 +115,16 @@ module SerializationHelper
|
|
115
115
|
records.each do |record|
|
116
116
|
columns.each do |column|
|
117
117
|
next if is_boolean(record[column])
|
118
|
-
record[column] = (record[column]
|
118
|
+
record[column] = convert_boolean(record[column])
|
119
119
|
end
|
120
120
|
end
|
121
121
|
records
|
122
122
|
end
|
123
123
|
|
124
|
+
def self.convert_boolean(value)
|
125
|
+
['t', '1', true, 1].include?(value)
|
126
|
+
end
|
127
|
+
|
124
128
|
def self.boolean_columns(table)
|
125
129
|
columns = ActiveRecord::Base.connection.columns(table).reject { |c| silence_warnings { c.type != :boolean } }
|
126
130
|
columns.map { |c| c.name }
|
@@ -192,4 +196,4 @@ module SerializationHelper
|
|
192
196
|
|
193
197
|
end
|
194
198
|
|
195
|
-
end
|
199
|
+
end
|
@@ -1,45 +1,45 @@
|
|
1
1
|
namespace :db do
|
2
|
-
|
3
|
-
|
2
|
+
desc "Dump schema and data to db/schema.rb and db/data.yml"
|
3
|
+
task(:dump => [ "db:schema:dump", "db:data:dump" ])
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
desc "Load schema and data from db/schema.rb and db/data.yml"
|
6
|
+
task(:load => [ "db:schema:load", "db:data:load" ])
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def dump_dir(dir = "")
|
14
|
-
"#{RAILS_ROOT}/db#{dir}"
|
15
|
-
end
|
8
|
+
namespace :data do
|
9
|
+
def db_dump_data_file (extension = "yml")
|
10
|
+
"#{dump_dir}/data.#{extension}"
|
11
|
+
end
|
16
12
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
helper = format_class.constantize
|
21
|
-
SerializationHelper::Base.new(helper).dump db_dump_data_file helper.extension
|
22
|
-
end
|
13
|
+
def dump_dir(dir = "")
|
14
|
+
"#{Rails.root}/db#{dir}"
|
15
|
+
end
|
23
16
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
desc "Dump contents of database to db/data.extension (defaults to yaml)"
|
18
|
+
task :dump => :environment do
|
19
|
+
format_class = ENV['class'] || "YamlDb::Helper"
|
20
|
+
helper = format_class.constantize
|
21
|
+
SerializationHelper::Base.new(helper).dump db_dump_data_file helper.extension
|
22
|
+
end
|
30
23
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
24
|
+
desc "Dump contents of database to curr_dir_name/tablename.extension (defaults to yaml)"
|
25
|
+
task :dump_dir => :environment do
|
26
|
+
format_class = ENV['class'] || "YamlDb::Helper"
|
27
|
+
dir = ENV['dir'] || "#{Time.now.to_s.gsub(/ /, '_')}"
|
28
|
+
SerializationHelper::Base.new(format_class.constantize).dump_to_dir dump_dir("/#{dir}")
|
29
|
+
end
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
desc "Load contents of db/data.extension (defaults to yaml) into database"
|
32
|
+
task :load => :environment do
|
33
|
+
format_class = ENV['class'] || "YamlDb::Helper"
|
34
|
+
helper = format_class.constantize
|
35
|
+
SerializationHelper::Base.new(helper).load (db_dump_data_file helper.extension)
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Load contents of db/data_dir into database"
|
39
|
+
task :load_dir => :environment do
|
40
|
+
dir = ENV['dir'] || "base"
|
41
|
+
format_class = ENV['class'] || "YamlDb::Helper"
|
42
|
+
SerializationHelper::Base.new(format_class.constantize).load_from_dir dump_dir("/#{dir}")
|
43
|
+
end
|
44
|
+
end
|
45
45
|
end
|
data/lib/yaml_db.rb
CHANGED
data/spec/base.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/base'
|
2
2
|
|
3
3
|
describe SerializationHelper::Base do
|
4
|
+
def prestub_active_record
|
5
|
+
|
6
|
+
end
|
4
7
|
|
5
8
|
before do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
@io = StringIO.new
|
10
|
+
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
11
|
+
ActiveRecord::Base.stub(:connection).and_return(mock('connection'))
|
9
12
|
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
|
10
|
-
|
13
|
+
end
|
11
14
|
|
12
15
|
def stub_helper!
|
13
16
|
@helper = mock("MyHelper")
|
@@ -4,9 +4,9 @@ describe SerializationHelper::Dump do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
7
|
-
ActiveRecord::Base.connection
|
7
|
+
ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
|
8
8
|
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
|
9
|
-
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a'
|
9
|
+
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a', :name => 'a', :type => :string), mock('b', :name => 'b', :type => :string) ])
|
10
10
|
ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
|
11
11
|
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
|
12
12
|
SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
|
@@ -5,7 +5,7 @@ describe SerializationHelper::Load do
|
|
5
5
|
SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
|
6
6
|
|
7
7
|
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
8
|
-
ActiveRecord::Base.connection
|
8
|
+
ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
|
9
9
|
ActiveRecord::Base.connection.stub!(:transaction).and_yield
|
10
10
|
@io = StringIO.new
|
11
11
|
end
|
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/base'
|
|
3
3
|
describe SerializationHelper::Utils, " convert records utility method" do
|
4
4
|
before do
|
5
5
|
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
6
|
-
ActiveRecord::Base.connection
|
6
|
+
ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "returns an array of hash values using an array of ordered keys" do
|
@@ -28,4 +28,24 @@ describe SerializationHelper::Utils, " convert records utility method" do
|
|
28
28
|
ActiveRecord::Base.connection.should_receive(:quote_table_name).with('values').and_return('`values`')
|
29
29
|
SerializationHelper::Utils.quote_table('values').should == '`values`'
|
30
30
|
end
|
31
|
+
|
32
|
+
it "should convert ruby booleans to true and false" do
|
33
|
+
SerializationHelper::Utils.convert_boolean(true).should == true
|
34
|
+
SerializationHelper::Utils.convert_boolean(false).should == false
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should convert ruby string t and f to true and false" do
|
38
|
+
SerializationHelper::Utils.convert_boolean('t').should == true
|
39
|
+
SerializationHelper::Utils.convert_boolean('f').should == false
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should convert ruby string 1 and 0 to true and false" do
|
43
|
+
SerializationHelper::Utils.convert_boolean('1').should == true
|
44
|
+
SerializationHelper::Utils.convert_boolean('0').should == false
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should convert ruby integer 1 and 0 to true and false" do
|
48
|
+
SerializationHelper::Utils.convert_boolean(1).should == true
|
49
|
+
SerializationHelper::Utils.convert_boolean(0).should == false
|
50
|
+
end
|
31
51
|
end
|
data/spec/yaml_dump_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe YamlDb::Dump do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
7
|
-
ActiveRecord::Base.connection
|
7
|
+
ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
|
8
8
|
ActiveRecord::Base.connection.stub!(:tables).and_return([ 'mytable', 'schema_info', 'schema_migrations' ])
|
9
|
-
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a'), mock('b', :name => 'b') ])
|
9
|
+
ActiveRecord::Base.connection.stub!(:columns).with('mytable').and_return([ mock('a',:name => 'a', :type => :string), mock('b', :name => 'b', :type => :string) ])
|
10
10
|
ActiveRecord::Base.connection.stub!(:select_one).and_return({"count"=>"2"})
|
11
11
|
ActiveRecord::Base.connection.stub!(:select_all).and_return([ { 'a' => 1, 'b' => 2 }, { 'a' => 3, 'b' => 4 } ])
|
12
12
|
YamlDb::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
|
data/spec/yaml_load_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe YamlDb::Load do
|
|
6
6
|
SerializationHelper::Utils.stub!(:quote_table).with('mytable').and_return('mytable')
|
7
7
|
|
8
8
|
silence_warnings { ActiveRecord::Base = mock('ActiveRecord::Base', :null_object => true) }
|
9
|
-
ActiveRecord::Base.connection
|
9
|
+
ActiveRecord::Base.stub(:connection).and_return(stub('connection').as_null_object)
|
10
10
|
ActiveRecord::Base.connection.stub!(:transaction).and_yield
|
11
11
|
end
|
12
12
|
|
data/yaml_db.gemspec
CHANGED
@@ -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
|
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{yaml_db}
|
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"]
|
12
|
-
s.date = %q{
|
12
|
+
s.date = %q{2011-04-19}
|
13
13
|
s.description = %q{
|
14
14
|
YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.
|
15
15
|
This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.
|
@@ -21,38 +21,37 @@ Any database that has an ActiveRecord adapter should work
|
|
21
21
|
]
|
22
22
|
s.files = [
|
23
23
|
"README.markdown",
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"about.yml",
|
27
|
+
"init.rb",
|
28
|
+
"lib/csv_db.rb",
|
29
|
+
"lib/serialization_helper.rb",
|
30
|
+
"lib/tasks/yaml_db_tasks.rake",
|
31
|
+
"lib/yaml_db.rb",
|
32
|
+
"spec/base.rb",
|
33
|
+
"spec/serialization_helper_base_spec.rb",
|
34
|
+
"spec/serialization_helper_dump_spec.rb",
|
35
|
+
"spec/serialization_helper_load_spec.rb",
|
36
|
+
"spec/serialization_utils_spec.rb",
|
37
|
+
"spec/yaml_dump_spec.rb",
|
38
|
+
"spec/yaml_load_spec.rb",
|
39
|
+
"spec/yaml_utils_spec.rb",
|
40
|
+
"yaml_db.gemspec"
|
41
41
|
]
|
42
42
|
s.homepage = %q{http://github.com/ludicast/yaml_db}
|
43
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
44
43
|
s.require_paths = ["lib"]
|
45
44
|
s.rubygems_version = %q{1.3.7}
|
46
45
|
s.summary = %q{yaml_db allows export/import of database into/from yaml files}
|
47
46
|
s.test_files = [
|
48
47
|
"spec/base.rb",
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
"spec/serialization_helper_base_spec.rb",
|
49
|
+
"spec/serialization_helper_dump_spec.rb",
|
50
|
+
"spec/serialization_helper_load_spec.rb",
|
51
|
+
"spec/serialization_utils_spec.rb",
|
52
|
+
"spec/yaml_dump_spec.rb",
|
53
|
+
"spec/yaml_load_spec.rb",
|
54
|
+
"spec/yaml_utils_spec.rb"
|
56
55
|
]
|
57
56
|
|
58
57
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaml_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 23
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
8
|
+
- 1
|
9
|
+
version: 0.2.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Adam Wiggins
|
@@ -16,16 +15,14 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date:
|
18
|
+
date: 2011-04-19 00:00:00 -04:00
|
20
19
|
default_executable:
|
21
20
|
dependencies: []
|
22
21
|
|
23
|
-
description:
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Any database that has an ActiveRecord adapter should work
|
28
|
-
|
22
|
+
description: "\n\
|
23
|
+
YamlDb is a database-independent format for dumping and restoring data. It complements the the database-independent schema format found in db/schema.rb. The data is saved into db/data.yml.\n\
|
24
|
+
This can be used as a replacement for mysqldump or pg_dump, but only for the databases typically used by Rails apps. Users, permissions, schemas, triggers, and other advanced database features are not supported - by design.\n\
|
25
|
+
Any database that has an ActiveRecord adapter should work\n"
|
29
26
|
email: nate@ludicast.com
|
30
27
|
executables: []
|
31
28
|
|
@@ -57,8 +54,8 @@ homepage: http://github.com/ludicast/yaml_db
|
|
57
54
|
licenses: []
|
58
55
|
|
59
56
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
57
|
+
rdoc_options: []
|
58
|
+
|
62
59
|
require_paths:
|
63
60
|
- lib
|
64
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -66,7 +63,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
63
|
requirements:
|
67
64
|
- - ">="
|
68
65
|
- !ruby/object:Gem::Version
|
69
|
-
hash: 3
|
70
66
|
segments:
|
71
67
|
- 0
|
72
68
|
version: "0"
|
@@ -75,7 +71,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
71
|
requirements:
|
76
72
|
- - ">="
|
77
73
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 3
|
79
74
|
segments:
|
80
75
|
- 0
|
81
76
|
version: "0"
|