cline 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Cline - CLI Line Notifier
2
2
 
3
+ ## **Important** Data schema has changed on version 0.2.3
4
+
5
+ Please try following commands:
6
+
7
+ In shell:
8
+
9
+ ~~~~
10
+ $ sqlite3 ~/.cline/cline.sqlite3
11
+ ~~~~
12
+
13
+ In sqlite3 prompt:
14
+ ~~~~
15
+ BEGIN TRANSACTION;
16
+ CREATE TABLE "tmp_notifications" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "message" text DEFAULT '' NOT NULL, "display_count" integer DEFAULT 0 NOT NULL, "notified_at" datetime NOT NULL);
17
+ INSERT INTO tmp_notifications SELECT id, message, display_count, time as notified_at FROM notifications;
18
+ DROP TABLE notifications;
19
+ ALTER TABLE tmp_notifications RENAME TO notifications;
20
+ COMMIT;
21
+ .q
22
+ ~~~~
23
+
3
24
  ## Installation
4
25
 
5
26
  ~~~~
@@ -7,6 +28,7 @@
7
28
  cline init
8
29
  echo "Cline.out_stream = Cline::OutStreams::WithGrowl.new($stdout)" > ~/.cline/config # growlnotify required
9
30
  echo "Cline.collectors << Cline::Collector::Feed" >> ~/.cline/config
31
+ echo "Cline.pool_size << 2000" >> ~/.cline/config
10
32
  curl http://foo.examle.com/url/to/opml.xml > ~/.cline/feeds.xml
11
33
 
12
34
  cline collect
@@ -47,7 +69,7 @@ example:
47
69
  class MyCollector
48
70
  def self.collect
49
71
  new.sources.each do |source|
50
- Cline::Notification.find_by_message(source.body) || Cline::Notification.create!(message: source.body, time: source.created_at)
72
+ Cline::Notification.find_by_message(source.body) || Cline::Notification.create!(message: source.body, notified_at: source.created_at)
51
73
  end
52
74
  end
53
75
 
@@ -21,6 +21,25 @@ Gem::Specification.new do |s|
21
21
  * `search` command is available.
22
22
  usage:
23
23
  $ cline search [keyword]
24
+
25
+ * Garbage collector is available.
26
+ Garbage collector will work after `cline collect`.
27
+ It requires Cline.pool_size.
28
+
29
+ example:
30
+ $ echo "Cline.pool_size = 2000" >> ~/.cline/config
31
+
32
+ * Data schema has changed!
33
+ Please try following commands:
34
+
35
+ $ sqlite3 ~/.cline/cline.sqlite3
36
+ > BEGIN TRANSACTION;
37
+ > CREATE TABLE "tmp_notifications" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "message" text DEFAULT '' NOT NULL, "display_count" integer DEFAULT 0 NOT NULL, "notified_at" datetime NOT NULL);
38
+ > INSERT INTO tmp_notifications SELECT id, message, display_count, time as notified_at FROM notifications;
39
+ > DROP TABLE notifications;
40
+ > ALTER TABLE tmp_notifications RENAME TO notifications;
41
+ > COMMIT;
42
+ > .q
24
43
  EOM
25
44
 
26
45
  #s.rubyforge_project = "cline"
@@ -43,6 +43,14 @@ module Cline
43
43
  @out_stream = stream
44
44
  end
45
45
 
46
+ def pool_size
47
+ @pool_size
48
+ end
49
+
50
+ def pool_size=(pool_size)
51
+ @pool_size = pool_size
52
+ end
53
+
46
54
  collectors = []
47
55
  define_method(:collectors) { collectors }
48
56
  end
@@ -3,12 +3,12 @@
3
3
  module Cline::Collectors
4
4
  class Base
5
5
  class << self
6
- def create_or_pass(message, time)
7
- message = message.encode(Encoding::UTF_8)
8
- time = parse_time_string_if_needed(time)
6
+ def create_or_pass(message, notified_at)
7
+ message = message.encode(Encoding::UTF_8)
8
+ notified_at = parse_time_string_if_needed(notified_at)
9
9
 
10
- Cline::Notification.instance_exec message, time do |message, time|
11
- create(message: message, time: time) unless find_by_message_and_time(message, time)
10
+ Cline::Notification.instance_exec message, notified_at do |message, notified_at|
11
+ create(message: message, notified_at: notified_at) unless find_by_message_and_notified_at(message, notified_at)
12
12
  end
13
13
  rescue ActiveRecord::StatementInvalid => e
14
14
  puts e.class, e.message
@@ -4,8 +4,8 @@ module Cline::Collectors
4
4
  class Github < Base
5
5
  class << self
6
6
  def collect
7
- new(login_name).activities.each do |message, time|
8
- create_or_pass message, time
7
+ new(login_name).activities.each do |message, notified_at|
8
+ create_or_pass message, notified_at
9
9
  end
