Class: Gm::Notepad::InputHandlers::QueryTableNamesHandler
- Inherits:
-
DefaultHandler
- Object
- DefaultHandler
- Gm::Notepad::InputHandlers::QueryTableNamesHandler
- Defined in:
- lib/gm/notepad/input_handlers/query_table_names_handler.rb
Constant Summary collapse
- QUERY_TABLE_NAMES_PREFIX =
'+'.freeze
- WITH_GREP_REGEXP =
%r{(?<declaration>\/(?<grep>[^\/]+)/)}
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from DefaultHandler
build_if_handled, #initialize, #lines
Constructor Details
This class inherits a constructor from Gm::Notepad::InputHandlers::DefaultHandler
Class Method Details
.handles?(input:) ⇒ Boolean
8 9 10 11 12 13 14 15 16 |
# File 'lib/gm/notepad/input_handlers/query_table_names_handler.rb', line 8 def self.handles?(input:) # Does not have the table prefix return false unless input.match(/^\+/) # It is only the table prefix return true if input.match(/^\+$/) # It is querying all tables by way of grep return true if input.match(/^\+\//) false end |
Instance Method Details
#after_initialize! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gm/notepad/input_handlers/query_table_names_handler.rb', line 19 def after_initialize! grep = nil input.sub!(/^./,'') if match = input.match(WITH_GREP_REGEXP) input.sub!(match[:declaration], '') grep = match[:grep] end table_names = table_registry.table_names table_names = table_names.grep(%r{#{grep}}) if grep table_names.each do |table_name| input.render_current_text(text: table_name, to_interactive: true, to_output: false, expand_line: false) end end |