Skip to content

Commit 03e935b

Browse files
dafyddcrosbyfacebook-github-bot
authored andcommitted
Move library files to lib/
Summary: This gets the cookbook tree in line with the bookworm-specific github repo, while still working when run within the cookbook Instead of using require_relative for libraries, we'll add the bookworm libraries to the LOAD_PATH in the wrapper script created in the prior diff in the stack. This allows us to follow the idiomatic lib/ directory layout seen in most Ruby gems (and used in the Bookworm github repo). Differential Revision: D68423773 fbshipit-source-id: 3c9acd5a1ffd971c9f0c55043486639c8b2e032c
1 parent f499c9a commit 03e935b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+44
-18
lines changed

cookbooks/fb_bookworm/files/default/bookworm/bin/bookworm

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ end
103103
# We require the libraries *after* the profiler has a chance to start,
104104
# also means faster `bookworm -h` response
105105
require 'set'
106-
require_relative '../exceptions'
107-
require_relative '../keys'
108-
require_relative '../configuration'
109-
require_relative '../crawler'
110-
require_relative '../knowledge_base'
111-
require_relative '../infer_engine'
112-
require_relative '../report_builder'
106+
require 'bookworm/exceptions'
107+
require 'bookworm/keys'
108+
require 'bookworm/configuration'
109+
require 'bookworm/crawler'
110+
require 'bookworm/knowledge_base'
111+
require 'bookworm/infer_engine'
112+
require 'bookworm/report_builder'
113113

114114
module Bookworm
115115
class ClassLoadError < RuntimeError; end
@@ -189,11 +189,12 @@ module Bookworm
189189
end
190190

191191
def load_src_dirs
192-
@report_src_dirs = ["#{__dir__}/../reports/"]
192+
require 'bookworm/load_hack'
193+
@report_src_dirs = [::Bookworm::BUILTIN_REPORTS_DIR]
193194
if Dir.exist? "#{@config.system_contrib_dir}/reports"
194195
@report_src_dirs.append "#{@config.system_contrib_dir}/reports"
195196
end
196-
@rule_src_dirs = ["#{__dir__}/../rules/"]
197+
@rule_src_dirs = [::Bookworm::BUILTIN_RULES_DIR]
197198
if Dir.exist? "#{@config.system_contrib_dir}/rules/"
198199
@rule_src_dirs.append "#{@config.system_contrib_dir}/rules/"
199200
end

cookbooks/fb_bookworm/files/default/bookworm/bookworm.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@
1717
# Wrapper so that we can have ruby load path hackery from the fb_bookworm cookbook
1818
# I'd like to believe this won't be permanent, but these things last for years...
1919

20+
$LOAD_PATH.unshift("#{__dir__}/lib")
2021
load 'bin/bookworm'

cookbooks/fb_bookworm/files/default/bookworm/configuration.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/configuration.rb

File renamed without changes.

cookbooks/fb_bookworm/files/default/bookworm/crawler.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/crawler.rb

File renamed without changes.

cookbooks/fb_bookworm/files/default/bookworm/exceptions.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/exceptions.rb

File renamed without changes.

cookbooks/fb_bookworm/files/default/bookworm/infer_base_classes.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/infer_base_classes.rb

File renamed without changes.

cookbooks/fb_bookworm/files/default/bookworm/infer_engine.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/infer_engine.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
require_relative 'knowledge_base'
17-
require_relative 'infer_base_classes'
16+
require 'bookworm/knowledge_base'
17+
require 'bookworm/infer_base_classes'
1818

1919
module Bookworm
2020
# The InferEngine class takes a KnowledgeBase object, and then runs the given

cookbooks/fb_bookworm/files/default/bookworm/keys.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/keys.rb

File renamed without changes.

cookbooks/fb_bookworm/files/default/bookworm/knowledge_base.rb renamed to cookbooks/fb_bookworm/files/default/bookworm/lib/bookworm/knowledge_base.rb

File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright (c) 2022-present, Meta Platforms, Inc. and affiliates
2+
# All rights reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# TODO: This is gross, and I seem to recall there was some way to get a gem's
17+
# library directory, but this should work for now.
18+
module Bookworm
19+
BUILTIN_REPORTS_DIR = "#{__dir__}/reports/".freeze
20+
BUILTIN_RULES_DIR = "#{__dir__}/rules/".freeze
21+
end

0 commit comments

Comments
 (0)