Skip to content

Instantly share code, notes, and snippets.

@jah2488
Created November 20, 2015 00:19
Show Gist options
  • Select an option

  • Save jah2488/a385cf0e8421429562c8 to your computer and use it in GitHub Desktop.

Select an option

Save jah2488/a385cf0e8421429562c8 to your computer and use it in GitHub Desktop.
Playing around with some data-mapper-esque orm nonsense and somehow pumped out this monster.
def translate_fields(field)
mapping.invert.fetch(field.to_sym, field.to_sym)
end
def perform_query(sql, opts = {})
results = get_records_from_query(sql, opts)
columns = results.shift
results.map do |row|
model_attr_hash = Hash[
column_names.map(&method(:translate_fields)).zip([nil] * column_names.count)
].merge(Hash[columns.map(&:method(:translate_fields))).zip(row)])
model.public_send(model_meth, **model_attr_hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment