Class: SQLite3::Database::FunctionProxy
- Inherits:
-
Object
- Object
- SQLite3::Database::FunctionProxy
- Defined in:
- lib/sqlite3/database.rb
Overview
A helper class for dealing with custom functions (see #create_function, #create_aggregate, and #create_aggregate_handler). It encapsulates the opaque function object that represents the current invocation. It also provides more convenient access to the API functions that operate on the function object.
This class will almost always be instantiated indirectly, by working with the create methods mentioned above.
Instance Attribute Summary collapse
-
#result ⇒ Object
Returns the value of attribute result.
Class Method Summary collapse
Instance Method Summary collapse
-
#[](key) ⇒ Object
Returns the value with the given key from the context.
-
#[]=(key, value) ⇒ Object
Sets the value with the given key in the context.
-
#initialize ⇒ FunctionProxy
constructor
Create a new FunctionProxy that encapsulates the given
func
object.
Constructor Details
#initialize ⇒ FunctionProxy
Create a new FunctionProxy that encapsulates the given func
object. If context is non-nil, the functions context will be set to that. If it is non-nil, it must quack like a Hash. If it is nil, then none of the context functions will be available.
63 64 65 66 |
# File 'lib/sqlite3/database.rb', line 63 def initialize @result = nil @context = {} end |
Instance Attribute Details
#result ⇒ Object
Returns the value of attribute result.
48 49 50 |
# File 'lib/sqlite3/database.rb', line 48 def result @result end |
Class Method Details
.proxy(handler) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/sqlite3/database.rb', line 50 def self.proxy(handler) proc do |*args| fp = new args.unshift(fp) handler.call(*args) fp.result end end |
Instance Method Details
#[](key) ⇒ Object
Returns the value with the given key from the context. This is only available to aggregate functions.
70 71 72 |
# File 'lib/sqlite3/database.rb', line 70 def []( key ) @context[ key ] end |
#[]=(key, value) ⇒ Object
Sets the value with the given key in the context. This is only available to aggregate functions.
76 77 78 |
# File 'lib/sqlite3/database.rb', line 76 def []=( key, value ) @context[ key ] = value end |