Class: Absinthe::Distillery::SourceLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/absinthe/distillery/source_loader.rb

Instance Method Summary collapse

Instance Method Details

#boot!(ctx) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/absinthe/distillery/source_loader.rb', line 5

def boot! ctx
  if ctx[:app_root]
    $LOAD_PATH.unshift(File.expand_path(File.join(ctx[:app_root], 'lib')))
  end

  @plugin_paths = []
  $LOAD_PATH.each do |path|
    plugin_path = File.join path, 'absinthe', 'plugins'
    if File.directory? plugin_path
      @plugin_paths << plugin_path
    end
  end
end

#source_files(root, paths) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/absinthe/distillery/source_loader.rb', line 19

def source_files root, paths
  # TODO validate the root param
  sources = []

  # TODO this is a mess
  paths.each do |path|
    plugin_sources = []
    @plugin_paths.each do |plugin_path|
      target = File.join plugin_path, "#{path}.rb"
      if File.file? target
        file = File.new target
        plugin_sources << file

        support_dir = File.join plugin_path, path.to_s
        if File.directory? support_dir
          $LOAD_PATH.unshift support_dir
        end

        yield file
        $LOAD_PATH.delete support_dir
      end
    end
    if plugin_sources.empty?
      raise PluginNotFound, "No plugin named #{path} was found in #{@plugin_paths.join ', '}"
    end
  end
end