Sha256: 9ed5d1fe0523756afa2b34997dd0e7f8572e4f1797de06c53a89c874239ee4dd

Contents?: true

Size: 952 Bytes

Versions: 3

Compression:

Stored size: 952 Bytes

Contents

require 'terminal-table'

module Arql::Commands
  module Models
    class << self
      def models
        t = []
        t << ['Table Name', 'Model Class', 'Abbr', 'Comment']
        t << nil
        Arql::Definition.models.each do |definition|
          t << [definition[:table], definition[:model].name, definition[:abbr] || '', definition[:comment] || '']
        end
        t
      end

      def models_table(regexp)
        Terminal::Table.new do |t|
          models.each_with_index { |row, idx| t << (row || :separator) if row.nil? ||
            regexp.nil? ||
            idx.zero? ||
            row.any? { |e| e =~ regexp }
          }
        end
      end
    end
  end

  Pry.commands.block_command 'm' do |regexp|
    puts
    puts Models::models_table(regexp.try { |e| eval(e) })
  end

  Pry.commands.alias_command 'l', 'm'
end

module Kernel
  def models
    Arql::Commands::Models::models
  end

  def tables
    models
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
arql-0.2.8 lib/arql/commands/models.rb
arql-0.2.7 lib/arql/commands/models.rb
arql-0.2.6 lib/arql/commands/models.rb