module Pakyow::TestHelp::Observable
Constants
- VIEW_CLASSES
TODO a version of this exists in ViewContext; consider drying it up
Public Instance Methods
method_missing(name, *args, &block)
click to toggle source
# File pakyow-test/lib/pakyow/test_help/observable.rb, line 14 def method_missing(name, *args, &block) handle_value(observable.send(name, *args, &block)) end
observed?(scope, action, traversal, values)
click to toggle source
# File pakyow-test/lib/pakyow/test_help/observable.rb, line 29 def observed?(scope, action, traversal, values) return false if @observations.nil? @observations.each do |observation| next if observation[:scope] != scope next if observation[:action] != action next if observation[:traversal] != traversal values.each_pair do |k, v| return false if observation[:values][k] != v end return true end return false end
observing(scope, action, traversal, values)
click to toggle source
TODO likely need to handle nested observations
# File pakyow-test/lib/pakyow/test_help/observable.rb, line 19 def observing(scope, action, traversal, values) @observations ||= [] @observations << { scope: scope, action: action, traversal: traversal, values: values } end
Private Instance Methods
handle_value(value)
click to toggle source
# File pakyow-test/lib/pakyow/test_help/observable.rb, line 48 def handle_value(value) if VIEW_CLASSES.include?(value.class) traversal = [] if self.is_a?(ObservableView) parent = presenter if view.is_a?(Pakyow::Presenter::View) || view.is_a?(Pakyow::Presenter::ViewCollection) traversal = @traversal.dup traversal << value.scoped_as end else parent = self end if value.is_a?(Pakyow::Presenter::ViewCollection) value.instance_variable_get(:@views).map! { |collected_view| ObservableView.new(collected_view, parent, traversal) } end return ObservableView.new(value, parent, traversal) end value end