Top Level Namespace
Defined Under Namespace
Modules: Judges Classes: Object
Instance Method Summary collapse
-
#if_absent(fb) {|f| ... } ⇒ Object
Injects a fact if it’s absent in the factbase.
-
#once(fb, judge: $judge) ⇒ Object
Returns a decorated global factbase, which only touches facts once.
Instance Method Details
#if_absent(fb) {|f| ... } ⇒ Object
Injects a fact if it’s absent in the factbase.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/judges/fb/if_absent.rb', line 27 def if_absent(fb) attrs = {} f = Judges::Accumulator.new(attrs) yield f q = attrs.map do |k, v| vv = v.to_s if v.is_a?(String) vv = "'#{vv.gsub('"', '\\"').gsub("'", "\\'")}'" elsif v.is_a?(Time) vv = v.iso8601 end "(eq #{k} #{vv})" end.join(' ') q = "(and #{q})" return unless fb.query(q).each.to_a.empty? n = fb.insert attrs.each { |k, v| n.send("#{k}=", v) } n end |