Class: Ardb::Adapter::Base
- Inherits:
-
Object
- Object
- Ardb::Adapter::Base
show all
- Defined in:
- lib/ardb/adapter/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
8
9
10
11
12
13
14
15
|
# File 'lib/ardb/adapter/base.rb', line 8
def initialize
@config_settings = Ardb.config.db_settings
@database = Ardb.config.db.database
@schema_format = Ardb.config.schema_format
schema_path = Ardb.config.schema_path
@ruby_schema_path = "#{schema_path}.rb"
@sql_schema_path = "#{schema_path}.sql"
end
|
Instance Attribute Details
#config_settings ⇒ Object
Returns the value of attribute config_settings.
5
6
7
|
# File 'lib/ardb/adapter/base.rb', line 5
def config_settings
@config_settings
end
|
#database ⇒ Object
Returns the value of attribute database.
5
6
7
|
# File 'lib/ardb/adapter/base.rb', line 5
def database
@database
end
|
#ruby_schema_path ⇒ Object
Returns the value of attribute ruby_schema_path.
6
7
8
|
# File 'lib/ardb/adapter/base.rb', line 6
def ruby_schema_path
@ruby_schema_path
end
|
Returns the value of attribute schema_format.
6
7
8
|
# File 'lib/ardb/adapter/base.rb', line 6
def schema_format
@schema_format
end
|
#sql_schema_path ⇒ Object
Returns the value of attribute sql_schema_path.
6
7
8
|
# File 'lib/ardb/adapter/base.rb', line 6
def sql_schema_path
@sql_schema_path
end
|
Instance Method Details
#==(other_adapter) ⇒ Object
82
83
84
|
# File 'lib/ardb/adapter/base.rb', line 82
def ==(other_adapter)
self.class == other_adapter.class
end
|
#create_db(*args) ⇒ Object
20
|
# File 'lib/ardb/adapter/base.rb', line 20
def create_db(*args); raise NotImplementedError; end
|
#drop_db(*args) ⇒ Object
21
|
# File 'lib/ardb/adapter/base.rb', line 21
def drop_db(*args); raise NotImplementedError; end
|
#drop_tables(*args) ⇒ Object
42
|
# File 'lib/ardb/adapter/base.rb', line 42
def drop_tables(*args); raise NotImplementedError; end
|
#dump_ruby_schema ⇒ Object
70
71
72
73
74
75
76
|
# File 'lib/ardb/adapter/base.rb', line 70
def dump_ruby_schema
require 'active_record/schema_dumper'
FileUtils.mkdir_p File.dirname(@ruby_schema_path)
File.open(@ruby_schema_path, 'w:utf-8') do |file|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
end
end
|
#dump_schema ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'lib/ardb/adapter/base.rb', line 61
def dump_schema
current_stdout = $stdout.dup
$stdout = File.new('/dev/null', 'w')
dump_ruby_schema
dump_sql_schema if @schema_format == :sql
$stdout = current_stdout
end
|
#dump_sql_schema ⇒ Object
78
79
80
|
# File 'lib/ardb/adapter/base.rb', line 78
def dump_sql_schema
raise NotImplementedError
end
|
#foreign_key_add_sql(*args) ⇒ Object
17
|
# File 'lib/ardb/adapter/base.rb', line 17
def foreign_key_add_sql(*args); raise NotImplementedError; end
|
#foreign_key_drop_sql(*args) ⇒ Object
18
|
# File 'lib/ardb/adapter/base.rb', line 18
def foreign_key_drop_sql(*args); raise NotImplementedError; end
|
#load_ruby_schema ⇒ Object
53
54
55
|
# File 'lib/ardb/adapter/base.rb', line 53
def load_ruby_schema
load @ruby_schema_path
end
|
#load_schema ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/ardb/adapter/base.rb', line 44
def load_schema
current_stdout = $stdout.dup
$stdout = File.new('/dev/null', 'w')
load_ruby_schema if @schema_format == :ruby
load_sql_schema if @schema_format == :sql
$stdout = current_stdout
end
|
#load_sql_schema ⇒ Object
57
58
59
|
# File 'lib/ardb/adapter/base.rb', line 57
def load_sql_schema
raise NotImplementedError
end
|
#migrate_db ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ardb/adapter/base.rb', line 23
def migrate_db
verbose = ENV["MIGRATE_QUIET"].nil?
version = ENV["MIGRATE_VERSION"] ? ENV["MIGRATE_VERSION"].to_i : nil
migrations_path = Ardb.config.migrations_path
if defined?(ActiveRecord::Migration::CommandRecorder)
require 'ardb/migration_helpers'
ActiveRecord::Migration::CommandRecorder.class_eval do
include Ardb::MigrationHelpers::RecorderMixin
end
end
ActiveRecord::Migrator.migrations_path = migrations_path
ActiveRecord::Migration.verbose = verbose
ActiveRecord::Migrator.migrate(migrations_path, version) do |migration|
ENV["MIGRATE_SCOPE"].blank? || (ENV["MIGRATE_SCOPE"] == migration.scope)
end
end
|