module Filigree::Visitor::ClassMethods

Class Methods #

Attributes

patterns[R]

Public Class Methods

extended(klass) click to toggle source
# File lib/filigree/visitor.rb, line 196
def self.extended(klass)
        klass.install_icvars
end

Public Instance Methods

Bind(name) click to toggle source

Force a name binding.

@param [Symbol] name Name to bind to

@return [BindingPattern]

# File lib/filigree/visitor.rb, line 93
def Bind(name)
        BindingPattern.new(name)
end
Literal(obj) click to toggle source

Force a literal comparison.

@param [Object] obj Object to be comapred against

@return [LiteralPattern]

# File lib/filigree/visitor.rb, line 102
def Literal(obj)
        LiteralPattern.new(obj)
end
add_pattern(new_pat) click to toggle source

Inserts a new pattern in the appropriate place in the patterns list.

@param [OuterPattern] new_pat New pattern to add

@return [void]

# File lib/filigree/visitor.rb, line 112
def add_pattern(new_pat)
        @patterns.each_with_index do |old_pat, index|
                if new_pat > old_pat
                        @patterns.insert(index, new_pat)
                        return
                end
        end

        @patterns << new_pat
end
inherited(klass) click to toggle source

A callback used to pass patterns declared in a parent class to a subclass.

@param [Class] klass Subclass

@return [void]

# File lib/filigree/visitor.rb, line 129
def inherited(klass)
        klass.install_icvars(@patterns.clone)
end
install_icvars(inherited_patterns = Array.new) click to toggle source

Install the instance class variables in the including class.

@return [void]

# File lib/filigree/visitor.rb, line 136
def install_icvars(inherited_patterns = Array.new)
        @patterns     = inherited_patterns
        @deferred     = Array.new
        @strict_match = false
end
method_missing(name, *args) click to toggle source

Used to generate wildcard and binding patterns.

Calls superclass method
# File lib/filigree/visitor.rb, line 188
def method_missing(name, *args)
        if args.empty?
                if name == :_ then WildcardPattern.instance else BindingPattern.new(name) end
        else
                super(name, *args)
        end
end
on(*pattern, &block) click to toggle source

Define a pattern for this visitor.

@see match Pattern matching description

@param [Object] pattern List of pattern elements @param [Proc] block Block to be executed when the pattern is matched

@return [void]

# File lib/filigree/visitor.rb, line 150
def on(*pattern, &block)
        guard = if pattern.last.is_a?(Proc) then pattern.pop end

        pattern = Filigree::wrap_pattern_elements(pattern)
        add_pattern (mp = OuterPattern.new(pattern, guard, block))

        if block
                @deferred.each { |deferred_pattern| deferred_pattern.block = block }
                @deferred.clear

        else
                @deferred << mp
        end
end
strict_match(bool) click to toggle source

Tell the visitor that it must raise an exception if no match is found.

@param [Boolean] bool Raise an exception or not.

@return [void]

# File lib/filigree/visitor.rb, line 171
def strict_match(bool)
        @strict_match = bool
end
strict_match?() click to toggle source

Accessor for the strict match member.

@return [Boolean] The value of the class's @strict_match

instance variable.
# File lib/filigree/visitor.rb, line 179
def strict_match?
        @strict_match
end