lib/rast/parameter_generator.rb in rast-0.10.0 vs lib/rast/parameter_generator.rb in rast-0.11.0

- old
+ new

@@ -80,25 +80,32 @@ end # Detects if rule config has one outcome to one token mapping. def one_to_one(outcome_to_clause) outcome_to_clause.each do |outcome, clause| + next if clause.is_a?(Array) && clause.size == 1 + return false if RuleEvaluator.tokenize(clause: clause).size > 1 end true end # Used to optimize by detecting the variables if rules config is a 1 outcome to 1 rule token. def detect_variables(spec_config) return nil unless one_to_one(spec_config['rules']) + tokens = spec_config['rules'].values + return { vars: tokens.map(&:first) } if tokens.first.is_a?(Array) && tokens.first.size == 1 + { vars: spec_config['rules'].values } end def instantiate_spec(spec_config) - spec_config['variables'] = detect_variables(spec_config) if spec_config['variables'].nil? + if spec_config['variables'].nil? + spec_config['variables'] = detect_variables(spec_config) + end spec = RastSpec.new( description: spec_config[:description], variables: spec_config['variables'], rule: Rule.new(rules: spec_config['rules'])