Class: ChemistryKit::Formula::FormulaLab
- Inherits:
-
Object
- Object
- ChemistryKit::Formula::FormulaLab
- Defined in:
- lib/chemistrykit/formula/formula_lab.rb
Overview
Factory class to assemble page objects with users
Instance Attribute Summary collapse
-
#formula ⇒ Object
readonly
Returns the value of attribute formula.
Instance Method Summary collapse
- #and_with(key) ⇒ Object
-
#initialize(driver, chemist_repository, formulas_dir) ⇒ FormulaLab
constructor
A new instance of FormulaLab.
- #mix(formula_key = nil) ⇒ Object
- #using(formula_key) ⇒ Object
- #with(key) ⇒ Object
- #with_first(type) ⇒ Object
- #with_random(type) ⇒ Object
Constructor Details
#initialize(driver, chemist_repository, formulas_dir) ⇒ FormulaLab
Returns a new instance of FormulaLab.
12 13 14 15 16 17 18 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 12 def initialize(driver, chemist_repository, formulas_dir) @driver = driver @chemist_repository = chemist_repository raise ArgumentError, "Formula directory \"#{formulas_dir}\" does not exist!" unless File.directory?(formulas_dir) @formulas_dir = formulas_dir @sub_chemists = [] end |
Instance Attribute Details
#formula ⇒ Object (readonly)
Returns the value of attribute formula.
10 11 12 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 10 def formula @formula end |
Instance Method Details
#and_with(key) ⇒ Object
54 55 56 57 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 54 def and_with(key) @sub_chemists << @chemist_repository.load_chemist_by_key(key) self end |
#mix(formula_key = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 25 def mix(formula_key = nil) @formula = formula_key ||= formula compose_chemists unless @sub_chemists.empty? raise ArgumentError, 'A formula key must be defined!' unless @formula formula_file = find_formula_file class_name = get_class_name formula_file formula = constantize(class_name).new(@driver) if formula.singleton_class.include?(ChemistryKit::Formula::ChemistAware) raise RuntimeError, "Trying to mix a formula: \"#{formula_key}\" that requires a user, but no user set!" unless @chemist formula.chemist = @chemist end formula end |
#using(formula_key) ⇒ Object
20 21 22 23 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 20 def using(formula_key) @formula = formula_key self end |
#with(key) ⇒ Object
39 40 41 42 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 39 def with(key) @chemist = @chemist_repository.load_chemist_by_key key self end |
#with_first(type) ⇒ Object
49 50 51 52 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 49 def with_first(type) @chemist = @chemist_repository.load_first_chemist_of_type type self end |
#with_random(type) ⇒ Object
44 45 46 47 |
# File 'lib/chemistrykit/formula/formula_lab.rb', line 44 def with_random(type) @chemist = @chemist_repository.load_random_chemist_of_type type self end |