artoo 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e3eeb439427b0af42baf98ca4785ae0c017a09e
4
- data.tar.gz: 8cdfdc43fca9a234b1d8b1c518b539ad8870265a
3
+ metadata.gz: 6059ccad349f757c75b1bba40c3258056bc690cb
4
+ data.tar.gz: ee353f9752cef6a52bd28129568e33bcebe318b1
5
5
  SHA512:
6
- metadata.gz: 046a09825eebba8e83d289f26c0a5efb8a3946685914dd97a4bf4149eaf77124cf2892150f2cb149d06ee0f69fe5c1ad056793274b889762a444711112157e19
7
- data.tar.gz: 72cac3523ba133f5d5fd72717bd7a61bf63efadf1fe4b26ad5b27653ce5ee5c2e752eee2c79bdc35851e75aa98873d0ffefcf668965a1ae7cd96cf359e06d2e4
6
+ metadata.gz: 59dff9b9afe24d635cdcb911a8a3422c0e08a2c5dcf470ae36d9a989dcbd0ed2e89dc4c0e9606ea7d24dcb5708a813da60fa6842d313dc638944c871f9882cc7
7
+ data.tar.gz: 6450d8ebc3ebe3c150ec1e0789c622395cd60a2ea34622fb21d23e4f042542686f34a1aa3e26b5a804741b8796c85858842fa53ca71b58ceda225f6123b9a91a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo (1.1.0)
4
+ artoo (1.1.1)
5
5
  celluloid (~> 0.15.0)
6
6
  celluloid-io (~> 0.15.0)
7
7
  multi_json (~> 1.6)
data/bin/robi CHANGED
@@ -12,26 +12,26 @@ command_set = Pry::CommandSet.new do
12
12
  output.puts "Starting robots..."
13
13
  end
14
14
 
15
- Celluloid::Actor[:master].start_work
15
+ Artoo::Master.start_work
16
16
  end
17
17
 
18
18
  block_command "pause", "Pause all robots" do
19
19
  output.puts "Pausing robots..."
20
- Celluloid::Actor[:master].pause_work
20
+ Artoo::Master.pause_work
21
21
  end
22
22
 
23
23
  block_command "continue", "Continue all robots" do
24
24
  output.puts "Continuing robots..."
25
- Celluloid::Actor[:master].continue_work
25
+ Artoo::Master.continue_work
26
26
  end
27
27
 
28
28
  block_command "stop", "Stop all robots" do
29
29
  output.puts "Stopping robots..."
30
- Celluloid::Actor[:master].stop_work
30
+ Artoo::Master.stop_work
31
31
  end
32
32
 
33
33
  block_command "list", "List all robots" do
34
- output.puts Celluloid::Actor[:master].robots
34
+ output.puts Artoo::Master.robots
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,30 @@
1
+ require 'artoo/robot'
2
+
3
+ class GreeterRobot < Artoo::Robot
4
+ work do
5
+ every(5.seconds) do
6
+ say 'Hola'
7
+ end
8
+ end
9
+
10
+ def say(greeting)
11
+ friend_name = "Number #{rand(5)}"
12
+ puts "Saying '#{greeting}' to #{friend_name}"
13
+ Artoo::Master.robot(friend_name).hello(greeting, current_instance)
14
+ end
15
+ end
16
+
17
+ class MessageRobot < Artoo::Robot
18
+ def hello(greeting, sender)
19
+ puts "'#{sender.name}' said '#{greeting}' to #{name}"
20
+ end
21
+ end
22
+
23
+ robots = []
24
+ 5.times do |i|
25
+ robots << MessageRobot.new(:name => "Number #{i}")
26
+ end
27
+
28
+ robots << GreeterRobot.new(:name => "Greeter")
29
+
30
+ Artoo::Robot.work!(robots)
@@ -0,0 +1,10 @@
1
+ require 'artoo/drivers/driver'
2
+
3
+ module Artoo
4
+ module Drivers
5
+ # DeviceInfo driver behaviors
6
+ class DeviceInfo < Driver
7
+ COMMANDS = [:firmware_name, :version, :connect].freeze
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Artoo
2
+ class RobotNotFound < StandardError; end # unable to find a robot by name in master
3
+ end
@@ -5,16 +5,60 @@ module Artoo
5
5
  include Celluloid
6
6
  attr_reader :robots
7
7
 
