Class: Cline::Command
- Inherits:
-
Thor
- Object
- Thor
- Cline::Command
- Defined in:
- lib/cline/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collect ⇒ Object
- #init ⇒ Object
- #open(alias_string = options[:hint]) ⇒ Object
- #recent(limit = options[:limit] || 10) ⇒ Object
- #search(keyword = optoins[:query]) ⇒ Object
- #server(command = :start) ⇒ Object
- #show(offset = options[:offset] || 0) ⇒ Object
- #status ⇒ Object
- #tick(interval = options[:interval] || 5, offset = options[:offset] || 0) ⇒ Object
- #version ⇒ Object
Class Method Details
Instance Method Details
#collect ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/cline/command.rb', line 91 def collect pid = Process.fork { Cline.collectors.each &:collect Notification.clean(Cline.notifications_limit) if Cline.notifications_limit } Process.waitpid pid end |
#init ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/cline/command.rb', line 102 def init Cline.establish_database_connection ActiveRecord::Base.connection.create_table(:notifications) do |t| t.text :message, null: false, default: '' t.integer :display_count, null: false, default: 0 t.datetime :notified_at, null: false end end |
#open(alias_string = options[:hint]) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/cline/command.rb', line 70 def open(alias_string = [:hint]) require 'launchy' notification = Notification.by_alias_string(alias_string).last if notification && url = notification.detect_url Launchy.open url else say 'No URL found', :red end end |
#recent(limit = options[:limit] || 10) ⇒ Object
114 115 116 117 118 |
# File 'lib/cline/command.rb', line 114 def recent(limit = [:limit] || 10) Notification.recent_notified.limit(limit).each do |notification| puts notification. end end |
#search(keyword = optoins[:query]) ⇒ Object
62 63 64 65 66 |
# File 'lib/cline/command.rb', line 62 def search(keyword = optoins[:query]) Notification.by_keyword(keyword).each do |notification| puts notification. end end |
#server(command = :start) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/cline/command.rb', line 126 def server(command = :start) case command.intern when :start puts 'starting cline server' Server.start when :stop puts 'stopping cline server' Server.stop when :reload puts 'reloading configuration' Cline.tap do |c| c.load_config_if_exists c.load_default_config end when :status if Server.running? puts "Socket file exists" puts "But server isn't responding" if Server.client_process? else puts "Server isn't running" end else puts 'Usage: cline server (start|stop)' end end |
#show(offset = options[:offset] || 0) ⇒ Object
46 47 48 |
# File 'lib/cline/command.rb', line 46 def show(offset = [:offset] || 0) notify Notification.display!(offset) end |
#status ⇒ Object
83 84 85 86 87 88 |
# File 'lib/cline/command.rb', line 83 def status puts "displayed : #{Notification.displayed.count}" puts "total : #{Notification.count}" server :status end |
#tick(interval = options[:interval] || 5, offset = options[:offset] || 0) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/cline/command.rb', line 52 def tick(interval = [:interval] || 5, offset = [:offset] || 0) loop do show offset sleep Integer(interval) end end |