lib/vedeu/interface/interfaces.rb in vedeu-0.0.5 vs lib/vedeu/interface/interfaces.rb in vedeu-0.0.6
- old
+ new
@@ -1,49 +1,53 @@
module Vedeu
class UndefinedInterface < StandardError; end
- class Interfaces
- class << self
- def default
- new { |io| io.add(:dummy, Dummy) }
- end
+ module Interfaces
+ extend self
- def define(&block)
- new(&block)
- end
+ def default
+ add(:dummy, Dummy)
end
- def initialize(&block)
- @interfaces ||= {}
+ def defined
+ interfaces.empty? ? nil : interfaces
+ end
- yield self if block_given?
+ def define(&block)
+ if block_given?
+ yield self
+ else
+ self
+ end
end
+ def list
+ interfaces.inspect
+ end
+
def add(name, klass, options = {})
if valid?(klass)
interfaces[name] = Proc.new { klass.new(options) }
interfaces
end
end
- def show
- interfaces
- end
-
def initial_state
interfaces.values.map { |io| io.call.initial_state }
end
def event_loop
interfaces.values.map { |io| io.call.event_loop }
end
private
- attr_accessor :interfaces
-
def valid?(klass)
raise UndefinedInterface unless Object.const_defined?(klass.to_s)
true
+ end
+
+ def interfaces
+ @interfaces ||= {}
end
end
end