Class: Sneaql::Core::SneaqlCommand
- Inherits:
-
Object
- Object
- Sneaql::Core::SneaqlCommand
- Defined in:
- lib/sneaql_lib/base.rb
Overview
Base class for SneaQL command tags
Direct Known Subclasses
Commands::SneaqlAssign, Commands::SneaqlAssignResult, Commands::SneaqlExecute, Commands::SneaqlExecuteIf, Commands::SneaqlExitIf, Commands::SneaqlExitStepIf, Commands::SneaqlFailIf, Commands::SneaqlIterateRecordset, Commands::SneaqlOnError, Commands::SneaqlRecordsetFromDirGlob, Commands::SneaqlRecordsetFromQuery, Commands::SneaqlRemoveRecordset, Commands::SneaqlTest
Instance Method Summary collapse
-
#action ⇒ Object
override this method with the actual code for your command.
-
#arg_definition ⇒ Object
override with an array in the form [:expression, :operator].
-
#initialize(jdbc_connection, expression_handler, exception_manager, recordset_manager, statement, logger = nil) ⇒ SneaqlCommand
constructor
this is the base object for a sneaql command subclass this and override the action method.
-
#valid_expression?(a) ⇒ Boolean
validates that the value is a valid expression.
-
#valid_operator?(a) ⇒ Boolean
validates that the value is a valid operator.
-
#valid_recordset?(a) ⇒ Boolean
validates that the value is a valid recordset name.
-
#valid_symbol?(a) ⇒ Boolean
note that this is not a ruby symbol, but a sneaql symbol should be a contigiuous string consisting of only letters, digits and underscores.
-
#valid_variable?(a) ⇒ Boolean
validates that the value is a valid variable name.
-
#validate_args(args) ⇒ Boolean
override this if you have a complex tag structure.
Constructor Details
#initialize(jdbc_connection, expression_handler, exception_manager, recordset_manager, statement, logger = nil) ⇒ SneaqlCommand
this is the base object for a sneaql command subclass this and override the action method
77 78 79 80 81 82 83 84 85 |
# File 'lib/sneaql_lib/base.rb', line 77 def initialize(jdbc_connection, expression_handler, exception_manager, recordset_manager, statement, logger = nil) @logger = logger ? logger : Logger.new(STDOUT) @jdbc_connection = jdbc_connection @expression_handler = expression_handler @exception_manager = exception_manager @statement = statement @recordset_manager = recordset_manager end |
Instance Method Details
#action ⇒ Object
override this method with the actual code for your command
88 89 90 |
# File 'lib/sneaql_lib/base.rb', line 88 def action nil end |
#arg_definition ⇒ Object
override with an array in the form [:expression, :operator]
93 94 95 |
# File 'lib/sneaql_lib/base.rb', line 93 def arg_definition [] end |
#valid_expression?(a) ⇒ Boolean
validates that the value is a valid expression
140 141 142 143 144 145 146 |
# File 'lib/sneaql_lib/base.rb', line 140 def valid_expression?(a) @expression_handler.valid_expression_reference?(a.to_s.strip) rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |
#valid_operator?(a) ⇒ Boolean
validates that the value is a valid operator
151 152 153 154 155 156 157 |
# File 'lib/sneaql_lib/base.rb', line 151 def valid_operator?(a) @expression_handler.valid_operators.include?(a.to_s.strip) rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |
#valid_recordset?(a) ⇒ Boolean
validates that the value is a valid recordset name
162 163 164 165 166 167 168 |
# File 'lib/sneaql_lib/base.rb', line 162 def valid_recordset?(a) @recordset_manager.valid_recordset_name?(a.to_s.strip) rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |
#valid_symbol?(a) ⇒ Boolean
note that this is not a ruby symbol, but a sneaql symbol should be a contigiuous string consisting of only letters, digits and underscores
175 176 177 178 179 180 181 182 |
# File 'lib/sneaql_lib/base.rb', line 175 def valid_symbol?(a) return true if a.match(/^\w+$/) false rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |
#valid_variable?(a) ⇒ Boolean
validates that the value is a valid variable name
129 130 131 132 133 134 135 |
# File 'lib/sneaql_lib/base.rb', line 129 def valid_variable?(a) @expression_handler.valid_session_variable_name?(a.to_s.strip) rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |
#validate_args(args) ⇒ Boolean
override this if you have a complex tag structure
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/sneaql_lib/base.rb', line 100 def validate_args(args) return false if args.length != arg_definition.length return true if (arg_definition == []) and (args == []) valid = [] args.each_with_index do |a, i| case when arg_definition[i] == :variable then valid << valid_variable?(a) when arg_definition[i] == :expression then valid << valid_expression?(a) when arg_definition[i] == :operator then valid << valid_operator?(a) when arg_definition[i] == :recordset then valid << valid_recordset?(a) when arg_definition[i] == :symbol then valid << valid_symbol?(a) else valid << false end end @logger.debug("arg validation results: #{valid}") !valid.include?(false) rescue => e @logger.error(e.) e.backtrace { |r| @logger.error(r) } raise e end |