Class: Loom::Pattern::Pattern

Inherits:
Object
  • Object
show all
Defined in:
lib/loom/pattern/pattern.rb

Overview

A value object represnting the .loom file pattern declarations. The difference between a Loom::Pattern::Pattern and Loom::Pattern::Reference is a pattern has no association to the context it should run in. It is simply a value object with pointers to its assigned values from the .loom file. However, a Reference includes it’s DefinitionContext, including nested before/after/with_facts/let hooks.

Constant Summary collapse

KINDS =
%i[pattern weave report]
.reduce({}) { |memo, k| memo.merge k => true }.freeze
KIND_KWARGS =

effectively, a list of ‘attr_readers` for the Pattern kind. but also used for validation

{
  weave: [:expanded_slugs]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, description: nil, kind: nil, **kind_kwargs, &block) ⇒ Pattern

Returns a new instance of Pattern.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/loom/pattern/pattern.rb', line 21

def initialize(name: nil, description: nil, kind: nil, **kind_kwargs, &block)
  @name = name
  @description = description
  @kind = kind
  @pattern_block = block

  @valid_kwargs = KIND_KWARGS[kind]
  kind_kwargs.each do |k, _|
    raise "unknown kind_kwarg: #{k}" unless @valid_kwargs.include? k
  end
  @kind_properties_struct = OpenStruct.new kind_kwargs
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



19
20
21
# File 'lib/loom/pattern/pattern.rb', line 19

def description
  @description
end

#kindObject (readonly)

Returns the value of attribute kind.



19
20
21
# File 'lib/loom/pattern/pattern.rb', line 19

def kind
  @kind
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/loom/pattern/pattern.rb', line 19

def name
  @name
end

#pattern_blockObject (readonly)

Returns the value of attribute pattern_block.



19
20
21
# File 'lib/loom/pattern/pattern.rb', line 19

def pattern_block
  @pattern_block
end