Class: Bake::Loaders

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bake/loaders.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLoaders

Returns a new instance of Loaders.



37
38
39
40
# File 'lib/bake/loaders.rb', line 37

def initialize
  @roots = {}
  @ordered = Array.new
end

Class Method Details

.default(working_directory) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/bake/loaders.rb', line 29

def self.default(working_directory)
  loaders = self.new
  
  loaders.append_defaults(working_directory)
  
  return loaders
end

Instance Method Details

#append_defaults(working_directory) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/bake/loaders.rb', line 46

def append_defaults(working_directory)
  # Load recipes from working directory:
  self.append_path(working_directory)
  
  # Load recipes from loaded gems:
  self.append_from_gems
end

#append_from_gemsObject



94
95
96
97
98
99
100
101
102
# File 'lib/bake/loaders.rb', line 94

def append_from_gems
  Gem.loaded_specs.each do |name, spec|
    Console.logger.debug(self) {"Checking gem #{name}: #{spec.full_gem_path}..."}
    
    if path = spec.full_gem_path and File.directory?(path)
      append_path(path, name: spec.full_name)
    end
  end
end

#append_from_paths(paths, **options) ⇒ Object



104
105
106
107
108
# File 'lib/bake/loaders.rb', line 104

def append_from_paths(paths, **options)
  paths.each do |path|
    append_path(path, **options)
  end
end

#append_from_root(current = Dir.pwd, **options) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/bake/loaders.rb', line 80

def append_from_root(current = Dir.pwd, **options)
  while current
    append_path(current, **options)
    
    parent = File.dirname(current)
    
    if current == parent
      break
    else
      current = parent
    end
  end
end

#append_path(current = Dir.pwd, **options) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bake/loaders.rb', line 60

def append_path(current = Dir.pwd, **options)
  recipes_path = File.join(current, "recipes")
  bake_path = File.join(current, "bake")
  
  if File.directory?(bake_path)
    return insert(bake_path, **options)
  end
  
  if File.directory?(recipes_path)
    Console.logger.warn(self) do |buffer|
      buffer.puts "Recipes path: #{recipes_path.inspect} is deprecated."
      buffer.puts "Please use #{bake_path.inspect} instead."
    end
    
    return insert(recipes_path, **options)
  end
  
  return false
end

#each(&block) ⇒ Object



54
55
56
57
58
# File 'lib/bake/loaders.rb', line 54

def each(&block)
  return to_enum unless block_given?
  
  @ordered.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/bake/loaders.rb', line 42

def empty?
  @ordered.empty?
end