Class: SQLKnit::SQL::Select
- Inherits:
-
Object
- Object
- SQLKnit::SQL::Select
- Defined in:
- lib/sql/select.rb
Instance Attribute Summary collapse
-
#statement_chains ⇒ Object
readonly
Returns the value of attribute statement_chains.
Instance Method Summary collapse
-
#initialize ⇒ Select
constructor
A new instance of Select.
- #text(str) ⇒ Object
- #to_statement ⇒ Object
Constructor Details
#initialize ⇒ Select
Returns a new instance of Select.
7 8 9 |
# File 'lib/sql/select.rb', line 7 def initialize @statement_chains = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(table_name, as_mapper) ⇒ Object (private)
21 22 23 24 25 26 27 28 |
# File 'lib/sql/select.rb', line 21 def method_missing table_name, as_mapper create_method table_name do |as_mapper| as_mapper.each {|col, as_col| text "#{table_name}.#{col} as #{as_col}"} end send table_name, as_mapper end |
Instance Attribute Details
#statement_chains ⇒ Object (readonly)
Returns the value of attribute statement_chains.
5 6 7 |
# File 'lib/sql/select.rb', line 5 def statement_chains @statement_chains end |
Instance Method Details
#text(str) ⇒ Object
11 12 13 |
# File 'lib/sql/select.rb', line 11 def text str statement_chains << str if not statement_chains.include? str end |
#to_statement ⇒ Object
15 16 17 |
# File 'lib/sql/select.rb', line 15 def to_statement "select #{statement_chains.join(",\n")}" end |