Class: Dandy::TypeLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/dandy/loaders/type_loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(dandy_config) ⇒ TypeLoader

Returns a new instance of TypeLoader.



3
4
5
# File 'lib/dandy/loaders/type_loader.rb', line 3

def initialize(dandy_config)
  @directories = dandy_config[:path][:dependencies]
end

Instance Method Details

#load_typesObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dandy/loaders/type_loader.rb', line 7

def load_types
  types = []
  @directories.each do |directory|
    dir = File.join(directory, '**/*')
    files = Dir.glob(dir).reject {|file_path| File.directory?(file_path)}

    files.each do |file|
      path = File.join(Dir.pwd, file)
      require path
      file_name = File.basename(file).gsub(File.extname(file), '')
      class_name = file_name.split('_').each(&:capitalize!).join('')
      types << {
        class: Object.const_get(class_name),
        path: file.gsub(File.extname(file), '').gsub(directory + '/', '')
      }
    end
  end

  types
end