Class: SQLExporter
- Inherits:
-
Object
- Object
- SQLExporter
- Defined in:
- lib/sqlexporter.rb
Overview
This class implements the interface for exprting SQLConstructor objects to strings.
Defined Under Namespace
Classes: Exporter_generic, Exporter_mysql
Constant Summary collapse
- DEFAULT_DIALECT =
defaults to ‘mysql’
'mysql'
Instance Attribute Summary collapse
-
#dialect ⇒ Object
Returns the value of attribute dialect.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#tidy ⇒ Object
Returns the value of attribute tidy.
Instance Method Summary collapse
-
#export(obj) ⇒ Object
The main method to export the obj to string.
-
#initialize(dialect = DEFAULT_DIALECT, tidy = false) ⇒ SQLExporter
constructor
Class constructor.
Constructor Details
#initialize(dialect = DEFAULT_DIALECT, tidy = false) ⇒ SQLExporter
Class constructor. Called with two optional arguments - dialect and tidy.
Dialect determines the translator class (e.g., Exporter_mysql,
Exporter_informix etc). Tidy determines whether the output should be
formatted and human-readable.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sqlexporter.rb', line 19 def initialize ( dialect = DEFAULT_DIALECT, tidy = false ) dialect ||= DEFAULT_DIALECT dialect_class = "Exporter_" + dialect.to_s begin @translator = SQLExporter.const_get( dialect_class ).new( tidy ) rescue raise NameError, ERR_UNKNOWN_DIALECT + ": " + dialect.to_s end @dialect, @tidy = dialect, tidy @separator = @translator.separator end |
Instance Attribute Details
#dialect ⇒ Object
Returns the value of attribute dialect.
7 8 9 |
# File 'lib/sqlexporter.rb', line 7 def dialect @dialect end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
8 9 10 |
# File 'lib/sqlexporter.rb', line 8 def separator @separator end |
#tidy ⇒ Object
Returns the value of attribute tidy.
7 8 9 |
# File 'lib/sqlexporter.rb', line 7 def tidy @tidy end |
Instance Method Details
#export(obj) ⇒ Object
The main method to export the obj to string. Calls the @translator’s
export method.
35 36 37 38 39 |
# File 'lib/sqlexporter.rb', line 35 def export ( obj ) string = @translator.export obj string = @separator + "(" + string + ")" if obj.inline return string end |