Sha256: c2c99c64c69bb388f4bf2c48cf8bd6f66b22debf85585508c0bbed9c40507495

Contents?: true

Size: 989 Bytes

Versions: 22

Compression:

Stored size: 989 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| e.start_with?('/') ? eval(e) : Regexp.new(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

22 entries across 22 versions & 1 rubygems

Version Path
arql-0.3.16 lib/arql/commands/models.rb
arql-0.3.15 lib/arql/commands/models.rb
arql-0.3.14 lib/arql/commands/models.rb
arql-0.3.13 lib/arql/commands/models.rb
arql-0.3.12 lib/arql/commands/models.rb
arql-0.3.11 lib/arql/commands/models.rb
arql-0.3.10 lib/arql/commands/models.rb
arql-0.3.9 lib/arql/commands/models.rb
arql-0.3.8 lib/arql/commands/models.rb
arql-0.3.7 lib/arql/commands/models.rb
arql-0.3.6 lib/arql/commands/models.rb
arql-0.3.5 lib/arql/commands/models.rb
arql-0.3.3 lib/arql/commands/models.rb
arql-0.3.2 lib/arql/commands/models.rb
arql-0.3.1 lib/arql/commands/models.rb
arql-0.3.0 lib/arql/commands/models.rb
arql-0.2.14 lib/arql/commands/models.rb
arql-0.2.13 lib/arql/commands/models.rb
arql-0.2.12 lib/arql/commands/models.rb
arql-0.2.11 lib/arql/commands/models.rb