Class: Cline::Command

Inherits:
Thor
  • Object
show all
Defined in:
lib/cline/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.startObject



7
8
9
10
# File 'lib/cline/command.rb', line 7

def self.start(*)
  Cline.boot
  super
end

Instance Method Details

#collectObject



62
63
64
65
66
# File 'lib/cline/command.rb', line 62

def collect
  Cline.collectors.each &:collect

  clean_obsoletes
end

#initObject



69
70
71
72
73
74
75
# File 'lib/cline/command.rb', line 69

def init
  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



45
46
47
48
49
50
51
52
53
# File 'lib/cline/command.rb', line 45

def open(alias_string = options[:hint])
  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] || 1) ⇒ Object



79
80
81
82
83
# File 'lib/cline/command.rb', line 79

def recent(limit = options[:limit] || 1)
  Notification.recent_notified.limit(limit).each do |notification|
    say notification.display_message
  end
end

#search(keyword = optoins[:query]) ⇒ Object



37
38
39
40
41
# File 'lib/cline/command.rb', line 37

def search(keyword = optoins[:query])
  Notification.by_keyword(keyword).each do |notification|
    say notification.display_message
  end
end

#show(offset = options[:offset] || 0) ⇒ Object



22
23
24
# File 'lib/cline/command.rb', line 22

def show(offset = options[:offset] || 0)
  Notification.display offset
end

#statusObject



56
57
58
59
# File 'lib/cline/command.rb', line 56

def status
  say "displayed : #{Notification.displayed.count}", :green
  say "total     : #{Notification.count}", :cyan
end

#tick(offset = options[:offset] || 0, interval = options[:interval] || 60) ⇒ Object



28
29
30
31
32
33
# File 'lib/cline/command.rb', line 28

def tick(offset = options[:offset] || 0, interval = options[:interval] || 60)
  loop do
    show offset
    sleep interval.to_i
  end
end

#versionObject



86
87
88
# File 'lib/cline/command.rb', line 86

def version
  say "cline version #{Cline::VERSION}"
end