Class: Ingredient
- Inherits:
-
Object
show all
- Defined in:
- lib/conman/ingredient.rb
Direct Known Subclasses
Recipe
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
7
8
9
|
# File 'lib/conman/ingredient.rb', line 7
def method_missing(m, *args, &block)
Recipe.execute_recipe(m, args)
end
|
Class Method Details
.execute_recipe(class_name, args = {}) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/conman/ingredient.rb', line 11
def self.execute_recipe(class_name, args={})
clazz_name = (class_name.to_s.split('_').map {|w| w.capitalize}.join) + 'Ingredient'
clazz = Kernel.const_get(clazz_name)
method = args.shift
recipe = clazz.new
if args.empty?
recipe.send method
else
recipe.send method, args.first
end
end
|
.method_missing(m, *args, &block) ⇒ Object
3
4
5
|
# File 'lib/conman/ingredient.rb', line 3
def self.method_missing(m, *args, &block)
Recipe.execute_recipe(m, args)
end
|
Instance Method Details
#option!(options, targets) ⇒ Object
31
32
33
|
# File 'lib/conman/ingredient.rb', line 31
def option!(options, targets)
raise ArgumentError, "Missing required parameter from #{options.inspect}, required = #{targets.inspect}" unless option?(options, targets)
end
|
#option?(options, targets) ⇒ Boolean
24
25
26
27
28
29
|
# File 'lib/conman/ingredient.rb', line 24
def option?(options, targets)
targets = [targets] unless targets.is_a? Array
targets.each do |target|
return false unless options[target] and !options[target].nil? and !options[target].to_s.strip.empty?
end
end
|