Class: Jekyll::Spaceship::Register

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-spaceship/cores/register.rb

Class Method Summary collapse

Class Method Details

.use(name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jekyll-spaceship/cores/register.rb', line 19

def self.use(name)
  name = name.to_s.gsub(/-/, '').downcase
  name += 'processor' unless name.match(/processor$/)

  self.walk(File.join(File.dirname(__FILE__), '/../processors')) do |path|
    filename = File.basename(path, '.rb')
    next if filename.gsub(/-/, '').downcase != name

    Logger.log "🗂  use #{filename}"
    require path
    constants = Jekyll::Spaceship.constants.select do |c|
      c.downcase.to_s == name
    end

    next if constants.first.nil?
    _class = Jekyll::Spaceship.const_get(constants.first)
    next unless _class.is_a? Class

    Manager.add _class.new
  end
end

.walk(start, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jekyll-spaceship/cores/register.rb', line 5

def self.walk(start, &block)
  Dir.foreach start do |x|
    path = File.join(start, x)
    if x == '.' or x == '..'
      next
    elsif File.directory?(path)
      block.call(path + '/')
      walk path
    else
      block.call(path)
    end
  end
end