Class: Amalgalite::SQLite3::Database::Function
- Inherits:
-
Object
- Object
- Amalgalite::SQLite3::Database::Function
- 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
-
#name ⇒ Object
readonly
the name of the function, and how it will be called in SQL.
Class Method Summary collapse
-
.signature(name, arity) ⇒ Object
The unique signature of this function.
Instance Method Summary collapse
-
#arity ⇒ Object
The arity of SQL function, -1 means it is takes a variable number of arguments.
-
#call(*args) ⇒ Object
Invoke the proc.
-
#initialize(name, _proc) ⇒ Function
constructor
Initialize with the name and the Proc.
-
#signature ⇒ Object
(also: #to_s)
The unique signature of this function.
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
#name ⇒ Object (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
#arity ⇒ Object
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 |