Module: SqlValuedColumns::ClassMethods

Defined in:
lib/sql_valued_columns.rb

Instance Method Summary collapse

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 - Array of arguments to pass to the SQL function specified. If an argument is a Symbol, the name it represents will be called on the model at save time. If it is a Proc, it will be called with the model passed as the only argument to the Proc. If it is a String, the String will 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)
  options = args.extract_options!
  raw = options[:raw] == true
  @sql_columns ||= { }
  @sql_columns[column] = [function, args, raw]
end

#sql_columnsObject



35
36
37
# File 'lib/sql_valued_columns.rb', line 35

def sql_columns
  @sql_columns ||= { }
end