Class: StudentInputFormController
- Inherits:
-
Object
- Object
- StudentInputFormController
- Defined in:
- lib/student_input_form_controller.rb
Instance Method Summary collapse
-
#initialize(parent_controller) ⇒ StudentInputFormController
constructor
A new instance of StudentInputFormController.
- #on_db_conn_error ⇒ Object
- #on_view_created ⇒ Object
- #process_fields(fields) ⇒ Object
- #set_view(view) ⇒ Object
Constructor Details
#initialize(parent_controller) ⇒ StudentInputFormController
Returns a new instance of StudentInputFormController.
6 7 8 |
# File 'lib/student_input_form_controller.rb', line 6 def initialize(parent_controller) @parent_controller = parent_controller end |
Instance Method Details
#on_db_conn_error ⇒ Object
42 43 44 45 46 |
# File 'lib/student_input_form_controller.rb', line 42 def on_db_conn_error api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') api.call(0, "No connection to DB", "Error", 0) @view.close end |
#on_view_created ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/student_input_form_controller.rb', line 14 def on_view_created begin @student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance)) rescue Mysql2::Error::ConnectionError on_db_conn_error end end |
#process_fields(fields) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/student_input_form_controller.rb', line 22 def process_fields(fields) begin last_name = fields.delete(:last_name) first_name = fields.delete(:first_name) parental_name = fields.delete(:parental_name) return if last_name.nil? || first_name.nil? || parental_name.nil? student = Student.new(last_name, first_name, parental_name, **fields) @student_list.add_student(student) @view.close rescue ArgumentError => e api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I') api.call(0, e., 'Error', 0) end end |
#set_view(view) ⇒ Object
10 11 12 |
# File 'lib/student_input_form_controller.rb', line 10 def set_view(view) @view = view end |