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
63
64
65
|
# File 'lib/ardb/adapter/base.rb', line 63
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
23
|
# File 'lib/ardb/adapter/base.rb', line 23
def drop_tables(*args); raise NotImplementedError; end
|
#dump_ruby_schema ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/ardb/adapter/base.rb', line 51
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
42
43
44
45
46
47
48
49
|
# File 'lib/ardb/adapter/base.rb', line 42
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
59
60
61
|
# File 'lib/ardb/adapter/base.rb', line 59
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
34
35
36
|
# File 'lib/ardb/adapter/base.rb', line 34
def load_ruby_schema
load @ruby_schema_path
end
|
#load_schema ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/ardb/adapter/base.rb', line 25
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
38
39
40
|
# File 'lib/ardb/adapter/base.rb', line 38
def load_sql_schema
raise NotImplementedError
end
|