Created
November 20, 2015 00:19
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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