Class: Dorm::WhereDSL

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

Overview

DSL for building WHERE conditions

Defined Under Namespace

Classes: Condition, FieldCondition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, param_counter) ⇒ WhereDSL

Returns a new instance of WhereDSL.



346
347
348
349
350
# File 'lib/dorm/query_builder.rb', line 346

def initialize(table_name, param_counter)
  @table_name = table_name
  @param_counter = param_counter
  @params = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(field_name, *args) ⇒ Object



352
353
354
# File 'lib/dorm/query_builder.rb', line 352

def method_missing(field_name, *args)
  FieldCondition.new(field_name, @table_name, self)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



344
345
346
# File 'lib/dorm/query_builder.rb', line 344

def params
  @params
end

Instance Method Details

#add_param(value) ⇒ Object



356
357
358
359
360
# File 'lib/dorm/query_builder.rb', line 356

def add_param(value)
  @params << value
  @param_counter += 1
  "$#{@param_counter}"
end