module Sequel::DuplicateColumnsHandler
Constants
- CALLER_ARGS
Public Instance Methods
columns=(cols)
click to toggle source
Override the attr_writer to check for duplicate columns, and call #handle_duplicate_columns if necessary.
Calls superclass method
# File lib/sequel/extensions/duplicate_columns_handler.rb, line 48 def columns=(cols) if cols && cols.uniq.size != cols.size handle_duplicate_columns(cols) end super end
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, line 41 def on_duplicate_columns(handler = (raise Error, "Must provide either an argument or a block to on_duplicate_columns" unless block_given?; nil), &block) raise Error, "Cannot provide both an argument and a block to on_duplicate_columns" if handler && block clone(:on_duplicate_columns=>handler||block) end
Private Instance Methods
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, line 72 def duplicate_columns_handler_type(cols) handler = opts.fetch(:on_duplicate_columns){db.opts.fetch(:on_duplicate_columns, :warn)} if handler.respond_to?(:call) handler.call(cols) else handler end 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, line 58 def handle_duplicate_columns(cols) message = "#{caller(*CALLER_ARGS).first}: One or more duplicate columns present in #{cols.inspect}" case duplicate_columns_handler_type(cols) when :raise raise DuplicateColumnError, message when :warn warn message end end