Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Still a lot of changes, getting there
- Loading branch information
Showing
13 changed files
with
331 additions
and
316 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
module Notify | ||
@debug = nil | ||
class<<self | ||
# force Notification to show up in stack backtraces of delegated methods | ||
attr_accessor :debug | ||
end | ||
|
||
def notify(name) | ||
n = name.to_s | ||
listeners = "@notify_#{n}_listeners" | ||
module_eval(<<-EOS, '(__NOTIFICATION__)', 1) | ||
#{listeners} = nil | ||
def notify(*names) | ||
names.each do |name| | ||
n = name.to_s | ||
listeners = "@notify_#{n}_listeners" | ||
module_eval <<-EOS | ||
#{listeners} = nil | ||
def notify_#{n} | ||
exceptions = nil | ||
if #{listeners} | ||
#{listeners}.each do |l| | ||
begin | ||
|l| l.call | ||
rescue Exception => ex | ||
$@.delete_if{|s| /^\\(__NOTIFICATION__\\):/ =~ s} unless Notification::debug | ||
exceptions ||= [] | ||
exceptions << ex | ||
def notify_#{n}(*args) | ||
errors = nil | ||
if #{listeners} | ||
#{listeners}.each do |l| | ||
begin | ||
l.call(*args) | ||
rescue Exception => ex | ||
errors ||= [] | ||
errors << ex | ||
end | ||
end | ||
if errors && respond_to?(:handle_notify_error) | ||
handle_notify_error(errors) | ||
end | ||
end | ||
if exceptions && respond_to? :handle_notify_exception | ||
handle_notify_exception(exceptions) | ||
end | ||
end | ||
end | ||
def on_#{n}(&proc) | ||
#{listeners} ||= [] | ||
#{listeners} << proc | ||
end | ||
private :notify_#{n} | ||
EOS | ||
def on_#{n}(&proc) | ||
#{listeners} ||= [] | ||
#{listeners} << proc | ||
end | ||
EOS | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
include 'ruby_plc/sequences/step_base' | ||
|
||
module RubyPlc | ||
module Sequences | ||
class ChooseOne | ||
include StepBase | ||
|
||
attr_reader :name | ||
|
||
def initialize(name = nil) | ||
init_step_listeners | ||
@name = name | ||
@idle_step = Step.new | ||
@end_step = Step.new {|s| s.on_exit continue! } | ||
@steps = [@idle_step, @end_step] | ||
yield self if block_given? | ||
end | ||
|
||
def branch(condition, step = nil) | ||
s = to_step(step) || Sequence.new | ||
@idle_step.continue_if condition, s | ||
s.default_next_step = @end_step | ||
@steps << s | ||
yield s if block_given? | ||
end | ||
|
||
def otherwise(step) | ||
s = to_step(step) || Sequence.new | ||
@idle_step.otherwise_to s | ||
s.default_next_step = @end_step | ||
@steps << s | ||
yield s if block_given? | ||
end | ||
|
||
def active? | ||
@steps.inject(false) {|act, s| act || s.active? } | ||
end | ||
|
||
def perform_start | ||
@idle_step.start | ||
end | ||
|
||
def perform_reset | ||
@steps.each {|br| br.last.reset } | ||
end | ||
|
||
|
||
private | ||
|
||
def to_step(step) | ||
if step.respond_to? :to_step | ||
step.to_step | ||
else | ||
step | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.