Module: Loom::Pattern::DSL
- Defined in:
- lib/loom/pattern/dsl.rb
Instance Method Summary collapse
- #after(&block) ⇒ Object
- #before(&block) ⇒ Object
- #description(description) ⇒ Object (also: #desc)
- #facts ⇒ Object
- #hook(scope, &block) ⇒ Object
- #hooks ⇒ Object
- #let(name, &block) ⇒ Object
- #let_map ⇒ Object
- #pattern(name, &block) ⇒ Object
- #pattern_description(name) ⇒ Object
- #pattern_method(name) ⇒ Object
- #pattern_methods ⇒ Object
- #with_facts(**new_facts, &block) ⇒ Object
Instance Method Details
#after(&block) ⇒ Object
147 148 149 |
# File 'lib/loom/pattern/dsl.rb', line 147 def after(&block) hook :after, &block end |
#before(&block) ⇒ Object
143 144 145 |
# File 'lib/loom/pattern/dsl.rb', line 143 def before(&block) hook :before, &block end |
#description(description) ⇒ Object Also known as: desc
105 106 107 |
# File 'lib/loom/pattern/dsl.rb', line 105 def description(description) @next_description = description end |
#facts ⇒ Object
168 169 170 |
# File 'lib/loom/pattern/dsl.rb', line 168 def facts @facts || {} end |
#hook(scope, &block) ⇒ Object
138 139 140 141 |
# File 'lib/loom/pattern/dsl.rb', line 138 def hook(scope, &block) @hooks ||= [] @hooks << Hook.new(scope, &block) end |
#hooks ⇒ Object
164 165 166 |
# File 'lib/loom/pattern/dsl.rb', line 164 def hooks @hooks || [] end |
#let(name, &block) ⇒ Object
117 118 119 120 |
# File 'lib/loom/pattern/dsl.rb', line 117 def let(name, &block) @let_map ||= {} @let_map[name.to_sym] = block end |
#let_map ⇒ Object
172 173 174 |
# File 'lib/loom/pattern/dsl.rb', line 172 def let_map @let_map || {} end |
#pattern(name, &block) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/loom/pattern/dsl.rb', line 122 def pattern(name, &block) Loom.log.debug3(self) { "defined pattern method => #{name}" } @pattern_methods ||= [] @pattern_method_map ||= {} @pattern_descriptions ||= {} method_name = name.to_sym @pattern_methods << method_name @pattern_method_map[method_name] = true @pattern_descriptions[method_name] = @next_description @next_description = nil define_method method_name, &block end |
#pattern_description(name) ⇒ Object
155 156 157 |
# File 'lib/loom/pattern/dsl.rb', line 155 def pattern_description(name) @pattern_descriptions[name] end |
#pattern_method(name) ⇒ Object
159 160 161 162 |
# File 'lib/loom/pattern/dsl.rb', line 159 def pattern_method(name) raise UnknownPatternMethod, name unless @pattern_method_map[name] instance_method name end |
#pattern_methods ⇒ Object
151 152 153 |
# File 'lib/loom/pattern/dsl.rb', line 151 def pattern_methods @pattern_methods || [] end |
#with_facts(**new_facts, &block) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/loom/pattern/dsl.rb', line 110 def with_facts(**new_facts, &block) @facts ||= {} @facts.merge! new_facts yield_result = yield @facts if block_given? @facts = yield_result if yield_result.is_a? Hash end |