Module: Bake::Scope

Defined in:
lib/bake/scope.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.inspectObject



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

def self.inspect
  "Bake::Scope<#{self.const_get(:FILE_PATH)}>"
end

.load(file_path, path = []) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/bake/scope.rb', line 25

def self.load(file_path, path = [])
  scope = Module.new
  scope.extend(self)
  
  scope.const_set(:FILE_PATH, file_path)
  scope.const_set(:PATH, path)
  
  scope.module_eval(File.read(file_path), file_path)
  
  return scope
end

Instance Method Details

#pathObject



55
56
57
# File 'lib/bake/scope.rb', line 55

def path
  self.const_get(:PATH)
end

#recipe(name, **options, &block) ⇒ Object



41
42
43
# File 'lib/bake/scope.rb', line 41

def recipe(name, **options, &block)
  define_method(name, &block)
end

#recipe_for(name) ⇒ Object



59
60
61
# File 'lib/bake/scope.rb', line 59

def recipe_for(name)
  Recipe.new(self, name, self.instance_method(name))
end

#recipesObject



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

def recipes
  return to_enum(:recipes) unless block_given?
  
  names = self.instance_methods
  
  names.each do |name|
    yield recipe_for(name)
  end
end