module Sequel::DuplicateColumnsHandler
Constants
- CALLER_ARGS
:nocov:
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 47 def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless block_given?; nil), &block) 48 raise Error, "Cannot provide both an argument and a block to on_duplicate_columns" if handler && block 49 clone(:on_duplicate_columns=>handler||block) 50 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 55 def columns=(cols) 56 if cols && cols.uniq.size != cols.size 57 handle_duplicate_columns(cols) 58 end 59 super 60 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 77 def duplicate_columns_handler_type(cols) 78 handler = opts.fetch(:on_duplicate_columns){db.opts.fetch(:on_duplicate_columns, :warn)} 79 80 if handler.respond_to?(:call) 81 handler.call(cols) 82 else 83 handler 84 end 85 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 63 def handle_duplicate_columns(cols) 64 message = "#{caller(*CALLER_ARGS).first}: One or more duplicate columns present in #{cols.inspect}" 65 66 case duplicate_columns_handler_type(cols) 67 when :raise 68 raise DuplicateColumnError, message 69 when :warn 70 warn message 71 end 72 end