Sha256: 613fdba407ccfefe5610d1883bc0315d1950392f50e281eab1e672d106b1645b

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

# -*- encoding : utf-8 -*-
module ActiveRecord

  module ConnectionAdapters
    class AbstractAdapter
      def match(string)
        raise "match not implemented"
      end

      def cast_types
        native_database_types.merge custom_cast_types
      end

      def custom_cast_types
        {}
      end
    end

    class PostgreSQLAdapter
      def match(string)
        "~* #{string}"
      end
    end

    module MysqlCommon
      def match(string)
        "REGEXP #{string}"
      end

      def custom_cast_types
        { :string  => { :name=>'char'    },
          :integer => { :name=>'signed'  },
          :text    => { :name=>'char'    },
          :float   => { :name=>'decimal' },
          :binary  => { :name=>'binary'  }  }
      end
    end

    class MysqlAdapter
      include MysqlCommon
    end

    class Mysql2Adapter
      include MysqlCommon
    end

    class SQLiteAdapter
      def match(string)
        "REGEXP #{string}"
      end
    end
  end
  
  module Transactions
    #FIXME!!
    # the following code is already in Rails 4 (see https://github.com/rails/rails/commit/c8792c7b2ea4f5fe7a5610225433ea8dd8d0f83e)
    # it allows manual rollbacks in after_save (eg store events) to reset the object correctly
    #  hopefully we can soon get rid of this code!
    
    def with_transaction_returning_status
      status = nil
      self.class.transaction do
        add_to_transaction
        begin
          status = yield
        rescue ActiveRecord::Rollback
          @_start_transaction_state[:level] = (@_start_transaction_state[:level] || 0) - 1
          status = nil
        end

        raise ActiveRecord::Rollback unless status
      end
      status
    end
  end
  
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
card-1.16.6 lib/card/active_record_ext.rb
card-1.16.5 lib/card/active_record_ext.rb
card-1.16.4 lib/card/active_record_ext.rb
card-1.16.3 lib/card/active_record_ext.rb
card-1.16.2 lib/card/active_record_ext.rb
card-1.16.1 lib/card/active_record_ext.rb
card-1.16.0 lib/card/active_record_ext.rb
card-1.15.7 lib/card/active_record_ext.rb
card-1.15.6 lib/card/active_record_ext.rb
card-1.15.5 lib/card/active_record_ext.rb
card-1.15.4 lib/card/active_record_ext.rb
card-1.15.3 lib/card/active_record_ext.rb
card-1.15.2 lib/card/active_record_ext.rb
card-1.15.1 lib/card/active_record_ext.rb
card-1.15.0 lib/card/active_record_ext.rb
card-1.15.pre2 lib/card/active_record_ext.rb
card-1.15.pre lib/card/active_record_ext.rb