Class: Column

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

Direct Known Subclasses

Count, Sum

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



102
103
104
# File 'lib/lilit_sql.rb', line 102

def name
  @name
end

#originObject

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_sqlObject



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_sqlObject



131
132
133
# File 'lib/lilit_sql.rb', line 131

def ref_sql
  "#{@from.alias_name}.#{@name}"
end

#stateObject



155
156
157
# File 'lib/lilit_sql.rb', line 155

def state
  self.instance_variables.map { |variable| self.instance_variable_get variable }
end

#with_from(from) ⇒ Object



111
112
113
# File 'lib/lilit_sql.rb', line 111

def with_from(from)
  Column.new(@name, @origin, from)
end