Class: AppMode

Inherits:
StateManager show all
Defined in:
lib/app_mode/app_mode.rb

Overview

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

Constant Summary collapse

@@mode =

Tracks a global mode setting.

nil

Instance Attribute Summary

Attributes inherited from StateManager

#state, #valid_states

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from StateManager

#send

Constructor Details

#initialize(*args) ⇒ AppMode

Constructor.

Raises:

  • (NotImplementedError)


42
43
44
45
46
# 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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class StateManager

Class Method Details

.send(method, *args) ⇒ Object

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.



55
56
57
58
# 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) ⇒ Object

Initializes the global mode setting.



61
62
63
# File 'lib/app_mode/app_mode.rb', line 61

def setup(*args)
  @@mode = self.superclass.new(*args)
end