Class: Bake::Recipe
- Inherits:
-
Object
- Object
- Bake::Recipe
- Defined in:
- lib/bake/recipe.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #arity ⇒ Object
- #call(*arguments, **options) ⇒ Object
- #command ⇒ Object
- #description ⇒ Object
- #explain(context, *arguments, **options) ⇒ Object
-
#initialize(scope, name, method = nil) ⇒ Recipe
constructor
A new instance of Recipe.
- #method ⇒ Object
- #options? ⇒ Boolean
- #parameters ⇒ Object
- #prepare(arguments) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(scope, name, method = nil) ⇒ Recipe
Returns a new instance of Recipe.
23 24 25 26 27 28 29 30 |
# File 'lib/bake/recipe.rb', line 23 def initialize(scope, name, method = nil) @scope = scope @name = name @command = nil @description = nil @method = method end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
33 34 35 |
# File 'lib/bake/recipe.rb', line 33 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
32 33 34 |
# File 'lib/bake/recipe.rb', line 32 def scope @scope end |
Instance Method Details
#arity ⇒ Object
63 64 65 |
# File 'lib/bake/recipe.rb', line 63 def arity method.arity end |
#call(*arguments, **options) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/bake/recipe.rb', line 91 def call(*arguments, **) if @scope.send(@name, *arguments, **) else # Ignore options... @scope.send(@name, *arguments) end end |
#command ⇒ Object
55 56 57 |
# File 'lib/bake/recipe.rb', line 55 def command @command ||= compute_command end |
#description ⇒ Object
108 109 110 |
# File 'lib/bake/recipe.rb', line 108 def description @description ||= read_description end |
#explain(context, *arguments, **options) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/bake/recipe.rb', line 100 def explain(context, *arguments, **) if puts "#{self}(#{arguments.join(", ")}, #{.inspect})" else puts "#{self}(#{arguments.join(", ")})" end end |
#method ⇒ Object
35 36 37 |
# File 'lib/bake/recipe.rb', line 35 def method @method ||= @scope.method(@name) end |
#options? ⇒ Boolean
47 48 49 50 51 52 53 |
# File 'lib/bake/recipe.rb', line 47 def if parameters = self.parameters type, name = self.parameters.last return type == :keyrest || type == :keyreq || type == :key end end |
#parameters ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/bake/recipe.rb', line 39 def parameters parameters = method.parameters unless parameters.empty? return parameters end end |
#prepare(arguments) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/bake/recipe.rb', line 67 def prepare(arguments) offset = 0 ordered = [] = {} while argument = arguments.first name, value = argument.split('=', 2) if name and value # Consume it: arguments.shift [name.to_sym] = value elsif ordered.size < self.arity # Consume it: ordered << arguments.shift else break end end return ordered, end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/bake/recipe.rb', line 59 def to_s self.command end |