Class: DmAdapterSimpledb::WhereExpression

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Query::Conditions
Defined in:
lib/dm-adapter-simpledb/where_expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conditions, options = {}) ⇒ WhereExpression

Returns a new instance of WhereExpression.



8
9
10
11
# File 'lib/dm-adapter-simpledb/where_expression.rb', line 8

def initialize(conditions, options={})
  @conditions = conditions
  @logger     = options.fetch(:logger){ DataMapper.logger }
end

Instance Attribute Details

#conditionsObject (readonly)

Returns the value of attribute conditions.



5
6
7
# File 'lib/dm-adapter-simpledb/where_expression.rb', line 5

def conditions
  @conditions
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/dm-adapter-simpledb/where_expression.rb', line 6

def logger
  @logger
end

Instance Method Details

#to_sObject



13
14
15
# File 'lib/dm-adapter-simpledb/where_expression.rb', line 13

def to_s
  node_to_expression(conditions)
end

#unsupported_conditions(node = conditions, top = true) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dm-adapter-simpledb/where_expression.rb', line 17

def unsupported_conditions(node=conditions, top=true)
  case node
  when InclusionComparison
    if node.value.is_a?(Range) && node.value.exclude_end?
      logger.warn "Exclusive ranges are not supported natively by the SimpleDB adapter"
      node.dup
    end
  when RegexpComparison
    logger.warn "Regexp comparisons are not supported natively by the SimpleDB adapter"
    node.dup
  when AbstractOperation
    op_copy = node.dup
    op_copy.clear
    operands_copy = 
      node.operands.map{|o| unsupported_conditions(o,false)}.compact
    if operands_copy.size > 0
      op_copy.operands.merge(operands_copy)
      op_copy
    else
      top ? Operation.new(:and) : nil
    end
  else top ? Operation.new(:and) : nil
  end
end