Class: ForestLiana::LiveQueryChecker
- Inherits:
-
Object
- Object
- ForestLiana::LiveQueryChecker
- Defined in:
- app/services/forest_liana/live_query_checker.rb
Constant Summary collapse
- QUERY_SELECT =
/\ASELECT\s.*FROM\s.*\z/im
Instance Method Summary collapse
-
#initialize(query, context) ⇒ LiveQueryChecker
constructor
A new instance of LiveQueryChecker.
- #validate ⇒ Object
Constructor Details
#initialize(query, context) ⇒ LiveQueryChecker
Returns a new instance of LiveQueryChecker.
5 6 7 8 |
# File 'app/services/forest_liana/live_query_checker.rb', line 5 def initialize(query, context) @query = query.strip @context = context end |
Instance Method Details
#validate ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/services/forest_liana/live_query_checker.rb', line 10 def validate raise generate_error 'You cannot execute an empty SQL query.' if @query.blank? if @query.include?(';') && @query.index(';') < (@query.length - 1) raise generate_error 'You cannot chain SQLÂ queries.' end raise generate_error 'Only SELECT queries are allowed.' if QUERY_SELECT.match(@query).nil? end |