Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/db-charmer.rb,
lib/gems/activerecord-import.rb,
lib/rails/3.0/active_record/base.rb

Class Method Summary collapse

Class Method Details

.columns_with_wraithdb_columnsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/rails/3.0/active_record/base.rb', line 26

def columns_with_wraithdb_columns
  begin
    columns_without_wraithdb_columns
  rescue StandardError => e
    columns = WraithDB::Schema.tables[table_name.to_s].columns
    return columns.map {|column|
      WraithDB::Column.new(column)
    }
  end
end

.establish_connection_with_activerecord_import(*args) ⇒ Object Also known as: establish_connection



4
5
6
7
8
9
10
11
12
13
# File 'lib/gems/activerecord-import.rb', line 4

def establish_connection_with_activerecord_import(*args)
  establish_connection_without_activerecord_import(*args)
  begin
    ActiveSupport.run_load_hooks(:active_record_connection_established, connection)
  rescue StandardError => e
    # ActiveImport will not work but this shouldn't be an issue as it's 
    # only used in Rake tasks. If the DB is down we won't be importing
    # anything in a rake task anyhow.
  end
end

.relation_with_wraith_charmed(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/gems/db-charmer.rb', line 5

def relation_with_wraith_charmed(*args, &block)
  begin
    relation_without_wraith_charmed(*args, &block)
  rescue StandardError => e
    # This leaves connection resolution for db_charmer to runtime rather than assigning an
    # instance variable
    base = self
    rel = relation_without_db_charmer

    rel.define_singleton_method(:db_charmer_connection) do
      base.connection
    end
    rel.db_charmer_enable_slaves = self.db_charmer_slaves.any?
    rel.db_charmer_connection_is_forced = !db_charmer_top_level_connection?
    rel
  end
end

.replace_bind_variables_with_wraithdb(statement, values) ⇒ Object

If we do variable binding inside of where clauses on scopes it needs to work without an actual connection. The implementation provided mirrors the Mysql2Adapter



6
7
8
9
10
11
12
13
14
# File 'lib/rails/3.0/active_record/base.rb', line 6

def replace_bind_variables_with_wraithdb(statement, values)
  begin
    replace_bind_variables_without_wraithdb(statement, values)
  rescue StandardError => e
    raise e if e.kind_of? PreparedStatementInvalid
    bound = values.dup
    statement.gsub('?') { quote_bound_value(bound.shift, WraithDB::Schema.connection) }
  end
end

.table_exists_with_wraithdb_columns?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/rails/3.0/active_record/base.rb', line 17

def table_exists_with_wraithdb_columns?
  begin
    table_exists_without_wraithdb_columns?
  rescue StandardError => e
    WraithDB::Schema.tables.has_key?(table_name.to_s)
  end
end