Class: Column

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

Direct Known Subclasses

Count, Sum

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#*, #+, #<, #<=, #>, #>=, #and, #asc, #desc, #eq, #in, #minus, #ne, #not, #plus

Constructor Details

#initialize(name, origin = nil, from = nil) ⇒ Column

Returns a new instance of Column.



264
265
266
267
268
# File 'lib/lilit_sql.rb', line 264

def initialize(name, origin = nil, from = nil)
  @name = name
  @origin = origin
  @from = from
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



262
263
264
# File 'lib/lilit_sql.rb', line 262

def name
  @name
end

#originObject

Returns the value of attribute origin.



262
263
264
# File 'lib/lilit_sql.rb', line 262

def origin
  @origin
end

Instance Method Details

#==(other) ⇒ Object



292
293
294
# File 'lib/lilit_sql.rb', line 292

def ==(other)
  other.class == self.class && other.state == state
end

#decl_sqlObject



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/lilit_sql.rb', line 278

def decl_sql
  s = ''
  if origin
    origin_sql = if origin.is_a?(Proc)
                   origin.call.ref_sql
                 else
                   origin.ref_sql
                 end
    s += "#{origin_sql} as " if origin_sql != @name.to_s
  end
  s += @name.to_s
  s
end

#ref_sqlObject



274
275
276
# File 'lib/lilit_sql.rb', line 274

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

#stateObject



296
297
298
# File 'lib/lilit_sql.rb', line 296

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

#with_from(from) ⇒ Object



270
271
272
# File 'lib/lilit_sql.rb', line 270

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