Sha256: f58c2cf735db1549eda0171802d4a208e4a35c983d773681918cbec926a1ee3a
Contents?: true
Size: 973 Bytes
Versions: 1
Compression:
Stored size: 973 Bytes
Contents
class Sqlite3Extension def self.setup(connection) @connection = connection regexp year end def self.regexp @connection.create_function("regexp", 2) do |func, expr, value| begin if value.to_s && value.to_s.match(Regexp.new(expr.to_s)) func.result = 1 else func.result = 0 end rescue => e puts "error: #{e}" end end end def self.year @connection.create_function("year", 1) do |func, date| begin func.result = Date.parse(date).year rescue => e puts "error: #{e}" end end end end require 'active_record/connection_adapters/abstract/connection_pool' class ActiveRecord::ConnectionAdapters::ConnectionPool alias orig_connection connection def connection conn = orig_connection if conn.adapter_name.eql?("SQLite") Sqlite3Extension.setup(conn.instance_variable_get(:@connection)) end return conn end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
bookyt-0.0.1 | lib/sqlite3_extensions.rb |