lib/kindergarten/perimeter.rb in kindergarten-0.1.0 vs lib/kindergarten/perimeter.rb in kindergarten-0.1.1
- old
+ new
@@ -81,24 +81,34 @@
@callbacks ||= {}
@callbacks[purpose] ||= {}
@callbacks[purpose][event] ||= []
@callbacks[purpose][event] << block
end
+
+ def subscriptions
+ @callbacks ||= {}
+ end
end
- attr_reader :child, :governess
+ attr_reader :child, :governess, :sandbox
# Obtain an un-sandboxed instance for testing purposes
#
# @return [Perimeter] with the given child and/or governess
#
def self.instance(child=nil, governess=nil)
self.new(child, governess)
end
- def initialize(child, governess)
- @child = child
+ def initialize(sandbox, governess)
+ if sandbox.is_a? Kindergarten::Sandbox
+ @sandbox = sandbox
+ @child = sandbox.child
+ else
+ @child = sandbox
+ end
+
@governess = governess
unless @governess.nil? || self.class.govern_proc.nil?
@governess.instance_eval(&self.class.govern_proc)
end
@@ -121,9 +131,18 @@
else
self.governess.governed(method, &block)
end
+ end
+
+ def fire(event, payload=nil)
+ if @sandbox.nil?
+ Kindergarten.warning("There is no sandbox, is this a test-perimeter?")
+ return
+ end
+
+ @sandbox.purpose[self.class.purpose].fire(event, payload)
end
end
end