lib/rom/sql/header.rb in rom-sql-0.3.2 vs lib/rom/sql/header.rb in rom-sql-0.4.0.beta1
- old
+ new
@@ -1,16 +1,15 @@
module ROM
module SQL
# @private
class Header
- include Charlatan.new(:columns)
include Equalizer.new(:columns, :table)
- attr_reader :table
+ attr_reader :columns, :table
def initialize(columns, table)
- super
+ @columns = columns
@table = table
end
def to_ary
columns
@@ -23,34 +22,34 @@
h[left.to_sym] = (right || left).to_sym
end
end
def names
- map { |col| :"#{col.to_s.split('___').last}" }
+ columns.map { |col| :"#{col.to_s.split('___').last}" }
end
def project(*names)
- find_all { |col| names.include?(col) }
+ self.class.new(columns.find_all { |col| names.include?(col) }, table)
end
def qualified
- map { |col| :"#{table}__#{col}" }
+ self.class.new(columns.map { |col| :"#{table}__#{col}" }, table)
end
def rename(options)
- map do |col|
+ self.class.new(columns.map { |col|
new_name = options[col]
if new_name
:"#{col}___#{new_name}"
else
col
end
- end
+ }, table)
end
def prefix(col_prefix)
- rename(Hash[map { |col| [col, :"#{col_prefix}_#{col}"] }])
+ rename(Hash[columns.map { |col| [col, :"#{col_prefix}_#{col}"] }])
end
end
end
end