Class: GraphQL::Doctor::Source::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/doctor/source/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(root: Dir.pwd, config: Config.new, cache: true) ⇒ Loader

Returns a new instance of Loader.



10
11
12
13
14
15
# File 'lib/graphql/doctor/source/loader.rb', line 10

def initialize(root: Dir.pwd, config: Config.new, cache: true)
  @root = File.expand_path(root)
  @config = config
  @cache = cache && Cache.new(directory: File.join(@root, ".graphql-doctor/cache"))
  @config_digest = Digest::SHA256.hexdigest(JSON.generate(config.values))
end

Instance Method Details

#discover(paths = []) ⇒ Object



25
26
27
28
29
30
# File 'lib/graphql/doctor/source/loader.rb', line 25

def discover(paths = [])
  patterns = paths.empty? ? @config["include"] : paths
  included = patterns.flat_map { |pattern| expand(pattern) }.uniq
  excluded = @config["exclude"].flat_map { |pattern| expand(pattern) }
  (included - excluded).select { |path| File.file?(path) && File.extname(path) == ".rb" }.sort
end

#load(paths = [], jobs: 1) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/graphql/doctor/source/loader.rb', line 17

def load(paths = [], jobs: 1)
  files = discover(paths)
  return Index.new.freeze! if files.empty?

  indexes = parse_files(files, jobs.to_i)
  indexes.reduce(Index.new, &:merge).freeze!
end