michaelmior /
NoSE
| 1 | # frozen_string_literal: true |
||
| 2 | # rubocop:disable Lint/HandleExceptions |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 3 | begin |
||
| 4 | 1 | require 'binding_of_caller' |
|
| 5 | 1 | require 'pry' |
|
| 6 | rescue LoadError |
||
| 7 | # Ignore in case we are not in development mode |
||
| 8 | end |
||
| 9 | # rubocop:enable Lint/HandleExceptions |
||
| 10 | |||
| 11 | 1 | module NoSE |
|
| 12 | # Various helpful debugging snippets |
||
| 13 | 1 | module Debug |
|
| 14 | # Convenience method to break in IndexLookupStep when |
||
| 15 | # a particular set of indexes is reach when planning |
||
| 16 | # @return [void] |
||
| 17 | 1 | def self.break_on_indexes(*index_keys) |
|
| 18 | apply = binding.of_caller(1) |
||
| 19 | parent = apply.eval 'parent' |
||
| 20 | index = apply.eval 'index' |
||
| 21 | current_keys = parent.parent_steps.indexes.map(&:key) << index.key |
||
| 22 | |||
| 23 | # rubocop:disable Lint/Debugger |
||
| 24 | binding.pry if current_keys == index_keys |
||
| 25 | # rubocop:enable Lint/Debugger |
||
| 26 | end |
||
| 27 | |||
| 28 | # Export entities in a model as global |
||
| 29 | # variales for easier access when debugging |
||
| 30 | # @return [void] |
||
| 31 | 1 | def self.export_model(model) |
|
| 32 | model.entities.each do |name, entity| |
||
| 33 | # rubocop:disable Lint/Eval |
||
| 34 | eval("$#{name} = entity") |
||
|
0 ignored issues
–
show
|
|||
| 35 | # rubocop:enable Lint/Eval |
||
| 36 | |||
| 37 | entity.fields.merge(entity.foreign_keys).each do |field_name, field| |
||
| 38 | entity.define_singleton_method field_name.to_sym, -> { field } |
||
| 39 | end |
||
| 40 | end |
||
| 41 | |||
| 42 | nil |
||
| 43 | end |
||
| 44 | end |
||
| 45 | end |
||
| 46 |