Class: UU::OS::VUC::FormController

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
uu_adk-0.28.16/lib/uu/os/vuc/form_controller.rb

Overview

Ancestor for development of custom form controllers. All controllers should define only event handling methods.

Examples:

Event method definition:

def on_<%event_code%>(view)
  # 1. process and modify view
  # 2. return status from {UU::ADK::HTTPStatus}
  #    (optional, 200/OK is returned if not defined)
end

Instance Method Summary (collapse)

Constructor Details

- (FormController) initialize

Creates new instance of FormController.



61
62
63
64
# File 'uu_adk-0.28.16/lib/uu/os/vuc/form_controller.rb', line 61

def initialize
  super
  @log = UU::OS::Logger.new(self.class)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

- (Object) method_missing(method, *args, &block)

Controller need not to implement all possible event methods. This method provides default behavior of all unimplemented events.



70
71
72
73
74
75
76
77
78
79
80
81
# File 'uu_adk-0.28.16/lib/uu/os/vuc/form_controller.rb', line 70

def method_missing(method, *args, &block)
  view = args[0]
  # Do not touch view in case of unimplemented event with exception
  # of submit event which must be always implemented.
  if (method == :on_submit)
    raise "Controller #{self.class} does not define on_submit method."
  elsif (method.to_s[/^on_/] == nil) || (args.size != 1)
    # Invoked method was not "event" method with view parameter - throw regular method missing exception.
    raise NameError.new("undefined local variable or method '#{method.to_s}' for #{self.class}")
  end
  return HTTPStatus::OK
end