Class: Ardb::Adapter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/adapter/base.rb

Direct Known Subclasses

Mysql, Postgresql, Sqlite

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

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_settingsObject (readonly)

Returns the value of attribute config_settings.



5
6
7
# File 'lib/ardb/adapter/base.rb', line 5

def config_settings
  @config_settings
end

#databaseObject (readonly)

Returns the value of attribute database.



5
6
7
# File 'lib/ardb/adapter/base.rb', line 5

def database
  @database
end

#ruby_schema_pathObject (readonly)

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

#schema_formatObject (readonly)

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_pathObject (readonly)

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

Raises:

  • (NotImplementedError)


20
# File 'lib/ardb/adapter/base.rb', line 20

def create_db(*args); raise NotImplementedError; end

#drop_db(*args) ⇒ Object

Raises:

  • (NotImplementedError)


21
# File 'lib/ardb/adapter/base.rb', line 21

def drop_db(*args);   raise NotImplementedError; end

#drop_tables(*args) ⇒ Object

Raises:

  • (NotImplementedError)


23
# File 'lib/ardb/adapter/base.rb', line 23

def drop_tables(*args); raise NotImplementedError; end

#dump_ruby_schemaObject



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_schemaObject



42
43
44
45
46
47
48
49
# File 'lib/ardb/adapter/base.rb', line 42

def dump_schema
  # silence STDOUT
  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_schemaObject

Raises:

  • (NotImplementedError)


59
60
61
# File 'lib/ardb/adapter/base.rb', line 59

def dump_sql_schema
  raise NotImplementedError
end

#foreign_key_add_sql(*args) ⇒ Object

Raises:

  • (NotImplementedError)


17
# File 'lib/ardb/adapter/base.rb', line 17

def foreign_key_add_sql(*args);  raise NotImplementedError; end

#foreign_key_drop_sql(*args) ⇒ Object

Raises:

  • (NotImplementedError)


18
# File 'lib/ardb/adapter/base.rb', line 18

def foreign_key_drop_sql(*args); raise NotImplementedError; end

#load_ruby_schemaObject



34
35
36
# File 'lib/ardb/adapter/base.rb', line 34

def load_ruby_schema
  load @ruby_schema_path
end

#load_schemaObject



25
26
27
28
29
30
31
32
# File 'lib/ardb/adapter/base.rb', line 25

def load_schema
  # silence STDOUT
  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_schemaObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/ardb/adapter/base.rb', line 38

def load_sql_schema
  raise NotImplementedError
end