class RailsSqlViews4::ConnectionAdapters::MappingDefinition
Public Class Methods
new(columns)
click to toggle source
Generates a hash of the form :old_column => :new_column Initially, it’ll map column names to themselves. use map_column
to modify the list.
# File lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb, line 30 def initialize(columns) @columns = columns @map = Hash.new() columns.each do |c| @map[c] = c end end
Public Instance Methods
map_column(old_name, new_name)
click to toggle source
Create a mapping from an old column name to a new one. If the new name is nil, specify that the old column shouldn’t appear in this new view.
# File lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb, line 42 def map_column(old_name, new_name) unless @map.include?(old_name) raise ActiveRecord::ActiveRecordError, "column #{old_name} not found, can't be mapped" end if new_name.nil? @map.delete old_name @columns.delete old_name else @map[old_name] = new_name end end
select_cols()
click to toggle source
# File lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb, line 54 def select_cols @columns end
view_cols()
click to toggle source
# File lib/rails_sql_views4/connection_adapters/abstract/schema_definitions.rb, line 58 def view_cols @columns.map { |c| @map[c] } end