10
10
  end
11
11
 
@@ -31,8 +31,11 @@ module Cline::Collectors
31
31
  events = JSON.parse(@api_url.read)
32
32
 
33
33
  events.map { |event|
34
- [extract_message(event), event['created_at']]
35
- }
34
+ message = extract_message(event)
35
+ next unless message
36
+
37
+ [message, event['created_at']]
38
+ }.compact
36
39
  end
37
40
 
38
41
  private
@@ -47,6 +47,8 @@ module Cline
47
47
  desc 'collect', 'Collect sources'
48
48
  def collect
49
49
  Cline.collectors.each &:collect
50
+
51
+ clean_obsoletes if Cline.pool_size
50
52
  end
51
53
 
52
54
  desc 'init', 'Init database'
@@ -54,7 +56,7 @@ module Cline
54
56
  ActiveRecord::Base.connection.create_table(:notifications) do |t|
55
57
  t.text :message, null: false, default: ''
56
58
  t.integer :display_count, null: false, default: 0
57
- t.datetime :time, null: false
59
+ t.datetime :notified_at, null: false
58
60
  end
59
61
  end
60
62
 
@@ -62,5 +64,11 @@ module Cline
62
64
  def version
63
65
  say "cline version #{Cline::VERSION}"
64
66
  end
67
+
68
+ private
69
+
70
+ def clean_obsoletes
71
+ Notification.clean Cline.pool_size
72
+ end
65
73
  end
66
74
  end
@@ -2,18 +2,20 @@
2
2
 
3
3
  module Cline
4
4
  class Notification < ActiveRecord::Base
5
- validate :time, presence: true
5
+ validate :notified_at, presence: true
6
6
  validate :message, presence: true, uniqueness: true
7
7
  validate :display_count, presence: true, numerically: true
8
8
 
9
9
  scope :by_keyword, ->(word) {
10
- where('message like ?', "%#{word}%").order('time DESC, display_count')
10
+ where('message like ?', "%#{word}%").order('notified_at DESC, display_count')
11
11
  }
12
12
 
13
13
  scope :earliest, ->(limit = 1, offset = 0) {
14
- order('display_count, time').limit(limit).offset(offset)
14
+ order_by_default_priority_for_display.order('notified_at ASC').limit(limit).offset(offset)
15
15
  }
16
16
 
17
+ scope :order_by_default_priority_for_display, order(:display_count)
18
+
17
19
  scope :displayed, where('display_count > 0')
18
20
 
19
21
  def message=(m)
@@ -28,6 +30,13 @@ module Cline
28
30
  def normalize_message(m)
29
31
  m.gsub(/[\r\n]/, '')
30
32
  end
33
+
34
+ def clean(pool_size)
35
+ order_by_default_priority_for_display.
36
+ order('notified_at DESC').
37
+ offset(pool_size).
38
+ destroy_all
39
+ end
31
40
  end
32
41
 
33
42
  def display
@@ -37,7 +46,7 @@ module Cline
37
46
  end
38
47
 
39
48
  def display_message
40
- "[#{time}][#{display_count}] #{message}"
49
+ "[#{notified_at}][#{display_count}] #{message}"
41
50
  end
42
51
  end
43
52
  end
@@ -1,3 +1,3 @@
1
1
  module Cline
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  Fabricator(:notification, class_name: Cline::Notification) do
4
4
  message { sequence(:message) {|i| "message ##{i}" } }
5
- time { Time.now }
5
+ notified_at { Time.now }
6
6
  end
@@ -4,9 +4,9 @@ require_relative '../spec_helper'
4
4
 
5
5
  describe Cline::Notification do
6
6
  describe '.ealiest' do
7
- let!(:notification1) { Fabricate(:notification, time: 2.days.ago.beginning_of_day, display_count: 3) }
8
- let!(:notification2) { Fabricate(:notification, time: 3.days.ago.beginning_of_day, display_count: 3) }
9
- let!(:notification3) { Fabricate(:notification, time: 3.days.ago.beginning_of_day, display_count: 2) }
7
+ let!(:notification1) { Fabricate(:notification, notified_at: 2.days.ago.beginning_of_day, display_count: 3) }
8
+ let!(:notification2) { Fabricate(:notification, notified_at: 3.days.ago.beginning_of_day, display_count: 3) }
9
+ let!(:notification3) { Fabricate(:notification, notified_at: 3.days.ago.beginning_of_day, display_count: 2) }
10
10
 
11
11
  context 'default(limit 1 offset 0)' do
12
12
  subject { Cline::Notification.earliest.all }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-15 00:00:00.000000000 Z
