Class: SQL
- Inherits:
-
Object
show all
- Defined in:
- lib/eno.rb
Constant Summary
collapse
- H_EMPTY =
{}.freeze
Instance Method Summary
collapse
Constructor Details
Returns a new instance of SQL.
[View source]
402
403
404
|
# File 'lib/eno.rb', line 402
def initialize(ctx)
@ctx = ctx
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink
#method_missing(sym, *args) ⇒ Object
[View source]
427
428
429
430
431
432
433
434
435
436
437
438
439
|
# File 'lib/eno.rb', line 427
def method_missing(sym, *args)
if @ctx.has_key?(sym)
value = @ctx[sym]
return Symbol === value ? Identifier.new(value) : value
end
super if sym == :to_hash
if args.empty?
Identifier.new(sym)
else
FunctionCall.new(sym, *args)
end
end
|
Instance Method Details
permalink
#from(*members, **props) ⇒ Object
[View source]
455
456
457
|
# File 'lib/eno.rb', line 455
def from(*members, **props)
@from = From.new(*members, **props)
end
|
permalink
#limit(*members) ⇒ Object
[View source]
475
476
477
|
# File 'lib/eno.rb', line 475
def limit(*members)
@limit = Limit.new(*members)
end
|
permalink
#order_by(*members, **props) ⇒ Object
[View source]
471
472
473
|
# File 'lib/eno.rb', line 471
def order_by(*members, **props)
@order_by = OrderBy.new(*members, **props)
end
|
permalink
#select(*members, **props) ⇒ Object
[View source]
447
448
449
450
451
452
453
|
# File 'lib/eno.rb', line 447
def select(*members, **props)
if members.empty? && !props.empty?
members = props.map { |k, v| Alias.new(v, k) }
props = {}
end
@select = Select.new(*members, **props)
end
|
permalink
#to_sql(&block) ⇒ Object
[View source]
406
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/eno.rb', line 406
def to_sql(&block)
instance_eval(&block)
[
@with,
@select || default_select,
@from,
@where,
@window,
@order_by,
@limit
].compact.map { |c| c.to_sql }.join(' ')
end
|
permalink
#where(expr) ⇒ Object
[View source]
459
460
461
462
463
464
465
|
# File 'lib/eno.rb', line 459
def where(expr)
if @where
@where.members << expr
else
@where = Where.new(expr)
end
end
|
permalink
#window(sym, &block) ⇒ Object
[View source]
467
468
469
|
# File 'lib/eno.rb', line 467
def window(sym, &block)
@window = Window.new(sym, &block)
end
|
permalink
#with(*members, **props) ⇒ Object
[View source]
441
442
443
|
# File 'lib/eno.rb', line 441
def with(*members, **props)
@with = With.new(*members, **props)
end
|