Class: Bake::Book
- Inherits:
-
Object
- Object
- Bake::Book
- Defined in:
- lib/bake/book.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#recipes ⇒ Object
readonly
Returns the value of attribute recipes.
Class Method Summary collapse
Instance Method Summary collapse
- #attach(name, callable, **options) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(path = [], **options) ⇒ Book
constructor
A new instance of Book.
- #lookup(name) ⇒ Object
- #recipe(name, **options, &block) ⇒ Object
- #recipe_for(path) ⇒ Object
- #to_s ⇒ Object
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 = [], **) @path = path @recipes = {} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
48 49 50 |
# File 'lib/bake/book.rb', line 48 def path @path end |
#recipes ⇒ Object (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, **) instance = self.new(*arguments, **) 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, **) @recipes[name] = Recipe.new(self, name, **) do |*arguments, **| callable.call(*arguments, **) 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
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, **, &block) unless block_given? block = self.method(name) end @recipes[name] = Recipe.new(self, name, **, &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_s ⇒ Object
51 52 53 |
# File 'lib/bake/book.rb', line 51 def to_s @path.join(':') end |