module Sequel::DuplicateColumnsHandler
Constants
- CALLER_ARGS
-
:nocov:
Public Instance Methods
Source
# File lib/sequel/extensions/duplicate_columns_handler.rb 48 def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless defined?(yield); nil), &block) 49 raise Error, "Cannot provide both an argument and a block to on_duplicate_columns" if handler && block 50 clone(:on_duplicate_columns=>handler||block) 51 end
Customize handling of duplicate columns for this dataset.
Private Instance Methods
Source
# File lib/sequel/extensions/duplicate_columns_handler.rb 56 def columns=(cols) 57 if cols && cols.uniq.size != cols.size 58 handle_duplicate_columns(cols) 59 end 60 super 61 end
Call handle_duplicate_columns
if there are duplicate columns.
Calls superclass method
Source
# File lib/sequel/extensions/duplicate_columns_handler.rb 78 def duplicate_columns_handler_type(cols) 79 handler = opts.fetch(:on_duplicate_columns){db.opts.fetch(:on_duplicate_columns, :warn)} 80 81 if handler.respond_to?(:call) 82 handler.call(cols) 83 else 84 handler 85 end 86 end
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.
Source
# File lib/sequel/extensions/duplicate_columns_handler.rb 64 def handle_duplicate_columns(cols) 65 message = "#{caller(*CALLER_ARGS).first}: One or more duplicate columns present in #{cols.inspect}" 66 67 case duplicate_columns_handler_type(cols) 68 when :raise, 'raise' 69 raise DuplicateColumnError, message 70 when :warn, 'warn' 71 warn message 72 end 73 end
Invoke the appropriate behavior when duplicate columns are present.