earthquake 0.2.5 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -59,6 +59,11 @@ The blue is excluded.
59
59
 
60
60
  デバッグモードで動作しているとき、コードの修正は即座に反映される(正確にはコマンドの実行の直前にリロードされる)。
61
61
 
62
+ ### Defining Plugin
63
+
64
+ "~/.earthquake/plugin" is the directory for plugins.
65
+ At launch, Earthquake try to load files under the directory.
66
+
62
67
  ### Defining your commands
63
68
 
64
69
  #### A command named 'foo':
@@ -90,7 +95,18 @@ The 'm' is a MatchData.
90
95
 
91
96
  ### Handling outputs
92
97
 
93
- #### Favorites notifier:
98
+ #### Keyword notifier:
99
+
100
+ Earthquake.init do
101
+ output do |item|
102
+ next unless item["stream"]
103
+ if item["text"] =~ /ruby/i
104
+ notify "#{item["user"]["screen_name"]}: #{item["text"]}"
105
+ end
106
+ end
107
+ end
108
+
109
+ #### Favorite notifier:
94
110
 
95
111
  Earthquake.init do
96
112
  output do |item|
@@ -101,11 +117,23 @@ The 'm' is a MatchData.
101
117
  end
102
118
  end
103
119
 
120
+ ### Defining filters
121
+
122
+ #### Filtering by keywords
123
+
124
+ Earthquake.init do
125
+ filter do |item|
126
+ if item["stream"] && item["text"]
127
+ item["text"] =~ /ruby/i
128
+ else
129
+ true
130
+ end
131
+ end
132
+ end
133
+
104
134
  TODO
105
135
  ----
106
136
 
107
- * filter
108
- * plugin system
109
137
  * keyword tracking
110
138
  * more intelligent completion
111
139
  * spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.3.0
data/earthquake.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{earthquake}
8
- s.version = "0.2.5"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["jugyo"]
@@ -1,4 +1,6 @@
1
1
  # encoding: UTF-8
2
+ require 'fileutils'
3
+
2
4
  module Earthquake
3
5
  module Core
4
6
  attr_accessor :config
@@ -17,6 +19,7 @@ module Earthquake
17
19
 
18
20
  def _init
19
21
  load_config
22
+ load_plugins
20
23
  inits.each { |block| class_eval(&block) }
21
24
  inits.clear
22
25
  end
@@ -32,13 +35,15 @@ module Earthquake
32
35
  # TODO: parse argv
33
36
  self.config = {
34
37
  :dir => File.expand_path('~/.earthquake'),
35
- :consumer_key => 'qOdgatiUm6HIRcdoGVqaZg',
36
- :consumer_secret => 'DHcL0bmS02vjSMHMrbFxCQqbDxh8yJZuLuzKviyFMo'
38
+ :plugin_dir => File.expand_path('~/.earthquake/plugin'),
39
+ :consumer_key => 'elraaTkvu5Zv6pOitFxyAA',
40
+ :consumer_secret => '9DlzIvTc7rZ9fQ13NGHQdrqfuAJf9XyoWKrhSnLx0'
37
41
  }
38
42
 
39
- unless File.exists?(config[:dir])
40
- require 'fileutils'
41
- FileUtils.mkdir_p(config[:dir])
43
+ [config[:dir], config[:plugin_dir]].each do |dir|
44
+ unless File.exists?(dir)
45
+ FileUtils.mkdir_p(dir)
46
+ end
42
47
  end
43
48
 
44
49
  config[:file] ||= File.join(config[:dir], 'config')
@@ -52,6 +57,16 @@ module Earthquake
52
57
  get_access_token unless self.config[:token] && self.config[:secret]
53
58
  end
54
59
 
60
+ def load_plugins
61
+ Dir[File.join(config[:plugin_dir], '*.rb')].each do |lib|
62
+ begin
63
+ require_dependency lib
64
+ rescue Exception => e
65
+ puts "<on_red>[ERROR] #{e.message.e}\n#{e.backtrace.join("\n").e}</on_red>".t
66
+ end
67
+ end
68
+ end
69
+
55
70
  def start(*argv)
56
71
  _init
57
72
  restore_history
@@ -139,8 +154,8 @@ module Earthquake
139
154
  end
140
155
  end
141
156
 
142
- def notify(message)
143
- Notify.notify 'earthquake', message
157
+ def notify(message, options = {:title => 'earthquake'})
158
+ Notify.notify options[:title], message
144
159
  end
145
160
  end
146
161
 
@@ -1,6 +1,14 @@
1
1
  # encoding: UTF-8
2
2
  module Earthquake
3
3
  module Output
4
+ def filters
5
+ @filters ||= []
6
+ end
7
+
8
+ def filter(&block)
9
+ filters << block
10
+ end
11
+
4
12
  def outputs
5
13
  @outputs ||= []
6
14
  end
@@ -12,8 +20,8 @@ module Earthquake
12
20
  return if item_queue.empty?
13
21
  insert do
14
22
  while item = item_queue.shift
15
- item["hide_timestamp"] = true
16
- puts_items(item)
23
+ item["stream"] = true
24
+ puts_items(item) if filters.all? { |filter| filter.call(item) }
17
25
  end
18
26
  end
19
27
  end
@@ -69,7 +77,7 @@ module Earthquake
69
77
  end
70
78
 
71
79
  statuses = ["[#{item["id"].to_s}]"]
72
- unless item["hide_timestamp"]
80
+ unless item["stream"]
73
81
  statuses.insert(0, "[#{Time.parse(item["created_at"]).strftime('%Y.%m.%d %X')}]")
74
82
  end
75
83
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earthquake
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.5
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - jugyo