Class: Redix::Logic

Inherits:
Object
  • Object
show all
Defined in:
lib/redix/logic.rb

Class Method Summary collapse

Class Method Details

.about_dialogObject



52
53
54
55
56
57
58
# File 'lib/redix/logic.rb', line 52

def about_dialog
  a = AboutDialog.new
  a.setupUi
  # a.title.setText("RediX")
  a.textBrowser.setHtml("About <a href='http://github.com/nofxx/redix'>Redix</a>....")
  a.show
end

.build_dbsObject



27
28
29
30
31
32
33
34
35
# File 'lib/redix/logic.rb', line 27

def build_dbs
  0.upto(15) do |i|
    a = Qt::Action.new(@u.mainWindow)
    a.connect(SIGNAL('triggered()')) { reconnect(@db = i) }
    # a.objectName("action#{i}")
    @u.menuChange.addAction(a)
    a.text = Qt::Application.translate("MainWindow", "##{i}", nil, Qt::Application::UnicodeUTF8)
  end
end

.build_keysObject



37
38
39
40
# File 'lib/redix/logic.rb', line 37

def build_keys
  @u.listWidget.clear
  @u.listWidget.addItems(r.keys.sort)
end

.commandObject



78
79
80
81
82
83
84
# File 'lib/redix/logic.rb', line 78

def command
  comm = @u.lineEdit.text
  @u.lineEdit.clear
  puts "Exec #{comm}"
  res = eval("r.#{comm}")
  @u.textBrowser.setHtml(res)# += res
end

.connect_dialogObject



42
43
44
45
46
47
48
49
50
# File 'lib/redix/logic.rb', line 42

def connect_dialog
  c = ConnectDialog.new
  c.setupUi
  redis = "#{r.client.host}:#{r.client.port}/#{r.client.db}"
  redis = "#{r.client.password}@" + redis if r.client.password
  c.lineEdit.setText(redis)
  c.buttonBox.connect(SIGNAL('accepted()')) { reconnect(c.lineEdit.text) }
  c.show
end

.failure(f) ⇒ Object



23
24
25
# File 'lib/redix/logic.rb', line 23

def failure(f)
  @u.statusbar.showMessage(f)
end

.for(u) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/redix/logic.rb', line 60

def for(u)
  @u = u
  build_keys
  build_dbs
  u.actionConnect.connect(SIGNAL('triggered()')) { connect_dialog }
  u.actionReconnect.connect(SIGNAL('triggered()')) { reconnect }
  u.actionAbout.connect(SIGNAL('triggered()')) { about_dialog }
  u.actionQuit.connect(SIGNAL('triggered()'), App, SLOT('quit()'))

  # Qt::ListWidgetItem.new(u.listWidget)
  # Qt::ListWidgetItem.new(u.listWidget)
  # u.listWidget.item(0).text = "foo"
  u.listWidget.connect(SIGNAL('itemClicked(QListWidgetItem *)')) do |i|
    zoom(i)
  end
  u.lineEdit.connect(SIGNAL('returnPressed()')) { command }
end

.r(db = 0) ⇒ Object



8
9
10
11
12
# File 'lib/redix/logic.rb', line 8

def r(db = 0)
  @r ||= Redis.new(:db => db)
rescue
  failure("Can't find redis on localhost:6379")
end

.reconnect(db = @db) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/redix/logic.rb', line 14

def reconnect(db = @db)
  puts "Reconnecting to DB ##{db}"
  params = db =~ /\./ ? { :url => "redis://#{db}" } : { :db => db }
  @r = Redis.connect(params)
  build_keys
rescue
  failure("Failure connecting to #{params}")
end

.zoom(i) ⇒ Object



86
87
88
89
# File 'lib/redix/logic.rb', line 86

def zoom(i)
  key = i.text
  @u.tableView.model = DataModel.new.for(key)
end