Sha256: fdf7bff260a2cb08ca58b33485f54d80963f59be6b3480d4d3d876ebd315bf60

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'set'

module SqliteExt

  module DbAutoCreatesRegisteredFunctions

    # Adds functions registered with SqliteExt to each new
    # instance before it is returned from `.new` or `.open` or is
    # passed to the given block.
    if RUBY_VERSION.split('.').first.to_i >= 2

      def initialize(file, *other_init_args)
        if block_given?
          super file, *other_init_args do
            SqliteExt.enhance_db_session self
            yield self
          end
        else
          super
          SqliteExt.enhance_db_session self
        end
      end

    else

      def self.included(other)
        orig_initialize = other.instance_method(:initialize)

        other.send :define_method, :initialize, proc{ |file, *other_init_args, &block|
          if block
            orig_initialize.bind(self).call file, *other_init_args do
              SqliteExt.enhance_db_session self
              block.call self
            end
          else
            orig_initialize.bind(self).call file, *other_init_args
            SqliteExt.enhance_db_session self
          end
        }
      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sqlite_ext-1.5.0 lib/sqlite_ext/db_auto_creates_registered_functions.rb