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
- #<=>(other) ⇒ Object
- #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
- #source_location ⇒ 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 31 |
# File 'lib/bake/recipe.rb', line 23 def initialize(scope, name, method = nil) @scope = scope @name = name @command = nil @description = nil @method = method @arity = nil end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
34 35 36 |
# File 'lib/bake/recipe.rb', line 34 def name @name end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
33 34 35 |
# File 'lib/bake/recipe.rb', line 33 def scope @scope end |
Instance Method Details
#<=>(other) ⇒ Object
36 37 38 |
# File 'lib/bake/recipe.rb', line 36 def <=> other self.source_location <=> other.source_location end |
#arity ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/bake/recipe.rb', line 72 def arity if @arity.nil? @arity = method.parameters.count{|type, name| type == :req} end return @arity end |
#call(*arguments, **options) ⇒ Object
104 105 106 107 108 109 110 111 |
# File 'lib/bake/recipe.rb', line 104 def call(*arguments, **) if @scope.send(@name, *arguments, **) else # Ignore options... @scope.send(@name, *arguments) end end |
#command ⇒ Object
64 65 66 |
# File 'lib/bake/recipe.rb', line 64 def command @command ||= compute_command end |
#description ⇒ Object
121 122 123 |
# File 'lib/bake/recipe.rb', line 121 def description @description ||= read_description end |
#explain(context, *arguments, **options) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/bake/recipe.rb', line 113 def explain(context, *arguments, **) if puts "#{self}(#{arguments.join(", ")}, #{options.inspect})" else puts "#{self}(#{arguments.join(", ")})" end end |
#method ⇒ Object
40 41 42 |
# File 'lib/bake/recipe.rb', line 40 def method @method ||= @scope.method(@name) end |
#options? ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/bake/recipe.rb', line 56 def if parameters = self.parameters type, name = self.parameters.last return type == :keyrest || type == :keyreq || type == :key end end |
#parameters ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/bake/recipe.rb', line 48 def parameters parameters = method.parameters unless parameters.empty? return parameters end end |
#prepare(arguments) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bake/recipe.rb', line 80 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 |
#source_location ⇒ Object
44 45 46 |
# File 'lib/bake/recipe.rb', line 44 def source_location self.method.source_location end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/bake/recipe.rb', line 68 def to_s self.command end |