Class: Loom::Pattern::ReferenceSet

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

Overview

A collection of Pattern::Reference objects

Defined Under Namespace

Classes: Builder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReferenceSet

Returns a new instance of ReferenceSet.



30
31
32
# File 'lib/loom/pattern/reference_set.rb', line 30

def initialize
  @slug_to_ref_map = {}
end

Class Method Details

.builder(file_src, file_path) ⇒ Object



25
26
27
# File 'lib/loom/pattern/reference_set.rb', line 25

def builder(file_src, file_path)
  Builder.create(file_src, file_path)
end

.load_from_file(path) ⇒ Object



20
21
22
23
# File 'lib/loom/pattern/reference_set.rb', line 20

def load_from_file(path)
  Loom.log.debug1(self) { "loading patterns from file => #{path}" }
  builder(File.read(path), path).build
end

Instance Method Details

#add_pattern_refs(refs) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/loom/pattern/reference_set.rb', line 53

def add_pattern_refs(refs)
  refs.each do |ref|
    Loom.log.debug2(self) { "adding ref to set => #{ref.slug}" }
    raise DuplicatePatternRef, ref.slug if @slug_to_ref_map[ref.slug]
    @slug_to_ref_map[ref.slug] = ref
  end
end

#get_pattern_ref(slug) ⇒ Object Also known as: []

Raises:



42
43
44
45
46
# File 'lib/loom/pattern/reference_set.rb', line 42

def get_pattern_ref(slug)
  ref = @slug_to_ref_map[slug]
  raise NoReferenceForSlug, slug unless ref
  ref
end

#merge!(ref_set) ⇒ Object



49
50
51
# File 'lib/loom/pattern/reference_set.rb', line 49

def merge!(ref_set)
  add_pattern_refs(ref_set.pattern_refs)
end

#pattern_refsObject



38
39
40
# File 'lib/loom/pattern/reference_set.rb', line 38

def pattern_refs
  @slug_to_ref_map.values
end

#slugsObject



34
35
36
# File 'lib/loom/pattern/reference_set.rb', line 34

def slugs
  @slug_to_ref_map.keys
end