8
+ class << self
9
+ def current
10
+ Celluloid::Actor[:master] ||= self.new
11
+ end
12
+
13
+ def assign(bots=[])
14
+ current.assign(bots)
15
+ end
16
+
17
+ def robots
18
+ current.robots
19
+ end
20
+
21
+ def robot(name)
22
+ current.robot(name)
23
+ end
24
+
25
+ def start_work
26
+ current.start_work
27
+ end
28
+
29
+ def stop_work
30
+ current.stop_work
31
+ end
32
+
33
+ def pause_work
34
+ current.pause_work
35
+ end
36
+
37
+ def continue_work
38
+ current.continue_work
39
+ end
40
+ end
41
+
8
42
  # Create new master
9
43
  # @param [Collection] robots
10
- def initialize(bots)
11
- @robots = bots
44
+ def initialize(bots=[])
45
+ @robots = []
46
+ assign(bots)
47
+ end
48
+
49
+ # Assign robots to Master controller
50
+ # @param [Collection] robots
51
+ def assign(bots=[])
52
+ robots.concat(bots)
53
+ bots.each {|r| r.async.work} if Artoo::Robot.is_running?
12
54
  end
13
55
 
14
56
  # @param [String] name
15
57
  # @return [Robot] robot
16
58
  def robot(name)
17
- robots.find {|r| r.name == name}
59
+ r = robots.find {|r| r.name == name}
60
+ raise RobotNotFound if r.nil?
61
+ r
18
62
  end
19
63
 
20
64
  # @param [String] name
@@ -1,9 +1,8 @@
1
1
  require 'celluloid/autostart'
2
2
  require 'celluloid/io'
3
3
  require 'multi_json'
4
- require 'artoo/ext/timers'
5
- require 'artoo/ext/actor'
6
4
 
5
+ require 'artoo/ext/actor'
7
6
  require 'artoo/robot_class_methods'
8
7
  require 'artoo/basic'
9
8
  require 'artoo/connection'
@@ -11,6 +10,7 @@ require 'artoo/adaptors/adaptor'
11
10
  require 'artoo/device'
12
11
  require 'artoo/drivers/driver'
13
12
  require 'artoo/events'
13
+ require 'artoo/exceptions'
14
14
  require 'artoo/api/api'
15
15
  require 'artoo/master'
16
16
  require 'artoo/port'
@@ -89,7 +89,7 @@ module Artoo
89
89
 
90
90
  # @return [Collection] connection types
91
91
  def connection_types
92
- current_class.connection_types
92
+ current_class.connection_types ||= [{:name => :passthru}]
93
93
  end
94
94
 
95
95
  # @return [Collection] device types
@@ -58,17 +58,17 @@ module Artoo
58
58
  # or, a new instance can be created
59
59
  # @param [Robot] robot
60
60
  def work!(robot=nil)
61
+ prepare_work(robot)
61
62
  return if is_running?
62
- prepare_robots(robot)
63
63
 
64
64
  unless cli?
65
65
  begin
66
66
  start_api
67
- master.start_work
67
+ Artoo::Master.start_work
68
68
  begin_working
69
69
  rescue Interrupt
70
70
  Celluloid::Logger.info 'Shutting down...'
71
- master.stop_work if master
71
+ Artoo::Master.stop_work
72
72
  # Explicitly exit so busy Processor threads can't block
73
73
  # process shutdown... taken from Sidekiq, thanks!
74
74
  exit(0)
@@ -77,7 +77,7 @@ module Artoo
77
77
  end
78
78
 
79
79
  # Prepare master robots for work
80
- def prepare_robots(robot=nil)
80
+ def prepare_work(robot=nil)
81
81
  if robot.respond_to?(:work)
82
82
  robots = [robot]
83
83
  elsif robot.kind_of?(Array)
@@ -86,7 +86,7 @@ module Artoo
86
86
  robots = [self.new]
87
87
  end
88
88
 
89
- Celluloid::Actor[:master] = Master.new(robots)
89
+ Artoo::Master.assign(robots)
90
90
  end
91
91
 
92
92
  def begin_working
@@ -112,11 +112,6 @@ module Artoo
112
112
  Celluloid::Actor[:api] = Api::Server.new(self.api_host, self.api_port) if self.use_api
113
113
  end
114
114
 
115
- # Master actor
116
- def master
117
- Celluloid::Actor[:master]
118
- end
119
-
120
115
  # @return [Boolean] True if test env
