lib/chef/knife/patches/parser.rb in knife-solo-0.1.0.pre1 vs lib/chef/knife/patches/parser.rb in knife-solo-0.1.0

- old
+ new

@@ -68,36 +68,48 @@ else keys.any?{ |key| self.elements[1].match(item[key]) } end end end - + # we don't support range matches # range of integers would be easy to implement # but string ranges are hard class FiledRange < Treetop::Runtime::SyntaxNode end - - class InclFieldRange < FieldRange + + # we handle '[* TO *]' as a special case since it is common in + # cookbooks for matching the existence of keys + class InclFieldRange + def match(item) + field = self.elements[0].text_value + range_start = self.elements[1].transform + range_end = self.elements[2].transform + if range_start == "*" and range_end == "*" + !!item[field] + else + raise "Ranges not really supported yet" + end + end end - + class ExclFieldRange < FieldRange end - + class RangeValue < Treetop::Runtime::SyntaxNode end - + class FieldName < Treetop::Runtime::SyntaxNode def match( item ) if self.text_value.count("_") > 0 item.merge!(build_flat_hash(item)) end if self.text_value.end_with?("*") part = self.text_value.chomp("*") item.keys.collect{ |key| key.start_with?(part)? key: nil}.compact else - if item.has_key?(self.text_value) + if item[self.text_value] [self.text_value,] else nil end end @@ -107,68 +119,68 @@ class Body < Treetop::Runtime::SyntaxNode def match( item ) self.elements[0].match( item ) end end - + class Group < Treetop::Runtime::SyntaxNode def match( item ) self.elements[0].match(item) end end - + class BinaryOp < Treetop::Runtime::SyntaxNode def match( item ) self.elements[1].match( self.elements[0].match(item), self.elements[2].match(item) ) end end - + class OrOperator < Treetop::Runtime::SyntaxNode def match( cond1, cond2 ) cond1 or cond2 end end - + class AndOperator < Treetop::Runtime::SyntaxNode def match( cond1, cond2 ) cond1 and cond2 end end - + # we don't support fuzzy string matching class FuzzyOp < Treetop::Runtime::SyntaxNode end - + class BoostOp < Treetop::Runtime::SyntaxNode end - + class FuzzyParam < Treetop::Runtime::SyntaxNode end - + class UnaryOp < Treetop::Runtime::SyntaxNode def match( item ) self.elements[0].match( self.elements[1].match(item) ) end end - + class NotOperator < Treetop::Runtime::SyntaxNode def match( cond ) not cond end end - + class RequiredOperator < Treetop::Runtime::SyntaxNode end - + class ProhibitedOperator < Treetop::Runtime::SyntaxNode end - + class Phrase < Treetop::Runtime::SyntaxNode # a quoted ::Term def match( value ) self.elements[0].match(value) end @@ -193,10 +205,10 @@ raise "Query #{data} is not supported: #{msg}" end self.clean_tree(tree) tree end - + private def self.clean_tree(root_node) # remove all SyntaxNode elements from the tree, we don't need them as # the related ruby class already knowns what to do.