Class: QED::Applique
Overview
Applique is a module built per-script from the applique directory.
Applique scripts are loaded at the start of a session.
The Applique is the whole collection of appliques that apply to given demonstrandum. The applique that apply are the scripts located in the directory relative to the demonstrandum script and all such directories above this upto and the project's root directory.
All scripts in the Applique must be compatible/consistant. For two demos to have separate applique they must be kept in separate directories.
Instance Attribute Summary collapse
-
#__matchers__ ⇒ Object
readonly
Array of matchers.
-
#__signals__ ⇒ Object
readonly
Hash of signals.
Class Method Summary collapse
-
.cache ⇒ Object
Load cache.
-
.for(file) ⇒ Object
Create new Applique caching instance based-on
file.
Instance Method Summary collapse
-
#After(type = :demo) { ... } ⇒ Object
After advice.
-
#Before(type = :demo) { ... } ⇒ Object
Before advice.
-
#const_missing(name) ⇒ Object
Redirect missing constants to Object classto simulate TOPLEVEL.
-
#initialize(file = nil) ⇒ Applique
constructor
Setup new Applique instance.
-
#initialize_copy(other) ⇒ Object
Duplicate matcher and signal advice when duplicting applique.
-
#When(*patterns) { ... } ⇒ Object
Pattern matchers and "upon" events.
Constructor Details
#initialize(file = nil) ⇒ Applique
Setup new Applique instance.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/qed/applique.rb', line 37 def initialize(file=nil) super() extend self @__matchers__ = [] @__signals__ = {} if file @file = file case File.extname(file) when '.rb' module_eval(File.read(file), file) else # little bit of a trick here, we create a new demo but manually # set the applique. That way the applique files won't be reloaded. # we then run the demo that applique get loaded. demo = Demo.new(file, :applique=>[self]) Evaluator.run(demo, :applique=>true) end end end |
Instance Attribute Details
#__matchers__ ⇒ Object (readonly)
Array of matchers.
70 71 72 |
# File 'lib/qed/applique.rb', line 70 def __matchers__ @__matchers__ end |
#__signals__ ⇒ Object (readonly)
Hash of signals.
73 74 75 |
# File 'lib/qed/applique.rb', line 73 def __signals__ @__signals__ end |
Class Method Details
.cache ⇒ Object
Load cache.
17 18 19 |
# File 'lib/qed/applique.rb', line 17 def self.cache @cache ||= {} end |
.for(file) ⇒ Object
Create new Applique caching instance based-on file.
28 29 30 |
# File 'lib/qed/applique.rb', line 28 def self.for(file) cache[file] ||= new(file) end |
Instance Method Details
#After(type = :demo) { ... } ⇒ Object
After advice.
119 120 121 122 123 124 125 126 |
# File 'lib/qed/applique.rb', line 119 def After(type=:demo, &procedure) type = type.to_sym type = :demo if type == :all type = :test if type == :each type = "after_#{type}".to_sym @__signals__[type] = procedure #define_method(type, &procedure) end |
#Before(type = :demo) { ... } ⇒ Object
Before advice.
104 105 106 107 108 109 110 111 |
# File 'lib/qed/applique.rb', line 104 def Before(type=:demo, &procedure) type = type.to_sym type = :demo if type == :all type = :test if type == :each type = "before_#{type}".to_sym @__signals__[type] = procedure #define_method(type, &procedure) end |
#const_missing(name) ⇒ Object
Redirect missing constants to Object classto simulate TOPLEVEL.
150 151 152 |
# File 'lib/qed/applique.rb', line 150 def const_missing(name) Object.const_get(name) end |
#initialize_copy(other) ⇒ Object
Duplicate matcher and signal advice when duplicting applique.
64 65 66 67 |
# File 'lib/qed/applique.rb', line 64 def initialize_copy(other) @__matchers__ = other.__matchers__.dup @__signals__ = other.__signals__.dup end |
#When(*patterns) { ... } ⇒ Object
Pattern matchers and "upon" events.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/qed/applique.rb', line 81 def When(*patterns, &procedure) if patterns.size == 1 && Symbol === patterns.first type = "#{patterns.first}".to_sym @__signals__[type] = procedure #define_method(type, &procedure) else patterns = patterns.map do |p| if String === p p.split('...').map{ |e| e.strip } else p end end.flatten @__matchers__ << [patterns, procedure] end end |