Module: ERLE::Registry

Defined in:
lib/erle/registry.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

._enclosuresObject

Returns the value of attribute _enclosures.



5
6
7
# File 'lib/erle/registry.rb', line 5

def _enclosures
  @_enclosures
end

._patternsObject

Returns the value of attribute _patterns.



6
7
8
# File 'lib/erle/registry.rb', line 6

def _patterns
  @_patterns
end

Class Method Details

.enclosure(klass, one, two) ⇒ Object



12
13
14
# File 'lib/erle/registry.rb', line 12

def self.enclosure(klass, one, two)
  @_enclosures[one] = klass
end

.open_find(str) ⇒ Object



31
32
33
34
35
# File 'lib/erle/registry.rb', line 31

def self.open_find(str)
  sorted_encolsures.find do |k, v|
    str =~ k
  end
end

.openingsObject



41
42
43
# File 'lib/erle/registry.rb', line 41

def self.openings
  @openings ||= sorted_encolsures.keys
end

.openings_regexObject



49
50
51
# File 'lib/erle/registry.rb', line 49

def self.openings_regex
  @openings_regex ||= Regexp.new("(#{openings_source.join('|')})")
end

.openings_sourceObject



45
46
47
# File 'lib/erle/registry.rb', line 45

def self.openings_source
  @openings_source ||= openings.map(&:source)
end

.pattern(klass, pat) ⇒ Object



16
17
18
# File 'lib/erle/registry.rb', line 16

def self.pattern(klass, pat)
  (@_patterns[klass] ||= Set.new).add(pat)
end

.pattern_findObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/erle/registry.rb', line 20

def self.pattern_find
  return unless block_given?
  @_patterns.each do |klass, patterns|
    pattern = patterns.find do |pattern|
      yield(pattern)
    end
    return [klass, pattern] if pattern
  end
  nil
end

.sorted_encolsuresObject



37
38
39
# File 'lib/erle/registry.rb', line 37

def self.sorted_encolsures
  @sorted_encolsures ||= @_enclosures.sort_by { |pattern, klass| pattern.source.length }.reverse.to_h
end