Sha256: f7557c45b351c276767890ea60ee1b36abbe2127292df83a76a9ecc48c4d93a4

Contents?: true

Size: 1.1 KB

Versions: 83

Compression:

Stored size: 1.1 KB

Contents

module Amalgalite::SQLite3
  class Database
    ##
    # A wrapper around a proc for use as an SQLite Ddatabase fuction
    #
    #   f = Function.new( 'md5', lambda { |x| Digest::MD5.hexdigest( x.to_s ) } )
    #
    class Function

      # the name of the function, and how it will be called in SQL
      attr_reader :name

      # The unique signature of this function.  This is used to determin if the
      # function is already registered or not
      #
      def self.signature( name, arity )
        "#{name}/#{arity}"
      end

      # Initialize with the name and the Proc
      #
      def initialize( name, _proc )
        @name = name
        @function = _proc
      end

      # The unique signature of this function
      #
      def signature
        @signature ||= Function.signature( name, arity )
      end
      alias :to_s :signature

      # The arity of SQL function, -1 means it is takes a variable number of
      # arguments.
      #
      def arity
        @function.arity
      end

      # Invoke the proc 
      #
      def call( *args )
        @function.call( *args )
      end
    end
  end
end

Version data entries

83 entries across 83 versions & 2 rubygems

Version Path
amalgalite-1.6.3-x64-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.3 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.1-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.1-x64-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.1 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.0-x64-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.0-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.6.0 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.5.0-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.5.0 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.4.1-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.4.1 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.4.0-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.4.0 lib/amalgalite/sqlite3/database/function.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/amalgalite-1.3.0/lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.3.0-x86-mswin32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.3.0 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.1.2-x86-mingw32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.1.2-x86-mswin32 lib/amalgalite/sqlite3/database/function.rb
amalgalite-1.1.2 lib/amalgalite/sqlite3/database/function.rb