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