Class: Column
- Inherits:
-
Object
- Object
- Column
- Defined in:
- lib/lilit_sql.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#origin ⇒ Object
Returns the value of attribute origin.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #<=(other) ⇒ Object
- #==(other) ⇒ Object
- #decl_sql ⇒ Object
- #eq(other) ⇒ Object
- #in(list) ⇒ Object
-
#initialize(name, origin = nil, from = nil) ⇒ Column
constructor
A new instance of Column.
- #ref_sql ⇒ Object
- #state ⇒ Object
- #with_from(from) ⇒ Object
Constructor Details
#initialize(name, origin = nil, from = nil) ⇒ Column
Returns a new instance of Column.
105 106 107 108 109 |
# File 'lib/lilit_sql.rb', line 105 def initialize(name, origin = nil, from = nil) @name = name @origin = origin @from = from end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
102 103 104 |
# File 'lib/lilit_sql.rb', line 102 def name @name end |
#origin ⇒ Object
Returns the value of attribute origin.
103 104 105 |
# File 'lib/lilit_sql.rb', line 103 def origin @origin end |
Instance Method Details
#*(other) ⇒ Object
123 124 125 |
# File 'lib/lilit_sql.rb', line 123 def *(other) Expr.new(self, :*, other) end |
#<=(other) ⇒ Object
127 128 129 |
# File 'lib/lilit_sql.rb', line 127 def <=(other) Expr.new(self, :<=, other) end |
#==(other) ⇒ Object
151 152 153 |
# File 'lib/lilit_sql.rb', line 151 def ==(other) other.class == self.class && other.state == self.state end |
#decl_sql ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/lilit_sql.rb', line 135 def decl_sql s = '' if origin origin_sql = if origin.is_a?(Proc) origin.call.ref_sql else origin.ref_sql end if origin_sql != @name.to_s s += "#{origin_sql} as " end end s += @name.to_s s end |
#eq(other) ⇒ Object
115 116 117 |
# File 'lib/lilit_sql.rb', line 115 def eq(other) Expr.new(self, :eq, other) end |
#in(list) ⇒ Object
119 120 121 |
# File 'lib/lilit_sql.rb', line 119 def in(list) Expr.new(self, :in, list) end |
#ref_sql ⇒ Object
131 132 133 |
# File 'lib/lilit_sql.rb', line 131 def ref_sql "#{@from.alias_name}.#{@name}" end |
#state ⇒ Object
155 156 157 |
# File 'lib/lilit_sql.rb', line 155 def state self.instance_variables.map { |variable| self.instance_variable_get variable } end |