Module: Loom::Pattern::DSL

Defined in:
lib/loom/pattern/dsl.rb

Overview

TODO: clarify this DSL to only export:

  • description

  • pattern

  • let

  • after/before

other methods are utility methods used to process and run patterns.

Instance Method Summary collapse

Instance Method Details

#after(&block) ⇒ Object



265
266
267
# File 'lib/loom/pattern/dsl.rb', line 265

def after(&block)
  hook :after, &block
end

#before(&block) ⇒ Object



261
262
263
# File 'lib/loom/pattern/dsl.rb', line 261

def before(&block)
  hook :before, &block
end

#description(description) ⇒ Object Also known as: desc



225
226
227
# File 'lib/loom/pattern/dsl.rb', line 225

def description(description)
  @next_description = description
end

#factsObject



294
295
296
# File 'lib/loom/pattern/dsl.rb', line 294

def facts
  @facts || {}
end

#hooksObject



290
291
292
# File 'lib/loom/pattern/dsl.rb', line 290

def hooks
  @hooks || []
end

#is_weave?(name) ⇒ Boolean

Returns:

  • (Boolean)


273
274
275
# File 'lib/loom/pattern/dsl.rb', line 273

def is_weave?(name)
  !!weave_slugs[name]
end

#let(name, default: nil, &block) ⇒ Object



237
238
239
240
241
242
# File 'lib/loom/pattern/dsl.rb', line 237

def let(name, default: nil, &block)
  raise "malformed let expression: missing block" unless block_given?

  @let_map ||= {}
  @let_map[name.to_sym] = LetMapEntry.new default, &block
end

#let_mapObject



298
299
300
# File 'lib/loom/pattern/dsl.rb', line 298

def let_map
  @let_map || {}
end

#pattern(name, &block) ⇒ Object



244
245
246
247
# File 'lib/loom/pattern/dsl.rb', line 244

def pattern(name, &block)
  Loom.log.debug1(self) { "defining pattern => #{name}" }
  define_pattern_internal(name, &block)
end

#pattern_description(name) ⇒ Object



281
282
283
# File 'lib/loom/pattern/dsl.rb', line 281

def pattern_description(name)
  @pattern_descriptions[name]
end

#pattern_method(name) ⇒ Object



285
286
287
288
# File 'lib/loom/pattern/dsl.rb', line 285

def pattern_method(name)
  raise UnknownPatternMethod, name unless @pattern_method_map[name]
  instance_method name
end

#pattern_methodsObject



277
278
279
# File 'lib/loom/pattern/dsl.rb', line 277

def pattern_methods
  @pattern_methods || []
end

#weave(name, pattern_slugs) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
# File 'lib/loom/pattern/dsl.rb', line 249

def weave(name, pattern_slugs)
  Loom.log.debug1(self) { "defining weave => #{name}" }
  @weave_slugs ||= {}
  @weave_slugs[name.to_sym] = pattern_slugs.map { |s| s.to_s }

  unless @next_description
    @next_description = "Weave runs patterns: %s" % pattern_slugs.join(", ")
  end

  define_pattern_internal(name) { |_, _| true }
end

#weave_slugsObject



269
270
271
# File 'lib/loom/pattern/dsl.rb', line 269

def weave_slugs
  @weave_slugs || {}
end

#with_facts(**new_facts, &block) ⇒ Object



230
231
232
233
234
235
# File 'lib/loom/pattern/dsl.rb', line 230

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