class AppMode

This class manages the mode that the executing code is running in.

Public Class Methods

new(*args) click to toggle source

Constructor.

# File lib/app_mode/app_mode.rb, line 42
def initialize(*args)
  # AppMode.new should not be called.
  raise NotImplementedError, "#{self.class.name}.new is not implemented. " +
    "You probably want #{self.class.superclass.name}.new."
end
send(method, *args) click to toggle source

Override the send method.

This was implemented to cover the case where test is used as a state. In that case, the default behavior was to call the private test method from Kernel. This prevents that behavior in cases where a public method is available via method_missing in the parent class.

Calls superclass method StateManager#send
# File lib/app_mode/app_mode.rb, line 55
def send(method, *args)
  return method_missing(method, *args) if respond_to_missing?(method, false)
  super
end
setup(*args) click to toggle source

Initializes the global mode setting.

# File lib/app_mode/app_mode.rb, line 61
def setup(*args)
  @@mode = self.superclass.new(*args)
end

Private Class Methods

method_missing(method, *args, &block) click to toggle source

Passes missing methods on to the instance.

# File lib/app_mode/app_mode.rb, line 70
def method_missing(method, *args, &block)
  setup unless @@mode
  @@mode.send method, *args
end
respond_to_missing?(method, include_private) click to toggle source

Ensure that the object knows what it can respond to via method_missing.

Input

method : Symbol

The method to check for a response to.

include_private : Boolean

Whether to include private methods.

Output

Boolean

Whether the object will respond to the specified method.

Calls superclass method StateManager#respond_to_missing?
# File lib/app_mode/app_mode.rb, line 81
def respond_to_missing?(method, include_private)
  return true if @@mode.respond_to?(method, include_private)
  super
end