module Sequel::DuplicateColumnsHandler
Constants
- CALLER_ARGS
Public Instance Methods
on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless block_given?; nil), &block)
click to toggle source
Customize handling of duplicate columns for this dataset.
# File lib/sequel/extensions/duplicate_columns_handler.rb 45 def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless block_given?; nil), &block) 46 raise Error, "Cannot provide both an argument and a block to on_duplicate_columns" if handler && block 47 clone(:on_duplicate_columns=>handler||block) 48 end
Private Instance Methods
columns=(cols)
click to toggle source
Call handle_duplicate_columns
if there are duplicate columns.
Calls superclass method
# File lib/sequel/extensions/duplicate_columns_handler.rb 53 def columns=(cols) 54 if cols && cols.uniq.size != cols.size 55 handle_duplicate_columns(cols) 56 end 57 super 58 end
duplicate_columns_handler_type(cols)
click to toggle source
Try to find dataset option for on_duplicate_columns. If not present on the dataset, use the on_duplicate_columns
option on the database. If not present on the database, default to :warn.
# File lib/sequel/extensions/duplicate_columns_handler.rb 75 def duplicate_columns_handler_type(cols) 76 handler = opts.fetch(:on_duplicate_columns){db.opts.fetch(:on_duplicate_columns, :warn)} 77 78 if handler.respond_to?(:call) 79 handler.call(cols) 80 else 81 handler 82 end 83 end
handle_duplicate_columns(cols)
click to toggle source
Invoke the appropriate behavior when duplicate columns are present.
# File lib/sequel/extensions/duplicate_columns_handler.rb 61 def handle_duplicate_columns(cols) 62 message = "#{caller(*CALLER_ARGS).first}: One or more duplicate columns present in #{cols.inspect}" 63 64 case duplicate_columns_handler_type(cols) 65 when :raise 66 raise DuplicateColumnError, message 67 when :warn 68 warn message 69 end 70 end