Class: ActiveRecord::ConnectionAdapters::UnitRecordAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::UnitRecordAdapter
- Defined in:
- lib/active_record/connection_adapters/unit_record_adapter.rb
Constant Summary collapse
- EXCEPTION_MESSAGE =
"ActiveRecord is disconnected; database access is unavailable in unit tests."
Instance Method Summary collapse
- #change_column(table_name, column_name, type, options = {}) ⇒ Object
- #change_column_default(table_name, column_name, default) ⇒ Object
- #change_strategy(new_strategy, &block) ⇒ Object
-
#columns(table_name, name = nil) ⇒ Object
:nodoc:.
- #create_table(table_name, options = {}) {|table_definition| ... } ⇒ Object
- #execute(sql, name = nil) ⇒ Object
-
#initialize(config = {}) ⇒ UnitRecordAdapter
constructor
A new instance of UnitRecordAdapter.
- #insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
- #native_database_types ⇒ Object
- #rename_column(table_name, column_name, new_column_name) ⇒ Object
- #rename_table(table_name, new_name) ⇒ Object
- #select_rows(sql, name = nil) ⇒ Object
- #tables ⇒ Object
Constructor Details
#initialize(config = {}) ⇒ UnitRecordAdapter
Returns a new instance of UnitRecordAdapter.
4 5 6 7 8 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 4 def initialize(config = {}) super @strategy = config[:strategy] || :raise @cached_columns = {"schema_info" => []} end |
Instance Method Details
#change_column(table_name, column_name, type, options = {}) ⇒ Object
72 73 74 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 72 def change_column(table_name, column_name, type, = {}) raise_or_noop end |
#change_column_default(table_name, column_name, default) ⇒ Object
76 77 78 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 76 def change_column_default(table_name, column_name, default) raise_or_noop end |
#change_strategy(new_strategy, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 43 def change_strategy(new_strategy, &block) unless [:noop, :raise].include?(new_strategy.to_sym) raise ArgumentError, "#{new_strategy.inspect} is not a valid strategy - valid values are :noop and :raise" end begin old_strategy = @strategy @strategy = new_strategy.to_sym yield ensure @strategy = old_strategy end end |
#columns(table_name, name = nil) ⇒ Object
:nodoc:
10 11 12 13 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 10 def columns(table_name, name = nil)#:nodoc: @cached_columns[table_name.to_s] || raise("Columns are not cached for '#{table_name}' - check schema.rb") end |
#create_table(table_name, options = {}) {|table_definition| ... } ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 15 def create_table(table_name, ={}) table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new(self) table_definition.primary_key([:primary_key] || "id") unless [:id] == false yield table_definition @cached_columns[table_name.to_s] = table_definition.columns.map do |c| ActiveRecord::ConnectionAdapters::Column.new(c.name.to_s, c.default, c.sql_type, c.null) end end |
#execute(sql, name = nil) ⇒ Object
56 57 58 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 56 def execute(sql, name = nil) raise_or_noop end |
#insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
60 61 62 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 60 def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) raise_or_noop end |
#native_database_types ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 25 def native_database_types # Copied from the MysqlAdapter so ColumnDefinition#sql_type will work { :primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY", :string => { :name => "varchar", :limit => 255 }, :text => { :name => "text" }, :integer => { :name => "int", :limit => 11 }, :float => { :name => "float" }, :decimal => { :name => "decimal" }, :datetime => { :name => "datetime" }, :timestamp => { :name => "datetime" }, :time => { :name => "time" }, :date => { :name => "date" }, :binary => { :name => "blob" }, :boolean => { :name => "tinyint", :limit => 1 } } end |
#rename_column(table_name, column_name, new_column_name) ⇒ Object
80 81 82 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 80 def rename_column(table_name, column_name, new_column_name) raise_or_noop end |
#rename_table(table_name, new_name) ⇒ Object
68 69 70 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 68 def rename_table(table_name, new_name) raise_or_noop end |
#select_rows(sql, name = nil) ⇒ Object
64 65 66 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 64 def select_rows(sql, name = nil) raise_or_noop [] end |
#tables ⇒ Object
84 85 86 |
# File 'lib/active_record/connection_adapters/unit_record_adapter.rb', line 84 def tables @cached_columns.keys end |