lib/cloud_sesame/query/ast/literal.rb in CloudSesame-0.4.6 vs lib/cloud_sesame/query/ast/literal.rb in CloudSesame-0.5.0
- old
+ new
@@ -7,22 +7,25 @@
ESCAPE_QUATE = "\\'"
attr_accessor :field
attr_reader :options, :value
- def initialize(field, value, options = {}, &block)
- @field = field
- @value = Value.parse value if value
- @value = Value.parse(ValueEvaluator.new.instance_exec &block) if block_given?
+ def initialize(field, value = nil, options = {})
+ @field, @options = field, options
+ self.value = value
+ end
- @options = options
- is_included
+ def value=(value)
+ if value
+ @value = Value.parse value
+ is_included
+ end
end
def is_for(field, options = {})
@field = field
- @options = options.merge @options
+ @options.merge! options
end
def is_included
applied[value] = true
end
@@ -34,11 +37,11 @@
def as_field
options[:as] || field
end
def compile(detailed = false)
- detailed ? detailed_format : standard_format
+ (detailed ? detailed_format : standard_format) if value
end
private
def applied
@@ -53,13 +56,9 @@
"field=#{ escape as_field.to_s } #{ value.compile }"
end
def escape(data)
"'#{ data.gsub(SINGLE_QUATE) { ESCAPE_QUATE } }'"
- end
-
- class ValueEvaluator
- include DSL::RangeMethods
end
end
end
end