12
+ date: 2011-11-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
16
- requirement: &70110337366880 !ruby/object:Gem::Requirement
16
+ requirement: &70095226423100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.14.6
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70110337366880
24
+ version_requirements: *70095226423100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &70110337365820 !ruby/object:Gem::Requirement
27
+ requirement: &70095226422520 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70110337365820
35
+ version_requirements: *70095226422520
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70110337364900 !ruby/object:Gem::Requirement
38
+ requirement: &70095226421980 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70110337364900
46
+ version_requirements: *70095226421980
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: feedzirra
49
- requirement: &70110337364100 !ruby/object:Gem::Requirement
49
+ requirement: &70095226421500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.0.31
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70110337364100
57
+ version_requirements: *70095226421500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: notify
60
- requirement: &70110337363240 !ruby/object:Gem::Requirement
60
+ requirement: &70095226421020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.3.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *70110337363240
68
+ version_requirements: *70095226421020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
- requirement: &70110337361340 !ruby/object:Gem::Requirement
71
+ requirement: &70095226420540 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.2
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70110337361340
79
+ version_requirements: *70095226420540
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: ir_b
82
- requirement: &70110337375580 !ruby/object:Gem::Requirement
82
+ requirement: &70095226420040 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.4.0
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70110337375580
90
+ version_requirements: *70095226420040
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: tapp
93
- requirement: &70110337371540 !ruby/object:Gem::Requirement
93
+ requirement: &70095226419520 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 1.1.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70110337371540
101
+ version_requirements: *70095226419520
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: rspec
104
- requirement: &70110337385460 !ruby/object:Gem::Requirement
104
+ requirement: &70095226419040 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.6.0
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *70110337385460
112
+ version_requirements: *70095226419040
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: rr
115
- requirement: &70110337383800 !ruby/object:Gem::Requirement
115
+ requirement: &70095226408260 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.0.4
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *70110337383800
123
+ version_requirements: *70095226408260
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: fabrication
126
- requirement: &70110337382240 !ruby/object:Gem::Requirement
126
+ requirement: &70095226407420 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 1.2.0
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *70110337382240
134
+ version_requirements: *70095226407420
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: fuubar
137
- requirement: &70110337380260 !ruby/object:Gem::Requirement
137
+ requirement: &70095226406860 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,10 +142,10 @@ dependencies:
142
142
  version: 0.0.6
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *70110337380260
145
+ version_requirements: *70095226406860
146
146
  - !ruby/object:Gem::Dependency
147
147
  name: simplecov
148
- requirement: &70110337378360 !ruby/object:Gem::Requirement
148
+ requirement: &70095226406380 !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements:
151
151
  - - ! '>='
@@ -153,10 +153,10 @@ dependencies:
153
153
  version: 0.5.3
154
154
  type: :development
155
155
  prerelease: false
156
- version_requirements: *70110337378360
156
+ version_requirements: *70095226406380
157
157
  - !ruby/object:Gem::Dependency
158
158
  name: activesupport
159
- requirement: &70110337393440 !ruby/object:Gem::Requirement
159
+ requirement: &70095226405880 !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
162
162
  - - ! '>='
@@ -164,7 +164,7 @@ dependencies:
164
164
  version: 3.1.1
165
165
  type: :development
166
166
  prerelease: false
167
- version_requirements: *70110337393440
167
+ version_requirements: *70095226405880
168
168
  description: Cline - CLI Line Notifier
169
169
  email:
170
170
  - celluloid.key@gmail.com
@@ -215,7 +215,16 @@ post_install_message: ! " **Important** Some features were added.\n\n * Ne
215
215
  collector (GitHub News Feed) is available.\n $ echo \"Cline.collectors << Cline::Collectors::Github\"
216
216
  >> ~/.cline/config\n $ echo \"Cline::Collectors::Github.login_name = 'your_github_login'\"
217
217
  >> ~/.cline/config\n\n * `search` command is available.\n usage:\n $
218
- cline search [keyword]\n"
218
+ cline search [keyword]\n\n * Garbage collector is available.\n Garbage collector
219
+ will work after `cline collect`.\n It requires Cline.pool_size.\n\n example:\n
220
+ \ $ echo \"Cline.pool_size = 2000\" >> ~/.cline/config\n\n * Data schema
221
+ has changed!\n Please try following commands:\n\n $ sqlite3 ~/.cline/cline.sqlite3\n
222
+ \ > BEGIN TRANSACTION;\n > CREATE TABLE \"tmp_notifications\" (\"id\" INTEGER
223
+ PRIMARY KEY AUTOINCREMENT NOT NULL, \"message\" text DEFAULT '' NOT NULL, \"display_count\"
224
+ integer DEFAULT 0 NOT NULL, \"notified_at\" datetime NOT NULL);\n > INSERT
225
+ INTO tmp_notifications SELECT id, message, display_count, time as notified_at FROM
226
+ notifications;\n > DROP TABLE notifications;\n > ALTER TABLE tmp_notifications
227
+ RENAME TO notifications;\n > COMMIT;\n > .q\n"
219
228
  rdoc_options: []
220
229
  require_paths:
221
230
  - lib