Skip to content

Commit

Permalink
Revert "Remove static method MiqExpression.evaluate"
Browse files Browse the repository at this point in the history
  • Loading branch information
gtanzillo committed May 13, 2016
1 parent 7af0731 commit 648d20b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
10 changes: 7 additions & 3 deletions app/models/miq_expression.rb
Expand Up @@ -1007,8 +1007,8 @@ def self.exclude_col_by_preprocess_options?(col, options)
Metric::Rollup.excluded_col_for_expression?(col.to_sym)
end

def evaluate(obj, tz = nil)
ruby_exp = to_ruby(tz)
def self.evaluate(expression, obj, tz = nil)
ruby_exp = expression.kind_of?(Hash) ? new(expression).to_ruby(tz) : expression.to_ruby(tz)
_log.debug("Expression before substitution: #{ruby_exp}")
subst_expr = Condition.subst(ruby_exp, obj)
_log.debug("Expression after substitution: #{subst_expr}")
Expand All @@ -1017,9 +1017,13 @@ def evaluate(obj, tz = nil)
result
end

def evaluate(obj, tz = nil)
self.class.evaluate(self, obj, tz)
end

def self.evaluate_atoms(exp, obj)
exp = exp.kind_of?(self) ? copy_hash(exp.exp) : exp
exp["result"] = new(exp).evaluate(obj)
exp["result"] = evaluate(exp, obj)

operators = exp.keys
operators.each do|k|
Expand Down
12 changes: 0 additions & 12 deletions spec/models/miq_expression_spec.rb
Expand Up @@ -2094,16 +2094,4 @@
expect(obj.evaluate(@data_hash)).to eq(false)
end
end

describe ".evaluate_atoms" do
it "adds mapping 'result'=>false to expression if expression evaluates to false on supplied object" do
expression = {">=" => {"field" => "Vm-num_cpu",
"value" => "2"}}
result = described_class.evaluate_atoms(expression, FactoryGirl.build(:vm))
expect(result).to include(
">=" => {"field" => "Vm-num_cpu",
"value" => "2"},
"result" => false)
end
end
end

0 comments on commit 648d20b

Please sign in to comment.