Class: Cassava::WhereClause

Inherits:
Struct
  • Object
show all
Defined in:
lib/cassava/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments

Returns:

  • (Object)

    the current value of arguments



195
196
197
# File 'lib/cassava/client.rb', line 195

def arguments
  @arguments
end

#partsObject

Returns the value of attribute parts

Returns:

  • (Object)

    the current value of parts



195
196
197
# File 'lib/cassava/client.rb', line 195

def parts
  @parts
end

Instance Method Details

#to_sObject



211
212
213
# File 'lib/cassava/client.rb', line 211

def to_s
  "WHERE #{parts.join(' AND ')}"
end

#where(*args) ⇒ Object



196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/cassava/client.rb', line 196

def where(*args)
  new_parts = self.parts.dup || []
  new_arguments = self.arguments.dup || []

  case args[0]
  when String
    new_parts << args[0]
    new_arguments += args[1..-1]
  when Hash
    new_parts += args[0].map { |key, value| "#{key} #{where_string(value)}" }
    new_arguments += args[0].values.flatten
  end
  self.class.new(new_parts, new_arguments)
end