Class: Redix::Logic
- Inherits:
-
Qt::Object
- Object
- Qt::Object
- Redix::Logic
- Defined in:
- lib/redix/logic.rb
Overview
/
Class Method Summary collapse
- .build_dbs ⇒ Object
- .build_keys ⇒ Object
- .command ⇒ Object
- .connect ⇒ Object
- .create_key(k, type = nil, v = nil) ⇒ Object
- .failure(f) ⇒ Object (also: message)
- .for(u) ⇒ Object
- .help ⇒ Object
- .new_key ⇒ Object
- .r(db = 0) ⇒ Object
- .reconnect(db = @db) ⇒ Object
- .zoom(i) ⇒ Object
Class Method Details
.build_dbs ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/redix/logic.rb', line 29 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..addAction(a) a.text = Qt::Application.translate("MainWindow", "##{i}", nil, Qt::Application::UnicodeUTF8) end end |
.build_keys ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/redix/logic.rb', line 39 def build_keys all = r.keys.sort @u.listWidget.clear @u.listWidget.addItems(all) puts r.info "DB Loaded #{all.size} keys. Used memory #{r.info['used_memory_human']}" rescue failure "Could not conect to redis" end |
.command ⇒ Object
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/redix/logic.rb', line 108 def command comm = @u.lineEdit.text @u.lineEdit.clear puts "Exec #{comm}" res = eval("r.#{comm}") rescue "FAIL" @u.textBrowser.setHtml("=> #{res}")# += res rescue Exception => e @u.textBrowser.setHtml e.to_s end |
.connect ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/redix/logic.rb', line 49 def connect 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..connect(SIGNAL('accepted()')) { reconnect(c.lineEdit.text) } c.show end |
.create_key(k, type = nil, v = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/redix/logic.rb', line 74 def create_key(k, type = nil, v = nil) unless type type = k.input_type.current_text v = k.input_value.text k = k.input_name.text end case type when 'string' then r.set(k, v) when 'hash' then r.hmset(k, v) when 'list' then r.add(k, v) when 'set' then r.sadd(k, v) end end |
.failure(f) ⇒ Object Also known as: message
24 25 26 |
# File 'lib/redix/logic.rb', line 24 def failure(f) @u..showMessage(f) end |
.for(u) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/redix/logic.rb', line 89 def for(u) @u = u build_keys build_dbs u.actionNew.connect(SIGNAL('triggered()')) { new_key } u.actionConnect.connect(SIGNAL('triggered()')) { connect } u.actionReconnect.connect(SIGNAL('triggered()')) { reconnect } u.actionAbout.connect(SIGNAL('triggered()')) { help } 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 |
.help ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/redix/logic.rb', line 59 def help a = AboutDialog.new a.setupUi # a.title.setText("RediX") a.textBrowser.setHtml("About <a href='http://github.com/nofxx/redix'>Redix</a><p>Marcos Piccinini</p>") a.show end |
.new_key ⇒ Object
67 68 69 70 71 72 |
# File 'lib/redix/logic.rb', line 67 def new_key k = NewKeyDialog.new k.setupUi k..connect(SIGNAL('accepted()')) { create_key(k) } k.show end |
.r(db = 0) ⇒ Object
9 10 11 12 13 |
# File 'lib/redix/logic.rb', line 9 def r(db = 0) @r ||= Redis.new(:db => db) rescue failure("Can't find redis on localhost:6379") end |
.reconnect(db = @db) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/redix/logic.rb', line 15 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 |