talks 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,4 +8,5 @@ rvm:
8
8
  - rbx-18mode
9
9
  - rbx-19mode
10
10
  # uncomment this line if your project needs to run something other than `rake`:
11
- script: rake
11
+ before_script: touch espeak && chmod a+x espeak && PATH=$PATH:$(pwd)
12
+ script: rake
@@ -1,5 +1,14 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.4.0
4
+
5
+ * Added options for Talks#say: :notify, :detach (@kossnocorp)
6
+ * Talks#notify more smart - get options for notifier (title, image, etc) (@kossnocorp)
7
+
8
+ ## 0.3.0
9
+
10
+ * Added notifier support (thanks to @kossnocorp)
11
+
3
12
  ## 0.2.0
4
13
 
5
14
  * Added espeak support
data/README.md CHANGED
@@ -15,6 +15,10 @@ I added in all sections of this readme notes about usage notifier
15
15
  functionality. And small
16
16
  [readme](https://github.com/ruby-talks/talks#using-talks-with-growl) about usage with Growl notifier.
17
17
 
18
+ ### Here is a small [screencast](http://www.youtube.com/watch?v=PaUpwQMBvOY) about talks
19
+
20
+ Soon we will finish the [wiki](https://github.com/ruby-talks/talks/wiki) and it will be (I hope) delimited and clear for understand.
21
+
18
22
  Sponsored by Evil Martians <http://evilmartians.com>
19
23
 
20
24
  ## Why?
@@ -185,7 +189,7 @@ Talks.voices[:espeak]
185
189
 
186
190
  For [Growl](http://growl.info) you should be a Mac user. And you should have Growl version >= 1.3.
187
191
 
188
- If it's or for you - you need to do several steps for using talks with Growl:
192
+ If it's ok for you - you need to do several steps for using talks with Growl:
189
193
 
190
194
  * Install the [growlnotify](http://growl.cachefly.net/GrowlNotify-1.3.zip) script
191
195
 
@@ -199,9 +203,11 @@ If it's or for you - you need to do several steps for using talks with Growl:
199
203
  Now you can use talks with Growl support:
200
204
 
201
205
  ```bash
202
- $: talking -bn 'This is before notification wich will shown with growl'
206
+ $: talking -bn 'This is before notification wich will shown with growl' ls -la
203
207
  ```
204
208
 
209
+ Here is the [screenshot](http://cl.ly/0K3V2F0A1C3O2z1q0923).
210
+
205
211
  ## Who?
206
212
 
207
213
  I did it myself.
@@ -28,20 +28,34 @@ module Talks
28
28
  VOICES
29
29
  end
30
30
 
31
+ def engine
32
+ config.engine
33
+ end
34
+
31
35
  def say(message, options = {})
36
+ abort "Undefined engine: #{engine}" unless ["say","espeak"].include? engine
32
37
  type = options[:type] || :default
33
- case config.engine
34
- when 'say'
35
- `say -v #{say_voice(type, options)} '#{message}'`
36
- when 'espeak'
37
- `espeak -v #{say_voice(type, options)} '#{message}'`
38
- else
39
- abort "Undefined engine: #{config.engine}"
40
- end
38
+
39
+ notify(message) if options[:notify] || config.notify_by_default
40
+
41
+ command = [engine, '-v', say_voice(type, options), "#{message}"]
42
+ command << '&' if options[:detach] || config.detach
43
+
44
+ system command.join(' ')
41
45
  end
42
46
 
43
47
  def notify(message, options = {})
44
- Notifier.notify message: message, title: 'Talks', image: ''
48
+ opts = \
49
+ {
50
+ :message => message,
51
+ :title => 'Talks',
52
+ :image => ''
53
+ }
54
+
55
+ opts.merge! config.notifier_options if config.notifier_options
56
+ opts.merge!(options)
57
+
58
+ Notifier.notify opts
45
59
  end
46
60
 
47
61
  def execute(command)
@@ -56,16 +70,18 @@ module Talks
56
70
  end
57
71
 
58
72
  TYPES.each do |type|
59
- define_method type do |message = nil, options = {type: type}|
60
- message ||= config.message(type)
61
- say(message, options)
62
- end
73
+ module_eval <<-RUBY_EVAL,__FILE__,__LINE__ + 1
74
+ def #{type}(message = nil, options = {:type => :#{type}})
75
+ message ||= config.message(:#{type})
76
+ say(message, options)
77
+ end
78
+ RUBY_EVAL
63
79
  end
64
80
 
65
81
  private
66
82
 
67
83
  def say_voice(type, options)
68
- if options[:voice] and VOICES[config.engine.to_sym].include?(options[:voice].to_s)
84
+ if options[:voice] and VOICES[engine.to_sym].include?(options[:voice].to_s)
69
85
  options[:voice]
70
86
  elsif TYPES.include? type
71
87
  config.voice type
@@ -25,11 +25,15 @@ module Talks
25
25
  :error => 'Error'
26
26
  }
27
27
 
28
- attr_accessor :voices, :messages, :default_voice, :options, :engine, :notifier
28
+ attr_accessor :voices, :messages, :default_voice, :options, :engine, :notifier,
29
+ :notifier_options, :detach, :notify_by_default
29
30
 
30
31
  def initialize(opts)
31
32
  @options = symbolize_hash_keys(opts)
32
33
  @engine = options[:engine] || default_engine_for_os
34
+ @notifier_options = options[:notifier_options] || {}
35
+ @detach = options[:detach]
36
+ @notify_by_default = options[:notify_by_default]
33
37
  @default_voice = options[:default_voice] || default_voice_for(engine)
34
38
  @voices = options[:voices] && DEFAULT_VOICES[engine.to_sym].merge(options[:voices]) ||
35
39
  DEFAULT_VOICES[engine.to_sym]
@@ -2,15 +2,15 @@ module Talks
2
2
  module Hooks
3
3
  class << self
4
4
 
5
+
5
6
  def create(args)
6
- engine = Talks.config.engine
7
7
  options, args = shift_options(args.dup)
8
8
  command_name = command args
9
9
  voice, before_message, after_message, before_notify, after_notify = \
10
10
  parse options, command_name
11
11
 
12
- before_hook = hook(engine, voice, before_message)
13
- after_hook = hook(engine, voice, after_message)
12
+ before_hook = hook(voice, before_message)
13
+ after_hook = hook(voice, after_message)
14
14
  command = args.join(' ')
15
15
 
16
16
  [before_notify, [before_hook, command, after_hook].join('; '), after_notify]
@@ -18,6 +18,10 @@ module Talks
18
18
 
19
19
  private
20
20
 
21
+ def engine
22
+ Talks.config.engine
23
+ end
24
+
21
25
  def shift_options(args, options={})
22
26
  # Check arguments for talks
23
27
  # one-two dashed. -v or --voice
@@ -68,7 +72,7 @@ module Talks
68
72
  [voice, before_message, after_message, before_notify, after_notify]
69
73
  end
70
74
 
71
- def hook(engine, voice, message)
75
+ def hook(voice, message)
72
76
  "#{engine} -v #{voice} '#{message}'"
73
77
  end
74
78
 
@@ -1,3 +1,3 @@
1
1
  module Talks
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4.0'
3
3
  end
@@ -12,7 +12,7 @@ describe Talks do
12
12
 
13
13
  it 'should have default methods' do
14
14
  [:add_hooks, :info, :error, :success, :warn, :say, :config].each do |method|
15
- Talks.methods.include?(method).should be_true
15
+ Talks.instance_methods.map(&:to_s).include?(method.to_s).should be_true
16
16
  end
17
17
  end
18
18
 
@@ -59,26 +59,62 @@ describe Talks do
59
59
  context 'hooks' do
60
60
 
61
61
  it 'should create hooks for any command by default' do
62
- Talks.add_hooks(['ls']).should == "#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'ls task ended'"
62
+ Talks.add_hooks(['ls']).should == ["ls task started","#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'ls task ended'","ls task ended"]
63
63
  end
64
64
 
65
65
  it 'should create preconfigured hooks for command from .talksrc' do
66
- Talks.add_hooks(['bundle']).should == "#{talk_command} -v bad 'Bundle before message'; bundle; #{talk_command} -v bad 'Bundle after message'"
66
+ Talks.add_hooks(['bundle']).should == ["bundle task started","#{talk_command} -v bad 'Bundle before message'; bundle; #{talk_command} -v bad 'Bundle after message'","bundle task ended"]
67
67
  end
68
68
 
69
69
  it 'should change voice if option sended' do
70
- Talks.add_hooks(['-v', 'vicki', 'ls']).should == "#{talk_command} -v vicki 'ls task started'; ls; #{talk_command} -v vicki 'ls task ended'"
70
+ Talks.add_hooks(['-v', 'vicki', 'ls']).should == ["ls task started","#{talk_command} -v vicki 'ls task started'; ls; #{talk_command} -v vicki 'ls task ended'","ls task ended"]
71
71
  end
72
72
 
73
73
  it 'should change messages if option sended' do
74
- Talks.add_hooks(['-bm', 'test', 'ls']).should == "#{talk_command} -v agnes 'test'; ls; #{talk_command} -v agnes 'ls task ended'"
75
- Talks.add_hooks(['-am', 'test', 'ls']).should == "#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'test'"
74
+ Talks.add_hooks(['-bm', 'test', 'ls']).should == ["ls task started","#{talk_command} -v agnes 'test'; ls; #{talk_command} -v agnes 'ls task ended'","ls task ended"]
75
+ Talks.add_hooks(['-am', 'test', 'ls']).should == ["ls task started","#{talk_command} -v agnes 'ls task started'; ls; #{talk_command} -v agnes 'test'","ls task ended"]
76
76
  end
77
77
 
78
78
  it 'should create hooks for command inside `bundle exec` by default' do
79
- Talks.add_hooks(['bundle', 'exec', 'ls']).should == "#{talk_command} -v agnes 'ls task started'; bundle exec ls; #{talk_command} -v agnes 'ls task ended'"
79
+ Talks.add_hooks(['bundle', 'exec', 'ls']).should == ["ls task started","#{talk_command} -v agnes 'ls task started'; bundle exec ls; #{talk_command} -v agnes 'ls task ended'","ls task ended"]
80
80
  end
81
81
 
82
82
  end
83
83
 
84
+ describe "#say" do
85
+ it "should execute command with single quotes" do
86
+ Talks.should_receive(:system)
87
+ Talks.say "I'm talking like a boss"
88
+ end
89
+
90
+ it 'should show notification if :notify => true option passed' do
91
+ Talks.stub(:system)
92
+ Talks.should_receive(:notify).with('Hello there!')
93
+ Talks.say 'Hello there!', :notify => true
94
+ end
95
+
96
+ it 'should not detach say process if detach: false option passed' do
97
+ Talks.config.detach = nil
98
+ Talks.should_receive(:system).with(/!$/)
99
+ Talks.say 'Hello there!'
100
+ end
101
+
102
+ it 'should detach say process if :detach => true option passed' do
103
+ Talks.should_receive(:system).with(/\s&$/)
104
+ Talks.say 'Hello there!', :detach => true
105
+ end
106
+ end
107
+
108
+ describe '#notify' do
109
+ it 'should show growl notification with default title' do
110
+ Notifier.should_receive('notify').with({ :message => 'Hello there!' }.merge Talks.config.notifier_options)
111
+ Talks.notify 'Hello there!'
112
+ end
113
+
114
+ it 'should use passed options' do
115
+ Notifier.should_receive('notify').with(:message => 'Hello there!', :title => 'Hello?', :image => 'icon.ico')
116
+ Talks.notify 'Hello there!', :title => 'Hello?', :image => 'icon.ico'
117
+ end
118
+ end
119
+
84
120
  end
@@ -1,4 +1,9 @@
1
1
  default_voice: 'agnes'
2
+ notify_by_default: true
3
+ notifier_options:
4
+ title: 'Something'
5
+ image: 'icon.png'
6
+ detach: true
2
7
  bundle:
3
8
  voice: 'bad'
4
9
  before_message: 'Bundle before message'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-19 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: notifier