Sha256: 9e06646ca20025eb1460cc490d3a6f3e32e08e498b0c4cdb0ad74fa3a79d3a1c

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

require "gm/notepad/input_handlers/default_handler"

module Gm
  module Notepad
    module InputHandlers
      class QueryTableNamesHandler < DefaultHandler
        QUERY_TABLE_NAMES_PREFIX = '+'.freeze
        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

        WITH_GREP_REGEXP = %r{(?<declaration>\/(?<grep>[^\/]+)/)}
        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
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
gm-notepad-0.0.18 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.17 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.16 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.15 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.14 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.13 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.12 lib/gm/notepad/input_handlers/query_table_names_handler.rb
gm-notepad-0.0.11 lib/gm/notepad/input_handlers/query_table_names_handler.rb