Class: Sqlyzer::Handler
- Inherits:
-
Object
- Object
- Sqlyzer::Handler
- Includes:
- Singleton
- Defined in:
- lib/sqlyzer/handler.rb
Overview
Singleton class handling generation and execution of all Sql commands. This is the only place where Sql requests are executed.
Class Method Summary collapse
-
.request(sender, action) ⇒ Object
Static method called by Sqlyzer::Serializer to request execution and generation of every Sql command.
Instance Method Summary collapse
-
#register_sender(sender) ⇒ Object
Register an instance of class extended with Sqlyzer::Serializer.
Class Method Details
.request(sender, action) ⇒ Object
Static method called by Sqlyzer::Serializer to request execution and generation of every Sql command. The command to generate and execute is determined by action Symbol value :
-
:sql_select,
-
:sql_insert,
-
:sql_update,
-
:sql_delete.
When action value is :sql_select, this method restore all sender attributes from data returned by generated Sql SELECT command execution.
When sender call this method for the first time, it is automatically registered through register_sender.
TODO: This method is very trivial for now, but further optimizations of Sql commands execution timelime have to go there.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/sqlyzer/handler.rb', line 66 def Handler.request(sender, action) Handler.instance.register_sender sender case action when :sql_select then Db::query(sender.sql_serialize(:sql_select)) { |data| data.each { |key, value| attrib = sender.sql_container_values[key] if attrib.nil? sender.sql_container_keys[key].to_owner(sender, value) else attrib.to_owner(sender, value) end } } else Db::do(sender.sql_serialize(action)) end nil end |
Instance Method Details
#register_sender(sender) ⇒ Object
Register an instance of class extended with Sqlyzer::Serializer. This method will create the Sql table associated with sender class if there is no table named like sender#sql_container_table().
41 42 43 44 |
# File 'lib/sqlyzer/handler.rb', line 41 def register_sender(sender) Db::do sender.sql_serialize(:sql_table) unless Db::tables.include?(sender.sql_container_table) end |