Class: Chlgr::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/chlr/client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dbObject



18
19
20
# File 'lib/chlr/client.rb', line 18

def self.db
  @@db
end

.setup(path) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/chlr/client.rb', line 5

def self.setup(path)
  @@db = Sequel.sqlite(File.expand_path(path))
  unless @@db.table_exists?(:logs)
    @@db.create_table :logs do
      primary_key :id
      Text :text
      DateTime :created_at
    end
  end
  require 'chlr/log'
  self
end

.startObject



22
23
24
# File 'lib/chlr/client.rb', line 22

def self.start
  self.new.start
end

Instance Method Details

#call_command(text) ⇒ Object



37
38
39
40
# File 'lib/chlr/client.rb', line 37

def call_command(text)
  cmd, *args = text.split(/\s/)
  Command.get(cmd).call(*args)
end

#startObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/chlr/client.rb', line 26

def start
  Readline.basic_word_break_characters= "\t\n\"\\'`><=;|&{("
  Readline.completion_proc = lambda do |text|
    Command.search(text)
  end

  while buf = Readline.readline('> ', true)
    call_command(buf)
  end
end