Class: SQB::WhereDSL

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

Defined Under Namespace

Classes: Attribute, NegativeAttribute, PositiveAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWhereDSL

Returns a new instance of WhereDSL.



6
7
8
# File 'lib/sqb/where_dsl.rb', line 6

def initialize
  @hash = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, value = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sqb/where_dsl.rb', line 10

def method_missing(name, value = nil)
  if name =~ /(.*)\=\z/
    attribute_name = $1
    @hash[attribute_name.to_sym] ||= {}
    @hash[attribute_name.to_sym][:equal] = value
  else
    @hash[name.to_sym] ||= {}
    attribute = PositiveAttribute.new(name.to_sym, @hash)
  end
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



4
5
6
# File 'lib/sqb/where_dsl.rb', line 4

def hash
  @hash
end