Class: Uttk::Filters::RPathFilter

Inherits:
Id show all
Defined in:
lib/uttk/filters/RPathFilter.rb

Direct Known Subclasses

JustStatus

Defined Under Namespace

Modules: Assertions Classes: Matcher

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filter

composition, #notif

Methods inherited from Logger::Backend

#update

Constructor Details

#initialize(*a, &b) ⇒ RPathFilter

Returns a new instance of RPathFilter.



16
17
18
19
20
# File 'lib/uttk/filters/RPathFilter.rb', line 16

def initialize ( *a, &b )
  @log = Logger.new # FIXME PERAPHS you can remove me
  @matchers = matchers.dup
  super
end

Instance Attribute Details

#logObject (readonly)

FIXME include Abstract



14
15
16
# File 'lib/uttk/filters/RPathFilter.rb', line 14

def log
  @log
end

Class Method Details

.disable_matcherObject

Raises:



78
79
80
# File 'lib/uttk/filters/RPathFilter.rb', line 78

def self.disable_matcher
  raise Matcher::Disable
end

.match(aRegexPath, aMethod = nil, &block) ⇒ Object

The aRegexpPath is matched against the path of every notification the filter receive. If the notification path matches, then the method mentioned as second argument is called. If no method are mentioned, it looks for a block. You must supply either a method or a block, not both.



68
69
70
71
72
73
74
75
76
# File 'lib/uttk/filters/RPathFilter.rb', line 68

def self.match ( aRegexPath, aMethod=nil, &block )
  if aMethod.nil? and block.nil?
    raise ArgumentError, "no block or method given"
  end
  if aMethod and block
    raise ArgumentError, "supply a block OR a method name not both"
  end
  self.matchers = matchers + [Matcher.new(aRegexPath, aMethod, &block)]
end

Instance Method Details

#add_observer(obj) ⇒ Object



23
24
25
26
# File 'lib/uttk/filters/RPathFilter.rb', line 23

def add_observer ( obj )
  @log.add_observer(obj)
  super
end

#new_leaf(lpath, leaf) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/uttk/filters/RPathFilter.rb', line 29

def new_leaf ( lpath, leaf )
  lpath << leaf
  @matchers.each do |matcher|
    next unless matcher.active?
    if matcher.have_a_star?
      buf = matcher.buffer
      is_prefix = lpath.rpath_prefix(matcher.re)
      unless buf.empty? or is_prefix
        buf.buffer.rpath(matcher.re) do |*args|
          matcher[self, *args]
        end
        buf.reset
      end
      if is_prefix
        if buf.empty?
          l = Logger.new(buf)
          lpath.each do |seg|
            l.new_node seg.segment, seg.options
          end
        end
        buf.update(:new_leaf, lpath, leaf)
      end
    else
      lpath.rpath(matcher.re) do |*args|
        matcher[self, *args]
      end
    end
  end
end