121
116
  def test?
122
117
  ENV["ARTOO_TEST"] == 'true'
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  unless const_defined?('VERSION')
3
- VERSION = "1.1.0"
3
+ VERSION = "1.1.1"
4
4
  end
5
5
  end
@@ -35,6 +35,10 @@ describe Artoo::Master do
35
35
  @master.robot("robot2").must_equal @robot2
36
36
  end
37
37
 
38
+ it 'Artoo::Master#robot with invalid robot name' do
39
+ proc {@master.robot("robotno")}.must_raise(Artoo::RobotNotFound)
40
+ end
41
+
38
42
  it 'Artoo::Master#robot_devices' do
39
43
  @master.robot_devices("robot2").first.must_equal "robot2-device1"
40
44
  end
@@ -69,19 +69,22 @@ describe Artoo::Robot do
69
69
  TestRobot.stubs(:begin_working)
70
70
  @master = mock('master')
71
71
  @master.expects(:start_work)
72
- TestRobot.stubs(:master).returns(@master)
72
+ Artoo::Master.stubs(:current).returns(@master)
73
73
  end
74
74
 
75
75
  it 'Artoo::Robot.work! with single object' do
76
+ @master.expects(:assign).with([@robot])
76
77
  TestRobot.work!(@robot)
77
78
  end
78
79
 
79
80
  it 'Artoo::Robot.work! with array of objects' do
80
81
  @robot2 = TestRobot.new(:name => "too", :connections => {:test_connection => {:port => '1234'}})
82
+ @master.expects(:assign).with([@robot, @robot2])
81
83
  TestRobot.work!([@robot, @robot2])
82
84
  end
83
85
 
84
86
  it 'Artoo::Robot.work! without object' do
87
+ @master.expects(:assign)
85
88
  TestRobot.work!
86
89
  end
87
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ron Evans
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2013-09-05 00:00:00.000000000 Z
15
+ date: 2013-09-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: celluloid
@@ -181,6 +181,7 @@ files:
181
181
  - examples/hello.rb
182
182
  - examples/hello_api.rb
183
183
  - examples/hello_api_multiple.rb
184
+ - examples/hello_messages.rb
184
185
  - examples/hello_modular.rb
185
186
  - examples/hello_multiple.rb
186
187
  - examples/notifications.rb
@@ -212,14 +213,15 @@ files:
212
213
  - lib/artoo/delegator.rb
213
214
  - lib/artoo/device.rb
214
215
  - lib/artoo/drivers/counter.rb
216
+ - lib/artoo/drivers/device_info.rb
215
217
  - lib/artoo/drivers/driver.rb
216
218
  - lib/artoo/drivers/passthru.rb
217
219
  - lib/artoo/drivers/pinger.rb
218
220
  - lib/artoo/drivers/random.rb
219
221
  - lib/artoo/drivers/test.rb
220
222
  - lib/artoo/events.rb
223
+ - lib/artoo/exceptions.rb
221
224
  - lib/artoo/ext/actor.rb
222
- - lib/artoo/ext/timers.rb
223
225
  - lib/artoo/generators/adaptor.rb
224
226
  - lib/artoo/generators/adaptor/Gemfile.tt
225
227
  - lib/artoo/generators/adaptor/LICENSE
@@ -1,41 +0,0 @@
1
- # Monkeypatches for Timers & Timer classes used by Celluloid
2
- class Timers
3
- def initialize
4
- @timers = SortedSet.new
5
- @paused_timers = SortedSet.new
6
- end
7
-
8
- def pause(timer = nil)
9
- return pause_all if timer.nil?
10
- raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer
11
- @timers.delete timer
12
- @paused_timers.add timer
13
- end
14
-
15
- def pause_all
16
- @timers.each {|timer| timer.pause}
17
- end
18
-
19
- def continue(timer = nil)
20
- return continue_all if timer.nil?
21
- raise TypeError, "not a Timers::Timer" unless timer.is_a? Timers::Timer
22
- @paused_timers.delete timer
23
- @timers.add timer
24
- end
25
-
26
- def continue_all
27
- @paused_timers.each {|timer| timer.continue}
28
- end
29
-
30
- class Timer
31
- # Pause this timer
32
- def pause
33
- @timers.pause self
34
- end
35
-
36
- # Continue this timer
37
- def continue
38
- @timers.continue self
39
- end
40
- end
41
- end