Module: SqlValuedColumns::ClassMethods
- Defined in:
- lib/sql_valued_columns.rb
Instance Method Summary collapse
-
#sql_column(column, function, *args) ⇒ Object
Indicates the given column will have its value filled by the result of an SQL function.
- #sql_columns ⇒ Object
Instance Method Details
#sql_column(column, function, *args) ⇒ Object
Indicates the given column will have its value filled by the result of an SQL function. Pass a hash as the last argument with any optional args.
Arguments
-
column-Symbol, the name of the column to fill -
function-String, the name of the function to execute, or the literal SQL to call if options is true -
args-Arrayof arguments to pass to the SQL function specified. If an argument is aSymbol, the name it represents will be called on the model at save time. If it is aProc, it will be called with the model passed as the only argument to theProc. If it is aString, theStringwill evaluated if the pattern #some_code appears within it. Once all these conditions have been exhausted, the resultant values will be quoted as appropriate by your database adapter and populate the arguments list of the SQL function you specified. -
options(optional) - Hash of optional arguments ( :raw ) .
28 29 30 31 32 33 |
# File 'lib/sql_valued_columns.rb', line 28 def sql_column(column, function, *args) = args. raw = [:raw] == true @sql_columns ||= { } @sql_columns[column] = [function, args, raw] end |
#sql_columns ⇒ Object
35 36 37 |
# File 'lib/sql_valued_columns.rb', line 35 def sql_columns @sql_columns ||= { } end |