Class: Bake::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/bake/base.rb

Overview

The base class for including Scope instances which define Recipe instances.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contextObject

Returns the value of attribute context



26
27
28
# File 'lib/bake/base.rb', line 26

def context
  @context
end

Class Method Details

.derive(path = []) ⇒ Object

Generate a base class for the specified path.



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

def self.derive(path = [])
  klass = Class.new(self)
  
  klass.const_set(:PATH, path)
  
  return klass
end

.inspectObject



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

def self.inspect
  if path = self.path
    "Bake::Base<#{path.join(':')}>"
  else
    super
  end
end

.pathArray(String)

The path of this derived base class.



57
58
59
60
61
# File 'lib/bake/base.rb', line 57

def self.path
  self.const_get(:PATH)
rescue
  nil
end

.to_sString

Format the class as a command.



39
40
41
42
43
44
45
# File 'lib/bake/base.rb', line 39

def self.to_s
  if path = self.path
    path.join(':')
  else
    super
  end
end

Instance Method Details

#call(*arguments) ⇒ Object

Proxy a method call using command line arguments through to the Context instance.



71
72
73
# File 'lib/bake/base.rb', line 71

def call(*arguments)
  self.context.call(*arguments)
end

#pathArray(String)

The path for this derived base class.



65
66
67
# File 'lib/bake/base.rb', line 65

def path
  self.class.path
end

#recipe_for(name) ⇒ Object

Look up a recipe with a specific name.



93
94
95
# File 'lib/bake/base.rb', line 93

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

#recipesEnumerable

Recipes defined in this scope.



80
81
82
83
84
85
86
87
88
# File 'lib/bake/base.rb', line 80

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