Class: SQLObject

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

Overview

Main class for all objects. All other entities should inherit this class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSQLObject

Do we really need a constructor here?



12
13
14
15
16
17
# File 'lib/sqlobject.rb', line 12

def initialize
    @string = nil
    @alias  = nil
    @name   = nil
    @inline = nil
end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



7
8
9
# File 'lib/sqlobject.rb', line 7

def alias
  @alias
end

#inlineObject

Returns the value of attribute inline.



7
8
9
# File 'lib/sqlobject.rb', line 7

def inline
  @inline
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/sqlobject.rb', line 7

def name
  @name
end

#separatorObject

Returns the value of attribute separator.



7
8
9
# File 'lib/sqlobject.rb', line 7

def separator
  @separator
end

Class Method Details

.get(*list) ⇒ Object

Convert values to the corresponding internal data types



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/sqlobject.rb', line 52

def self.get ( *list )
    list.map! do |expr|
        if expr.is_a? SQLObject
             # inline queries go in parens:
            if expr.class == SQLConstructor || expr.is_a?( SQLConstructor::GenericQuery )
                expr.inline = true
            end
            expr
        elsif expr.is_a? Array or expr.is_a? Range
            SQLValList.new *expr.to_a
        elsif expr.is_a? Hash
            SQLAliasedList.new expr
        elsif expr.is_a? Symbol
            SQLColumn.new( expr )
        else
            SQLValue.new( expr )
        end
    end

     # Return array or scalar, depending on the number of function arguments
    list.length == 1  ?  list[0]  :  list
end

Instance Method Details

#_name(name) ⇒ Object

Set object’s name for further named processing



22
23
24
25
# File 'lib/sqlobject.rb', line 22

def _name ( name )
    @name = name.to_s
    return self
end

#_stringObject

attr_reader for @string, actually an alias to to_s().



38
39
40
# File 'lib/sqlobject.rb', line 38

def _string
    to_s
end

#_string=(val) ⇒ Object

attr_writer for @string



45
46
47
# File 'lib/sqlobject.rb', line 45

def _string= ( val )
    @string = val
end

#to_sObject

Store string representation in @string after the first call



30
31
32
33
# File 'lib/sqlobject.rb', line 30

def to_s
    return @string  if @string
    @string = self.to_s
end