Class: SQLKnit::SQL::Select

Inherits:
Object
  • Object
show all
Defined in:
lib/sql/select.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSelect

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_chainsObject (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_statementObject



15
16
17
# File 'lib/sql/select.rb', line 15

def to_statement
  "select #{statement_chains.join(",\n")}"
end