Class: Amalgalite::SQLite3::Database::Function

Inherits:
Object
  • Object
show all
Defined in:
lib/amalgalite/sqlite3/database/function.rb

Overview

A wrapper around a proc for use as an SQLite Ddatabase fuction

f = Function.new( 'md5', lambda { |x| Digest::MD5.hexdigest( x.to_s ) } )

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, _proc) ⇒ Function

Initialize with the name and the Proc



22
23
24
25
# File 'lib/amalgalite/sqlite3/database/function.rb', line 22

def initialize( name, _proc )
  @name = name
  @function = _proc
end

Instance Attribute Details

#nameObject (readonly)

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



11
12
13
# File 'lib/amalgalite/sqlite3/database/function.rb', line 11

def name
  @name
end

Class Method Details

.signature(name, arity) ⇒ Object

The unique signature of this function. This is used to determin if the function is already registered or not



16
17
18
# File 'lib/amalgalite/sqlite3/database/function.rb', line 16

def self.signature( name, arity )
  "#{name}/#{arity}"
end

Instance Method Details

#arityObject

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



37
38
39
# File 'lib/amalgalite/sqlite3/database/function.rb', line 37

def arity
  @function.arity
end

#call(*args) ⇒ Object

Invoke the proc



43
44
45
# File 'lib/amalgalite/sqlite3/database/function.rb', line 43

def call( *args )
  @function.call( *args )
end

#signatureObject Also known as: to_s

The unique signature of this function



29
30
31
# File 'lib/amalgalite/sqlite3/database/function.rb', line 29

def signature
  @signature ||= Function.signature( name, arity )
end