Class: Bake::Book

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

Direct Known Subclasses

Context

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = [], **options) ⇒ Book

Returns a new instance of Book.



35
36
37
38
# File 'lib/bake/book.rb', line 35

def initialize(path = [], **options)
	@path = path
	@recipes = {}
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



48
49
50
# File 'lib/bake/book.rb', line 48

def path
  @path
end

#recipesObject (readonly)

Returns the value of attribute recipes.



49
50
51
# File 'lib/bake/book.rb', line 49

def recipes
  @recipes
end

Class Method Details

.load(file_path, *arguments, **options) ⇒ Object



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

def self.load(file_path, *arguments, **options)
	instance = self.new(*arguments, **options)
	
	instance.freeze
	
	instance.instance_eval(File.read(file_path), file_path)
	
	return instance
end

Instance Method Details

#attach(name, callable, **options) ⇒ Object



73
74
75
76
77
# File 'lib/bake/book.rb', line 73

def attach(name, callable, **options)
	@recipes[name] = Recipe.new(self, name, **options) do |*arguments, **options|
		callable.call(*arguments, **options)
	end
end

#each(&block) ⇒ Object



44
45
46
# File 'lib/bake/book.rb', line 44

def each(&block)
	@recipes.each_value(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bake/book.rb', line 40

def empty?
	@recipes.empty?
end

#lookup(name) ⇒ Object



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

def lookup(name)
	@recipes[name.to_sym]
end

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



65
66
67
68
69
70
71
# File 'lib/bake/book.rb', line 65

def recipe(name, **options, &block)
	unless block_given?
		block = self.method(name)
	end
	
	@recipes[name] = Recipe.new(self, name, **options, &block)
end

#recipe_for(path) ⇒ Object



59
60
61
62
63
# File 'lib/bake/book.rb', line 59

def recipe_for(path)
	if path.size == 1
		lookup(path.first)
	end
end

#to_sObject



51
52
53
# File 'lib/bake/book.rb', line 51

def to_s
	@path.join(':')
end