lib/rom/sql/header.rb in rom-sql-0.7.0 vs lib/rom/sql/header.rb in rom-sql-0.8.0
- old
+ new
@@ -2,10 +2,12 @@
module SQL
# @private
class Header
include Dry::Equalizer(:columns, :table)
+ SEP_REGEX = /_{2,3}/.freeze
+
attr_reader :columns, :table
def initialize(columns, table)
@columns = columns
@table = table
@@ -22,10 +24,14 @@
h[left.to_sym] = (right || left).to_sym
end
end
def names
- columns.map { |col| :"#{col.to_s.split('___').last}" }
+ columns.map { |col| :"#{col.to_s.split(SEP_REGEX).last}" }
+ end
+
+ def exclude(*names)
+ self.class.new(columns.find_all { |col| !names.include?(col) }, table)
end
def project(*names)
self.class.new(columns.find_all { |col| names.include?(col) }, table)
end