Class: FoodCritic::Chef::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/foodcritic/chef.rb

Instance Method Summary collapse

Instance Method Details

#chef_search_grammarsObject

lucene.treetop used to be provided by chef gem We’re keeping a local copy from chef 10.x



87
88
89
# File 'lib/foodcritic/chef.rb', line 87

def chef_search_grammars
  [File.expand_path("../../..", __FILE__) + "/misc/lucene.treetop"]
end

#create_parser(grammar_paths) ⇒ Object

Create the search parser from the first loadable grammar.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/foodcritic/chef.rb', line 92

def create_parser(grammar_paths)
  @search_parser ||=
    grammar_paths.inject(nil) do |parser, lucene_grammar|
      begin
        break parser unless parser.nil?

        # Don't instantiate custom nodes
        Treetop.load_from_string(
          IO.read(lucene_grammar).gsub(/<[^>]+>/, "")
        )
        LuceneParser.new
      rescue
        # Silently swallow and try the next grammar
      end
    end
end

#parserObject

The search parser



115
116
117
# File 'lib/foodcritic/chef.rb', line 115

def parser
  @search_parser
end

#parser?Boolean

Has the search parser been loaded?

Returns:

  • (Boolean)


110
111
112
# File 'lib/foodcritic/chef.rb', line 110

def parser?
  ! @search_parser.nil?
end